fork(2) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. }
  14. }
Success #stdin #stdout 0.04s 2184192KB
stdin
3.1: Modify the programs created in Lab2 to implement Exception Handling

3.2 The following PL/SQL block attempts to calculate bonus of staff for a given MGR_CODE. Bonus is to be considered as twice of salary. Though Exception Handling has been implemented but block is unable to handle the same.
Debug and verify the current behavior to trace the problem.

DECLARE
V_BONUS V_SAL%TYPE;
V_SAL STAFF_MASTER.STAFF_SAL%TYPE;

BEGIN
SELECT STAFF_SAL INTO V_SAL
FROM STAFF_MASTER 
WHERE MGR_CODE=100006;

V_BONUS:=2*V_SAL;
DBMS_OUTPUT.PUT_LINE('STAFF SALARY IS ' || V_SAL);
DBMS_OUTPUT.PUT_LINE('STAFF BONUS IS ' || V_BONUS);

EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('GIVEN CODE IS NOT VALID.ENTER VALID CODE');
END;

Example 3: PL/SQL block
DECLARE
 V_BONUS number(10);
 V_SAL STAFF_MASTER.STAFF_SAL%TYPE;
 BEGIN
 SELECT STAFF_SAL INTO V_SAL
 FROM STAFF_MASTER
 WHERE MGR_CODE=100006;
 V_BONUS:=2*V_SAL;
 DBMS_OUTPUT.PUT_LINE('STAFF SALARY IS ' || V_SAL);
 DBMS_OUTPUT.PUT_LINE('STAFF BONUS IS ' || V_BONUS);
 EXCEPTION
 WHEN too_many_rows THEN
 DBMS_OUTPUT.PUT_LINE('GIVEN CODE IS NOT VALID.ENTER VALID CODE');
 END;
 

3.3 Rewrite the above block to achieve the requirement.
DECLARE
CURSOR c1 is SELECT STAFF_SAL, STAFF_SAL*2 "STAFF_BONUS"
FROM STAFF_MASTER 
WHERE MGR_CODE=100006;
BEGIN
FOR I IN C1 LOOP
DBMS_OUTPUT.PUT_LINE('STAFF SALARY IS ' || I.STAFF_SAL);
DBMS_OUTPUT.PUT_LINE('STAFF BONUS IS ' || I.STAFF_BONUS);
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('GIVEN CODE IS NOT VALID.ENTER VALID CODE');
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE('TOO MANY ROWS');
END;
 
3.4
Predict the output of the following block ? What corrections would be needed to make it more efficient?



BEGIN
      DECLARE
      fname emp.ename%TYPE;
      BEGIN
      SELECT ename INTO fname
      FROM emp
      WHERE 1=2;

      DBMS_OUTPUT.PUT_LINE('This statement will print');
      EXCEPTION
      WHEN OTHERS THEN
      DBMS_OUTPUT.PUT_LINE('Some inner block error');
      END;

 EXCEPTION
 WHEN NO_DATA_FOUND THEN
 DBMS_OUTPUT.PUT_LINE('No data found in fname');

 WHEN OTHERS THEN
 DBMS_OUTPUT.PUT_LINE('Some outer block error');
 END;
BEGIN
      DECLARE
      CURSOR c1 is SELECT ename FROM emp WHERE 1=2;
      fname emp.ename%TYPE;
      BEGIN
      OPEN C1;
      FETCH C1 INTO fname;
      DBMS_OUTPUT.PUT_LINE('This statement will print');
      CLOSE C1;
      EXCEPTION
      WHEN OTHERS THEN
      DBMS_OUTPUT.PUT_LINE('Some inner block error');
      END;
 EXCEPTION
 WHEN NO_DATA_FOUND THEN
 DBMS_OUTPUT.PUT_LINE('No data found in fname');
 WHEN OTHERS THEN
 DBMS_OUTPUT.PUT_LINE('Some outer block error');
 END;
 
3.5 Debug the above block to trace the flow of control. 
      Additionally one can make appropriate changes in Select statement defined in the 
      block to check the flow.


3.6: Write a PL/SQL program to check for the commission for an employee no 7369. If no commission exists, then display the error message. Use Exceptions. 

 DECLARE
 CURSOR C1 IS SELECT comm
 FROM emp
 WHERE empno=7369;
 excep EXCEPTION;
 BEGIN
 FOR I IN C1 LOOP
 DBMS_OUTPUT.PUT_LINE(i.comm);
 END LOOP;
 IF null is null then
 raise excep;
 else null;
 end if;
 EXCEPTION
 when excep then
 null;
 DBMS_OUTPUT.PUT_LINE('COMMISION IS NULL');
 END;
 
3.7: Write a PL/SQL block to drop any user defined table.
CREATE OR REPLACE PROCEDURE dropit (ttype in varchar2, table_name in varchar2) AS
BEGIN
       EXECUTE IMMEDIATE 'DROP ' ||ttype||' '||table_name;
END;
/
exec dropit('table','emp_copy');
/
select * from emp_copy;
 








3.1: Modify the programs created in Lab2 to implement Exception Handling

3.2 The following PL/SQL block attempts to calculate bonus of staff for a given MGR_CODE. Bonus is to be considered as twice of salary. Though Exception Handling has been implemented but block is unable to handle the same.
Debug and verify the current behavior to trace the problem.

DECLARE
V_BONUS V_SAL%TYPE;
V_SAL STAFF_MASTER.STAFF_SAL%TYPE;

BEGIN
SELECT STAFF_SAL INTO V_SAL
FROM STAFF_MASTER 
WHERE MGR_CODE=100006;

V_BONUS:=2*V_SAL;
DBMS_OUTPUT.PUT_LINE('STAFF SALARY IS ' || V_SAL);
DBMS_OUTPUT.PUT_LINE('STAFF BONUS IS ' || V_BONUS);

EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('GIVEN CODE IS NOT VALID.ENTER VALID CODE');
END;

Example 3: PL/SQL block
DECLARE
 V_BONUS number(10);
 V_SAL STAFF_MASTER.STAFF_SAL%TYPE;
 BEGIN
 SELECT STAFF_SAL INTO V_SAL
 FROM STAFF_MASTER
 WHERE MGR_CODE=100006;
 V_BONUS:=2*V_SAL;
 DBMS_OUTPUT.PUT_LINE('STAFF SALARY IS ' || V_SAL);
 DBMS_OUTPUT.PUT_LINE('STAFF BONUS IS ' || V_BONUS);
 EXCEPTION
 WHEN too_many_rows THEN
 DBMS_OUTPUT.PUT_LINE('GIVEN CODE IS NOT VALID.ENTER VALID CODE');
 END;
 

3.3 Rewrite the above block to achieve the requirement.
DECLARE
CURSOR c1 is SELECT STAFF_SAL, STAFF_SAL*2 "STAFF_BONUS"
FROM STAFF_MASTER 
WHERE MGR_CODE=100006;
BEGIN
FOR I IN C1 LOOP
DBMS_OUTPUT.PUT_LINE('STAFF SALARY IS ' || I.STAFF_SAL);
DBMS_OUTPUT.PUT_LINE('STAFF BONUS IS ' || I.STAFF_BONUS);
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('GIVEN CODE IS NOT VALID.ENTER VALID CODE');
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE('TOO MANY ROWS');
END;
 
3.4
Predict the output of the following block ? What corrections would be needed to make it more efficient?



BEGIN
      DECLARE
      fname emp.ename%TYPE;
      BEGIN
      SELECT ename INTO fname
      FROM emp
      WHERE 1=2;

      DBMS_OUTPUT.PUT_LINE('This statement will print');
      EXCEPTION
      WHEN OTHERS THEN
      DBMS_OUTPUT.PUT_LINE('Some inner block error');
      END;

 EXCEPTION
 WHEN NO_DATA_FOUND THEN
 DBMS_OUTPUT.PUT_LINE('No data found in fname');

 WHEN OTHERS THEN
 DBMS_OUTPUT.PUT_LINE('Some outer block error');
 END;
BEGIN
      DECLARE
      CURSOR c1 is SELECT ename FROM emp WHERE 1=2;
      fname emp.ename%TYPE;
      BEGIN
      OPEN C1;
      FETCH C1 INTO fname;
      DBMS_OUTPUT.PUT_LINE('This statement will print');
      CLOSE C1;
      EXCEPTION
      WHEN OTHERS THEN
      DBMS_OUTPUT.PUT_LINE('Some inner block error');
      END;
 EXCEPTION
 WHEN NO_DATA_FOUND THEN
 DBMS_OUTPUT.PUT_LINE('No data found in fname');
 WHEN OTHERS THEN
 DBMS_OUTPUT.PUT_LINE('Some outer block error');
 END;
 
3.5 Debug the above block to trace the flow of control. 
      Additionally one can make appropriate changes in Select statement defined in the 
      block to check the flow.


3.6: Write a PL/SQL program to check for the commission for an employee no 7369. If no commission exists, then display the error message. Use Exceptions. 

 DECLARE
 CURSOR C1 IS SELECT comm
 FROM emp
 WHERE empno=7369;
 excep EXCEPTION;
 BEGIN
 FOR I IN C1 LOOP
 DBMS_OUTPUT.PUT_LINE(i.comm);
 END LOOP;
 IF null is null then
 raise excep;
 else null;
 end if;
 EXCEPTION
 when excep then
 null;
 DBMS_OUTPUT.PUT_LINE('COMMISION IS NULL');
 END;
 
3.7: Write a PL/SQL block to drop any user defined table.
CREATE OR REPLACE PROCEDURE dropit (ttype in varchar2, table_name in varchar2) AS
BEGIN
       EXECUTE IMMEDIATE 'DROP ' ||ttype||' '||table_name;
END;
/
exec dropit('table','emp_copy');
/
select * from emp_copy;
 








3.1: Modify the programs created in Lab2 to implement Exception Handling

3.2 The following PL/SQL block attempts to calculate bonus of staff for a given MGR_CODE. Bonus is to be considered as twice of salary. Though Exception Handling has been implemented but block is unable to handle the same.
Debug and verify the current behavior to trace the problem.

DECLARE
V_BONUS V_SAL%TYPE;
V_SAL STAFF_MASTER.STAFF_SAL%TYPE;

BEGIN
SELECT STAFF_SAL INTO V_SAL
FROM STAFF_MASTER 
WHERE MGR_CODE=100006;

V_BONUS:=2*V_SAL;
DBMS_OUTPUT.PUT_LINE('STAFF SALARY IS ' || V_SAL);
DBMS_OUTPUT.PUT_LINE('STAFF BONUS IS ' || V_BONUS);

EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('GIVEN CODE IS NOT VALID.ENTER VALID CODE');
END;

Example 3: PL/SQL block
DECLARE
 V_BONUS number(10);
 V_SAL STAFF_MASTER.STAFF_SAL%TYPE;
 BEGIN
 SELECT STAFF_SAL INTO V_SAL
 FROM STAFF_MASTER
 WHERE MGR_CODE=100006;
 V_BONUS:=2*V_SAL;
 DBMS_OUTPUT.PUT_LINE('STAFF SALARY IS ' || V_SAL);
 DBMS_OUTPUT.PUT_LINE('STAFF BONUS IS ' || V_BONUS);
 EXCEPTION
 WHEN too_many_rows THEN
 DBMS_OUTPUT.PUT_LINE('GIVEN CODE IS NOT VALID.ENTER VALID CODE');
 END;
 

3.3 Rewrite the above block to achieve the requirement.
DECLARE
CURSOR c1 is SELECT STAFF_SAL, STAFF_SAL*2 "STAFF_BONUS"
FROM STAFF_MASTER 
WHERE MGR_CODE=100006;
BEGIN
FOR I IN C1 LOOP
DBMS_OUTPUT.PUT_LINE('STAFF SALARY IS ' || I.STAFF_SAL);
DBMS_OUTPUT.PUT_LINE('STAFF BONUS IS ' || I.STAFF_BONUS);
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('GIVEN CODE IS NOT VALID.ENTER VALID CODE');
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE('TOO MANY ROWS');
END;
 
3.4
Predict the output of the following block ? What corrections would be needed to make it more efficient?



BEGIN
      DECLARE
      fname emp.ename%TYPE;
      BEGIN
      SELECT ename INTO fname
      FROM emp
      WHERE 1=2;

      DBMS_OUTPUT.PUT_LINE('This statement will print');
      EXCEPTION
      WHEN OTHERS THEN
      DBMS_OUTPUT.PUT_LINE('Some inner block error');
      END;

 EXCEPTION
 WHEN NO_DATA_FOUND THEN
 DBMS_OUTPUT.PUT_LINE('No data found in fname');

 WHEN OTHERS THEN
 DBMS_OUTPUT.PUT_LINE('Some outer block error');
 END;
BEGIN
      DECLARE
      CURSOR c1 is SELECT ename FROM emp WHERE 1=2;
      fname emp.ename%TYPE;
      BEGIN
      OPEN C1;
      FETCH C1 INTO fname;
      DBMS_OUTPUT.PUT_LINE('This statement will print');
      CLOSE C1;
      EXCEPTION
      WHEN OTHERS THEN
      DBMS_OUTPUT.PUT_LINE('Some inner block error');
      END;
 EXCEPTION
 WHEN NO_DATA_FOUND THEN
 DBMS_OUTPUT.PUT_LINE('No data found in fname');
 WHEN OTHERS THEN
 DBMS_OUTPUT.PUT_LINE('Some outer block error');
 END;
 
3.5 Debug the above block to trace the flow of control. 
      Additionally one can make appropriate changes in Select statement defined in the 
      block to check the flow.


3.6: Write a PL/SQL program to check for the commission for an employee no 7369. If no commission exists, then display the error message. Use Exceptions. 

 DECLARE
 CURSOR C1 IS SELECT comm
 FROM emp
 WHERE empno=7369;
 excep EXCEPTION;
 BEGIN
 FOR I IN C1 LOOP
 DBMS_OUTPUT.PUT_LINE(i.comm);
 END LOOP;
 IF null is null then
 raise excep;
 else null;
 end if;
 EXCEPTION
 when excep then
 null;
 DBMS_OUTPUT.PUT_LINE('COMMISION IS NULL');
 END;
 
3.7: Write a PL/SQL block to drop any user defined table.
CREATE OR REPLACE PROCEDURE dropit (ttype in varchar2, table_name in varchar2) AS
BEGIN
       EXECUTE IMMEDIATE 'DROP ' ||ttype||' '||table_name;
END;
/
exec dropit('table','emp_copy');
/
select * from emp_copy;
 







stdout
Standard output is empty