Thursday, February 15, 2018

Programs ADS Lab

Tags

20.

CREATE PACKAGE emp_sal1 AS  
   PROCEDURE find_sal(empid emp7567.id%type);  
END emp_sal1;
 
Output:

 
 
 
CREATE OR REPLACE PACKAGE BODY emp_sal1 AS   
    
   PROCEDURE find_sal(empid emp7567.id%TYPE) IS  
   c_sal emp7567.salary%TYPE;  
   BEGIN  
      SELECT salary INTO c_sal  
      FROM emp7567  
      WHERE id = empid;  
      dbms_output.put_line('Salary: '|| c_sal);  
   END find_sal;  
END emp_sal1; 
 
 
DECLARE  
   empid emp7567.id%type :=1507567;  
BEGIN  
   emp_sal1.find_sal(empid);  
END;   



21.

Code:

declare
empid emp7567.id%type := &id;
row emp7567%rowtype;
invalid exception;
begin
if empid<=0 then
raise invalid;   --userdefined exception
end if;
select * into row   from emp7567 where id= empid;
dbms_output.put_line('Name ' || row.name);
EXCEPTION
   WHEN no_data_found THEN     --system defined
      dbms_output.put_line('No such Employee!');
   WHEN invalid THEN
      dbms_output.put_line('Error! Invalid Id');
END;