Вы находитесь на странице: 1из 3

DECLARE CURSOR cur_withpar (deptno NUMBER) IS SELECT employee_id, last_name FROM employees_aditya WHERE department_id = deptno; emp_id employees_aditya.

employee_id%type; lname employees_aditya.last_name%type; BEGIN OPEN cur_withpar (&deptno.); fetch cur_withpar into emp_id,lname; dbms_output.put_line('employee id is: ' emp_id); dbms_output.put_line('last name is: ' lname); CLOSE cur_withpar; end; /

declare cursor all_emp20 is select employee_id,last_name from employees_aditya where department_id=20; emp_id employees_aditya.employee_id%type; lname employees_aditya.last_name%type; begin open all_emp20; loop fetch all_emp20 into emp_id, lname; exit when all_emp20%notfound; dbms_output.put_line('employee no. ' all_emp20%rowcount ' is:' lname ' with employee_id ' emp_id); end loop; end; / create procedure max_deptno is max_deptno number; begin select max(department_id) into max_deptno from departments_aditya; dbms_output.put_line('maximum department no. is: ' max_deptno); end;

create or replace function sum_salary(dept_no employees_aditya.department_id%typ e) return number is sumsal number; begin select sum(salary) into sumsal from employees_aditya where department_id=dept_n o; return sumsal; EXCEPTION WHEN NO_DATA_FOUND THEN dbms_output.put_line('no data found'); RETURN NULL; end; /

------------package spec-------------create or replace package pack7and8 as max_deptno number; sumsal number; procedure max_deptnum; function sum_salary(dept_no employees_aditya.department_id%type) return number ; end pack7and8; ------package body-------------

CREATE OR REPLACE PACKAGE BODY pack7and8 is procedure max_deptnum is max_deptno number; begin select max(department_id) into max_deptno from departments_aditya; dbms_output.put_line('maximum department no. is: ' max_deptno); end max_deptnum; function sum_salary(dept_no employees_aditya.department_id%type) return number is sumsal number; begin select sum(salary) into sumsal from employees_aditya where department_id=dept_n o; return sumsal; EXCEPTION WHEN NO_DATA_FOUND THEN dbms_output.put_line('no data found'); RETURN NULL; end sum_salary; end pack7and8; --------------------------------------------

declare e exception; empid number; lname varchar2(50); begin select employee_id,last_name into empid,lname from employees_aditya where employee_id=&emp_id; if (empid=206) then raise e; end if; dbms_output.put_line('the last name of employee is: ' lname); exception when e then dbms_output.put_line('employee id is wrong'); when no_data_found then dbms_output.put_line('no data found');

end; declare e exception; empid number; begin select employee_id into empid from employees_aditya where employee_id=&emp_id;

CREATE OR REPLACE TRIGGER instead_aditya INSTEAD OF INSERT OR UPDATE OR DELETE ON departments_aditya_v FOR EACH ROW BEGIN null; END; / if (empid>500) then raise e; end if; dbms_output.put_line('the last name of employee is: ' lname); declare e exception; empid number; begin select employee_id into empid from employees_aditya where employee_id=&emp_id; if (empid>500) then raise e; end if; dbms_output.put_line('the last name of employee is: ' lname); when e then dbms_output.put_line('employee id is wrong'); when no_data_found then dbms_output.put_line('no data found'); end;

Вам также может понравиться