SEQUENCE: A sequence is an object in oracle, which is used to generate a series of numbers. It can generate unique sequential numbers for using in a primary key column of a table.
SQL> ALTER SEQUENCE SS MAXVALUE 99999;
SQL> DROP SEQUENCE SS;
SEQUENCE: A sequence is an object in oracle, which is used to generate a series of numbers. It can generate unique sequential numbers for using in a primary key column of a table.
SQL> ALTER SEQUENCE SS MAXVALUE 99999;
SQL> DROP SEQUENCE SS;
LOCK TABLE : The LOCK TABLE command is used to prevent concurrent processes from changing a table or from using it.
1)IN SHARE MODE: In which concurrent processes are allowed to perform only
read-only operations.
2)IN EXCLUSIVE MODE:Prevents concurrent processes from performing any operation
the table.
Example:
For obtaining EXCLUSIVE LOCK we write.
If we try to obtain a lock using the first statement then Oracle waits if the table is not available for locking. In second statement it returns immediately.
Example: For obtaining SHARE LOCK we write.
SQL> LOCK TABLE STUD in SHARE MODE; --- to obtain shared mode lock
SELECT Column1, Column2, Aggregate_function(expression1)
FROM Table_Name
[WHERE Clause]
GROUP BY Column1, Column2
HAVING Having_Condition;
Example:
Table Name “EMPLOYEE”
ID | NAME | ADDRESS | DEPARTMENT | SALARY |
101 | Rajesh | Ghaziabad | IT | 10000 |
102 | Swati | Delhi | Non IT | 8000 |
103 | Manoj | Noida | IT | 15000 |
104 | Sachin | Noida | IT | 12000 |
105 | Swati | Delhi | Non IT | 8000 |
· Write a query to find Department where total salary is greater than 20000.
SELECT DEPARTMENT,
SUM(SALARY) as TOTAL_SALARY,
COUNT(ID) as NO_OF_EMP
FROM EMPLOYEE
GROUP BY DEPARTMENT
HAVING SUM(SALARY) > 20000;
Output of the above query will be:
DEPARTMENT | TOTAL_SALARY | NO_OF_EMP |
IT | 37000 | 3 |
· Write a query to find the address where more than one employee.
SELECT ADDRESS, COUNT(ID) as NO_OF_EMP
FROM EMPLOYEE
GROUP BY ADDRESS
HAVING COUNT(ID) > 1;
Output of the above query will be:
ADDRESS | NO_OF_EMP |
Noida | 1 |
Delhi | 2 |
· Write a query to find out duplicate name Employee.
SELECT NAME, COUNT(ID)
FROM EMPLOYEE
GROUP BY NAME
HAVING COUNT(ID) > 1;
Output of the above query will be:
Name | NO_OF_EMP |
Swati | 2 |
ID
|
NAME
|
ADDRESS
|
DEPARTMENT
|
SALARY
|
101
|
Rajesh
|
Ghaziabad
|
IT
|
10000
|
102
|
Swati
|
Delhi
|
Non IT
|
8000
|
103
|
Manoj
|
Noida
|
IT
|
15000
|
104
|
Sachin
|
Noida
|
IT
|
12000
|
105
|
Swati
|
Delhi
|
Non IT
|
8000
|
DEPARTMENT
|
TOTAL_SALARY
|
NO_OF_EMP
|
IT
|
37000
|
3
|
Non IT
|
16000
|
2
|
ADDRESS
|
NO_OF_EMP
|
Ghaziabad
|
1
|
Delhi
|
2
|
Noida
|
2
|
Name
|
NO_OF_EMP
|
Rajesh
|
1
|
Swati
|
2
|
Manoj
|
1
|
Sachin
|
1
|
ID
|
NAME
|
ADDRESS
|
DEPARTMENT
|
101
|
Rajesh
|
Ghaziabad
|
IT
|
102
|
Swati
|
Delhi
|
Non IT
|
103
|
Manoj
|
Noida
|
IT
|
104
|
Sachin
|
Noida
|
IT
|
ID
|
NAME
|
ADDRESS
|
DEPARTMENT
|
101
|
Rajesh
|
Ghaziabad
|
IT
|
102
|
Swati
|
Delhi
|
Non IT
|
103
|
Manoj
|
Noida
|
IT
|
104
|
Sachin
|
Delhi
|
IT
|
ID
|
NAME
|
ADDRESS
|
DEPARTMENT
|
101
|
Rajesh
|
Delhi
|
IT
|
102
|
Swati
|
Delhi
|
Non IT
|
103
|
Manoj
|
Delhi
|
IT
|
104
|
Sachin
|
Delhi
|
IT
|
ID
|
NAME
|
ADDRESS
|
DEPARTMENT
|
101
|
Rajesh
|
Ghaziabad
|
IT
|
102
|
Swati
|
Delhi
|
Non IT
|
103
|
Manoj
|
Noida
|
IT
|
104
|
Sachin
|
Delhi
|
Non IT
|