Write a PL/SQL block to take an input in the form of job.
Print employee information if the job is with one employee in the EMP table,
if the job is with more than one employee print appropriate message and
terminate the block, and if the job is not present print appropriate message and terminate the block.
DECLARE
JOB_SEARCH VARCHAR2(9);
NO NUMBER;
JOB_EXCEP1 EXCEPTION;
JOB_EXCEP2 EXCEPTION;
BEGIN
JOB_SEARCH:='&JOB_SEARCH';
SELECT COUNT(*) INTO NO FROM EMP WHERE JOB=JOB_SEARCH;
IF NO=1 THEN
DBMS_OUTPUT.PUT_LINE('PRINT EMPLOYEE INFORMATION...');
ELSIF NO=0 THEN
RAISE JOB_EXCEP1;
ELSE
RAISE JOB_EXCEP2;
END IF;
EXCEPTION
WHEN JOB_EXCEP1 THEN
DBMS_OUTPUT.PUT_LINE('NO JOB FOUND.');
WHEN JOB_EXCEP2 THEN
DBMS_OUTPUT.PUT_LINE('MORE THAN ONE JOB FOUND.');
END;
/
Print employee information if the job is with one employee in the EMP table,
if the job is with more than one employee print appropriate message and
terminate the block, and if the job is not present print appropriate message and terminate the block.
DECLARE
JOB_SEARCH VARCHAR2(9);
NO NUMBER;
JOB_EXCEP1 EXCEPTION;
JOB_EXCEP2 EXCEPTION;
BEGIN
JOB_SEARCH:='&JOB_SEARCH';
SELECT COUNT(*) INTO NO FROM EMP WHERE JOB=JOB_SEARCH;
IF NO=1 THEN
DBMS_OUTPUT.PUT_LINE('PRINT EMPLOYEE INFORMATION...');
ELSIF NO=0 THEN
RAISE JOB_EXCEP1;
ELSE
RAISE JOB_EXCEP2;
END IF;
EXCEPTION
WHEN JOB_EXCEP1 THEN
DBMS_OUTPUT.PUT_LINE('NO JOB FOUND.');
WHEN JOB_EXCEP2 THEN
DBMS_OUTPUT.PUT_LINE('MORE THAN ONE JOB FOUND.');
END;
/
No comments:
Post a Comment