DMS Practical Question
DMS Practical Question
DMS Practical Question
e. Delete the employee working in SALES department having salary below 10000.
ANS : DELETE FROM EMP WHERE DEPARTMENT=’SALES’ AND SALARY<10000;
4.Execute SQL Queries Using Arithmetic, Comparison, Logical, Set, Between and Like
Operators.
a.Display the name of employees who does not work under any Job id=2.
ANS : SELECT NAME FROM EMP WHERE JOBID NOT IN(2);
d. List the employee name and salary whose salary is not in the range of 20000 to 35000.
ANS : SELECT NAME,SALARY FROM EMP WHERE SALARY NOT BETWEEN 20000 AND 35000;
5.Execute SQL Queries Using String, Arithmetic,Date and Time, Aggregate Functions.
a.Display information of employees whose salary is greater than average salary of all
employees.
ANS : SELECT * FROM EMP WHERE SALARY>(SELECT AVG(SALARY) FROM SALARY);
DMS Practical Exam Questions
6. Execute Queries Using the Select Command with where,Having, Group by and Order
by Clauses.
c. Display number of employees working in each department and their department name.
ANS : SELECT COUNT(*) ,DEPTNAME FROM EMPLOYEE GROUP BY DEPTNAME;
d. Display the details of employees with the salary in increasing order.
ANS : SELECT * FROM EMPLOYEE ORDER BY SALARY;
e. List the number of employees from every department with sorted order(ascending).
ANS : SELECT COUNT(*) FROM EMP GROUP BY DEPTNO ORDER BY DEPTNO;
SELECT
2. Perform INNER JOIN on EMP and DEPT table.
ANS : SELECT * FROM EMP INNER JOIN DEPT ON EMP.DEPTNO=DEPT.DEPTNO;
DECLARE CURSOR C_HISAL IS SELECT ENAME,SALARY FROM EMP ORDER BY SALARY DESC;
SAL_TEMP C_HISAL%ROWTYPE;
BEGIN OPEN C_HISAL;
LOOP FETCH C_HISAL INTO SAL_TEMP;
DBMS_OUTPUT.PUT_LINE(SAL_TEMP.ENAME || ' ' || SAL_TEMP.SALARY);
EXIT WHEN C_HISAL%ROWCOUNT = 5;
END LOOP;
CLOSE C_HISAL;
END
Write a PL/SQL code to check whether specified employee is present in Emp table or
not. Accept empno from user. If employee does not exist display message using
exception handling.(Use No_data_found exception)
DECLARE
NO EMP.EMPNO%TYPE;
BEGIN
NO:=&NO;
SELECT EMPNO INTO NO FROM EMP WHERE EMPNO=NO;
DBMS_OUTPUT.PUT_LINE('EMPNO IS PRESENT: '||NO);
EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT.PUT_LINE('EMPNO NOT
PRESENT');
END;
DMS Practical Exam Questions
Write a PL/SQL program which accept the customer ID from the user if user enters an
invalid ID then the exception invalid_id is raised using exception handling.
DECLARE
C_ID NUMERIC(10);
INVALID_ID_EXCEPTION EXCEPTION;
BEGIN
C_ID:=&C_ID;
IF(C_ID<0) THEN
RAISE INVALID_ID_EXCEPTION;
END IF;
EXCEPTION
WHEN INVALID_ID_EXCEPTION THEN
DBMS_OUTPUT.PUT_LINE('INVALID CUSTOMER ID');
END;
CALLING PROCEDURE :
BEGIN
INC_SAL;
END;
DMS Practical Exam Questions
20. Executing DCL Commands Using SQL Create Users,Grant Privileges To Users ,Revoke
Privileges From Users.