Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- EX1
- ---------------------------------------------------------------------
- CREATE OR replace FUNCTION f2 (v_id employees.department_id%type )
- RETURN varchar2 IS nume employees.last_name%type;nume2 employees.last_name%type;
- BEGIN
- SELECT last_name
- INTO nume
- FROM employees
- WHERE v_id=employees.department_id
- AND salary =
- (
- SELECT max(salary)
- FROM employees);
- for k IN
- (
- SELECT last_name nume2
- FROM employees
- WHERE v_id = department_id)
- loop dbms_output.put_line('Angajat din dep :' || k.nume2);
- end loop;
- return nume;
- exception
- WHEN no_data_found THEN
- raise_application_error(-20000, 'Nu exista angajati cu numele dat');
- when too_many_rows THEN
- raise_application_error(-20001, 'Exista mai multi angajati cu numele dat');
- when others THEN
- raise_application_error(-20002,'Alta eroare!');
- end f2;
- BEGIN
- dbms_output.put_line('Salariul este '|| f2(90));END;
- EX2
- -------------------------------------------------------------
- CREATE OR replace PROCEDURE f3 (v_nume employees.last_name%type, v_nume1 employees.first_name%type ) IS nume employees.last_name%type;
- var1 varchar2(35) :='IT Support';var2 varchar2(35) :='Benefits';v3 varchar(35);BEGIN
- SELECT department_name
- INTO v3
- FROM departments,
- employees
- WHERE v_nume = employees.last_name
- AND departments.department_id = employees.department_id
- AND v_nume1=employees.first_name;
- IF var1 = v3 then
- dbms_output.put_line('IT Support');
- elsif var2 = v3 THEN
- dbms_output.put_line('Benefits');
- else dbms_output.put_line('NU');
- endif;
- exception
- WHEN no_data_found THEN
- raise_application_error(-20000, 'Nu exista angajati cu numele dat');
- when too_many_rows THEN
- raise_application_error(-20001, 'Exista mai multi angajati cu numele dat');
- when others THEN
- raise_application_error(-20002,'Alta eroare!');
- ENDf3;/
- BEGIN
- f3('King', 'Steven');END;/
- EX 3
- ---------------------------------------------------------------------------
- CREATE OR replace TRIGGER trig21 beforeupdate OF salary ON employees FOR each rowdeclare sal_max employees.salary%type;BEGIN
- SELECT Max(salary)
- INTO sal_max
- FROM employees;
- IF (:new.salary > sal_max) then
- raise_application_error(-20007,'salariul nu poate fi marit');
- endif;
- END;/UPDATE employees
- SET salary = 25000;DROP TRIGGER trig21;/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement