0% found this document useful (0 votes)
103 views28 pages

Display The Hire Date For The Employee With Id 110

This document contains PL/SQL code snippets that demonstrate the use of cursors to retrieve and manipulate data from database tables. Some key examples include: 1. Using cursors to retrieve and display employee hire dates, salaries before and after updates, and region names that start with A/a. 2. Summing odd and even numbers extracted from a string using a cursor and loop. 3. Updating order dates by adding or subtracting weeks using cursors with FOR UPDATE clauses. 4. Displaying customer names and their orders by nesting one cursor within another used as a parameter. 5. Retrieving the top 5 largest order values from an orders table using a cursor and exit

Uploaded by

Adina
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
103 views28 pages

Display The Hire Date For The Employee With Id 110

This document contains PL/SQL code snippets that demonstrate the use of cursors to retrieve and manipulate data from database tables. Some key examples include: 1. Using cursors to retrieve and display employee hire dates, salaries before and after updates, and region names that start with A/a. 2. Summing odd and even numbers extracted from a string using a cursor and loop. 3. Updating order dates by adding or subtracting weeks using cursors with FOR UPDATE clauses. 4. Displaying customer names and their orders by nesting one cursor within another used as a parameter. 5. Retrieving the top 5 largest order values from an orders table using a cursor and exit

Uploaded by

Adina
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 28

Sgbd

---Display the hire date for the employee with id 110

set serveroutput on
declare
v_emp employees%rowtype;
begin
select * into v_emp from employees where employee_id = 110;
dbms_output.put_line('Employee '|| v_emp.first_name || ' ' || v_emp.last_name || ' was hired
on ' || v_emp.hire_date);
end;
/
or

set serveroutput on

declare

type t_emp is record(

first_name employees.first_name%type,

last_name employees.last_name%type,

hire_date date

);

v_emp t_emp;

begin

select first_name, last_name , hire_date into v_emp from employees where employee_id = 110;

dbms_output.put_line('Employee '|| v_emp.first_name || ' ' || v_emp.last_name || ' was hired


on ' || v_emp.hire_date);

end;

--Change the salary for employee with id 125

set serveroutput on
declare

v_salary number;

begin

select salary into v_salary from employees where employee_id = 125;

dbms_output.put_line('Before: ' || v_salary);

if v_salary < 10000 then

v_salary := v_salary * 1.1; --10%

else

v_salary := v_salary * 1.05; --5%

end if;

dbms_output.put_line('After: ' || v_salary);

end;

When case

declare

v_grade number :=15;

begin

case

when (round(v_grade) <> v_grade) then

dbms_output.put_line('Has decimals!');

when v_grade is null then

dbms_output.put_line('Absent!');

when v_grade between 0 and 4 then

dbms_output.put_line('Failed!');

when v_grade between 5 and 10 then

dbms_output.put_line('Passed!');

--else

-- dbms_output.put_line('Wrong mark!');

end case;

exception when others then null;

end;
--SUM OF ODD AND EVEN NUMBERS FROM STRING

set serveroutput on

declare

v_string varchar2(30) := '42375423854826';

sum_odd number := 0;

sum_even number := 0;

c char;

begin

for i in 1..length(v_string) loop

dbms_output.put_line(i);

c := substr(v_string, i, 1);

if c mod 2 = 0 then

sum_even := sum_even + c;

else

sum_odd := sum_odd + c;

end if;

end loop;

dbms_output.put_line('Sum of evens: ' || sum_even);

dbms_output.put_line('Sum of odd: ' || sum_odd);

end;

--Create a SP that update the salary of a given employee (by substitution) for the following cases:

-- 0 - 3500 (increase of the salary with 10 %)

-- 3501 - 7500 increase of the salary with 5 %)

-- 7501 - 15000 increase of the salary with 2 %)

-- else the salary will have a decrease with 5%.

set serveroutput on

set define on

declare
v_salary employees.salary%type;

begin

select salary into v_salary from employees where employee_id = &v_id;

dbms_output.put_line('Initial salary: '|| v_salary);

if v_salary between 0 and 3500 then

v_salary := v_salary*1.1;

elsif v_salary between 3501 and 7500 then

v_salary := v_salary* 1.05;

elsif v_salary between 7501 and 1500 then

v_salary := v_salary * 1.02;

else

v_salary := v_salary * 0.95;

end if;

dbms_output.put_line('Final salary: ' || v_salary);

end;

----------------------------------------------------------------------------------

--1. Delete a row from Product_information table and count the number of deleted ones.

set serveroutput on

declare

nb_r number(2);

begin

delete from product_information where product_id = 100;

nb_r := SQL%ROWCOUNT;

dbms_output.put_line(nb_r || ' rows deleted.');

commit;

end;

--------------------------------------------------------------------------------------------
--2.Try to modify the name of the product 113. If the product doesn't exist(the update command
won't modify anything),

--display a message.

begin

update product_information set product_name = 'PC' where product_id = 113;

if SQL%NOTFOUND then

dbms_output.put_line('The product 113 doesn''t exist');

end if;

end;

--3. Display and calculate salary after apply taxes:

if salary > 2000 => apply taxes of 16%

if salary < 2000 => taxes won''t be applied.

declare

cursor c is select salary from employees;

row_c c%rowtype;

begin

open c;

loop

fetch c into row_c;

dbms_output.put_line('Initial salary: ' || row_c.salary);

if row_c.salary > 200 then

row_c.salary := row_c.salary * 0.86;

else row_c.salary := row_c.salary;

end if;

dbms_output.put_line('After taxes: '|| row_c.salary);

exit when c%notfound;

end loop;
close c;

end;

----------------------------------------------------------------------------------

-- 4. Display the regions that begin with 'A' or 'a'

declare

cursor c is select region_name from regions where upper(region_name) like 'A%';

row_c c%rowtype;

begin

open c;

loop

fetch c into row_c;

exit when c%notfound;

dbms_output.put_line(row_c.region_name);

end loop;

close c;

end;

-- 5. Display the regions that begin with 'A' or 'a' using for loop

********************************************************************************

declare

cursor c is select region_name from regions where upper(region_name) like 'A%';

begin

for region in c loop

dbms_output.put_line(region.region_name);

end loop;

end;

-- 6.Display the products that have a total ordered quantity larger than a value received as a
parameter
declare

cursor c(p_val number) is

select p.product_id prod ,sum(quantity ) total_q

from product_information p, order_items o

where p.product_id = o.product_id

group by p.product_id

having sum( quantity ) > p_val

order by total_q desc;

v_val NUMBER(5);

rec_prod c%rowtype;

BEGIN

v_val:=50;

DBMS_OUTPUT.PUT_LINE('The products that have a total ordered quantity larger than '|| v_val);

IF NOT c%ISOPEN THEN

OPEN c (v_val);

END IF;

LOOP

FETCH c into rec_prod;

EXIT WHEN c%notfound;

DBMS_OUTPUT.PUT_LINE(rec_prod.total_q||' pieces of product '||rec_prod.prod||' were


ordered');

END LOOP;

CLOSE c;

END;

--Display the most expensive 3 products.

declare

cursor c is select product_name, list_price from product_information where list_price is not null
order by list_price desc;

product c%rowtype;

begin
open c;

loop

fetch c into product;

exit when c%notfound or c%rowcount=4;

dbms_output.put_line(product.product_name|| ' ' || product.list_price);

end loop;

close c;

end;

-- Display the total quantity bought for each product.

declare

cursor c is select product_id id, sum(quantity) total from order_items group by product_id order by
total desc;

product c%rowtype;

begin

open c;

loop

fetch c into product;

exit when c%notfound;

dbms_output.put_line(product.id || ' ' || product.total);

end loop;

close c;

end;

OR

begin

dbms_output.put_line('Total quantity for each product:');

for rec in

(select p.product_id prod, sum(quantity) total_quantity

from product_information p, order_items o

where p.product_id=o.product_id

group by p.product_id)

loop
dbms_output.put_line(rec.total_quantity||' pieces of product '||rec.prod||' were ordered');

end loop;

end;

For Orders table update the order_date by adding a week to each date. Use a FOR UPDATE cursor to
block the rows in the table when the cursor is opened.

DECLARE

CURSOR c IS SELECT * FROM orders

FOR UPDATE OF order_date NOWAIT;

BEGIN

FOR rec IN c LOOP

DBMS_OUTPUT.PUT_LINE('The order '||rec.order_id||' has the date: '||rec.order_date);

UPDATE orders

SET order_date=order_date+7

WHERE order_id=rec.order_id;

DBMS_OUTPUT.PUT_LINE('The order '||rec.order_id||' has the date: '||rec.order_date);

END LOOP;

END;

--For Orders table update the order_date by decreasing it by one week. Use FOR UPDATE and
WHERE CURRENT OF clauses.

DECLARE

CURSOR c IS

SELECT *

FROM orders

FOR UPDATE OF order_date NOWAIT;

BEGIN

FOR rec IN c LOOP

DBMS_OUTPUT.PUT_LINE('The order '||rec.order_id||' has the date: '||rec.order_date);

UPDATE orders

SET order_date=order_date-7

WHERE CURRENT OF c;

DBMS_OUTPUT.PUT_LINE('The order '||rec.order_id||' has the date: '||rec.order_date);

END LOOP;
END;

Display all the customers and their orders. Use a cursor to load the customer’s name and another
cursor with parameter to load their orders

declare

cursor c is

select customer_id, cust_first_name, cust_last_name from customers c;

cursor c2 (c_id number) is

select * from orders where customer_id = c_id;

begin

for rec in c loop

dbms_output.put_line(rec.cust_first_name || ' '|| rec.cust_last_name);

for rec2 in c2 (rec.customer_id) loop

dbms_output.put_line(rec2.order_id);

end loop;

end loop;

end;

Display the orders that have the largest value. Stop after the first 5 orders.

declare

cursor c is

select order_id, order_total from orders order by order_total desc;

product c%rowtype;

begin

open c;

loop

fetch c into product;

exit when c%rowcount >5;

dbms_output.put_line(product.order_id || ' ' || product.order_total);

end loop;

close c;

end;
--Display product names for the products that have been orderd at least once

set serveroutput on

declare

cursor c is

select distinct product_name from product_information p join order_items o on p.product_id =


o.product_id order by product_name;

r varchar2(50);

begin

if not c%isopen then

open c;

end if;

loop

fetch c into r;

dbms_output.put_line(c%rowcount || '->' || r);

exit when c%notfound;

end loop;

close c;

end;

-- display the product name and the list_price

set serveroutput on

declare

cursor c is

select product_name, list_price from product_information order by list_price desc;

r c%rowtype;

begin

for r in c loop

dbms_output.put_line(c%rowcount || '->'|| r.product_name || ' has the price: ' || r.list_price);

end loop;

end;

OR
set serveroutput on

declare

cursor c is

select distinct product_name, list_price

from product_information p join order_items o

on p.product_id = o.product_id

order by list_price desc;

r c%rowtype;

begin

if not c%isopen then

open c;

end if;

loop

fetch c into r;

dbms_output.put_line(c%rowcount || '->'|| r.product_name || '-'|| r.list_price);

exit when c%notfound;

end loop;

close c;

end;

--3. Get top 10 products according to mean price

set serveroutput on

declare

cursor c is select distinct product_name, (list_price + min_price)/2 mean_price

from product_information p join order_items o

on p.product_id = o.product_id

order by mean_price desc;

r c%rowtype;

begin

for r in c loop

dbms_output.put_line(r.product_name || ' has the price ' || r.mean_price);


exit when c%notfound or c%rowcount > 9;

end loop;

end;

OR

set serveroutput on

declare

cursor c is select distinct product_name, (list_price + min_price)/2 mean_price

from product_information p join order_items o

on p.product_id = o.product_id

order by mean_price desc;

r c%rowtype;

begin

if not c%isopen then

open c;

end if;

loop

fetch c into r;

DBMS_OUTPUT.PUT_LINE(c%rowcount || '=>' || r.product_name || ' has the price ' ||


r.mean_price);

exit when c%notfound or c%rowcount > 9;

end loop;

close c;

end;

OR

set serveroutput on

declare

i pls_integer := 0;

begin
for r in (select distinct product_name, (list_price + min_price)/2 mean_price

from product_information p join order_items o

on p.product_id = o.product_id

order by mean_price desc)

loop

i := i+1;

exit when i=10;

DBMS_OUTPUT.PUT_LINE(i || '=>' || r.product_name || ' has the price ' || r.mean_price);

end loop;

end;

Display the department names of the departments which have employees. Under each department
display the names of the employees from that department.

+ the number of employees per department and the total number allover

set serveroutput on

declare

cursor c is

select distinct d.department_name , d.department_id

from departments d

join employees e

on e.department_id = d.department_id;

cursor c2(c_id number) is

select first_name, last_name from employees where department_id = c_id;

nr1 number;

nr2 number :=0;

begin

for r1 in c loop

nr1 := 0;

dbms_output.put_line (r1.department_name);

for r2 in c2(r1.department_id) loop

dbms_output.put_line(' ' || r2.first_name || ' ' || r2.last_name);


nr1 := nr1 + 1;

nr2 := nr2 + 1;

end loop;

dbms_output.put_line(nr1);

end loop;

dbms_output.put_line(nr2);

end;

Change the salary for the employee with id 50:

set serveroutput on

declare

cursor c is select employee_id, salary

from employees where department_id = 50 for update;

sal_before number;

sal_after number;

begin

select sum(salary) into sal_before from employees where department_id = 50;

for r in c loop

update employees set salary = salary * 1.05 --5%

where current of c;

end loop;

select sum(salary) into sal_after from employees where department_id = 50;

dbms_output.put_line(sal_before || '->' || sal_after);

rollback;

end;

--PRE-DEFINED EXCEPTION

--Display the product 13. If there is no such product, handle the exception.

DECLARE

name VARCHAR2(20);

BEGIN
SELECT product_name INTO name

FROM product_information

WHERE product_id=13;

dbms_output.put_line(name);

EXCEPTION

WHEN NO_DATA_FOUND THEN

dbms_output.put_line('The product doesn''t exist!');

END;

--NON-PREDEFINED EXCEPTION

--Insert a row in the Locations table. For the location_id use the value 213 and for the coutry_id use
NULL. An exception having the code ORA-01400 will be automatically raised. Handle the exception
regarding violating the integrity constraint.

DECLARE

INSERT_EXCEPT EXCEPTION;

PRAGMA EXCEPTION_INIT(INSERT_EXCEPT, -01400);

BEGIN

insert into locations (location_id, country_id) values ('213', NULL);

EXCEPTION

WHEN insert_except THEN

DBMS_OUTPUT.PUT_LINE('country_id cannot be null');

DBMS_OUTPUT.PUT_LINE(SQLERRM);

END;

--USER-DEFINED EXCEPTION

--Raise an error if the user tries to execute the PL/SQL block before 5 o’clock pm.

DECLARE

e_exc1 EXCEPTION;

BEGIN

IF TO_NUMBER(TO_CHAR(SYSDATE, 'HH24'))<=17 THEN

RAISE e_exc1;

END IF;

EXCEPTION
WHEN e_exc1 THEN

dbms_output.put_line('It is '||TO_CHAR(SYSDATE, 'HH24'));

dbms_output.put_line('Operation not yet allowed');

END;

User-defined exceptions can also be handled as Oracle exceptions, by giving them error codes and
error messages. In this case, the error code can have values between -20999 and -20000.

DECLARE

e_exc1 EXCEPTION;

PRAGMA EXCEPTION_INIT(e_exc1, -20600);

BEGIN

IF TO_NUMBER(TO_CHAR(SYSDATE, 'HH24'))<=17 THEN

RAISE_application_error(-20600,'error message');

END IF;

EXCEPTION

WHEN e_exc1 THEN

dbms_output.put_line('It is '||TO_CHAR(SYSDATE, 'HH24'));

dbms_output.put_line('Operation not yet allowed');

dbms_output.put_line(sqlerrm);

END;

--Display 1st 3 products by a category given, orderd by list price

create or replace procedure display_categ(categ varchar2) is

cursor c is select product_name from product_information

where category_id=categ and list_price is not null

order by list_price desc;

begin

for r in c loop

exit when c%rowcount>3;

dbms_output.put_line(r.product_name);

end loop;

end;

/
begin

display_categ(15); --hardware

end;

--Procedure with IN parameters

--Create a procedure that modifies the salary of an employee whose id is given as parameter. Also
the percentage of salary growth is given as a parameter.

CREATE OR REPLACE PROCEDURE

modify_salary(v_employee_id IN number, percent number)

IS v_salary number;

BEGIN

select salary into v_salary from employees where employee_id = v_employee_id;

dbms_output.put_line('The employee has the salary:'||v_salary);

update employees

set salary=salary*(1+percent/100)

where employee_id=v_employee_id;

select salary into v_salary from employees where employee_id=v_employee_id;

dbms_output.put_line('The employee has the salary:'||v_salary);

END;

EXECUTE modify_salary(176, 10);

begin

modify_salary(176, 10);

end;

--Procedure with OUT parametres

--Create a procedure that returns the name and the salary of an employee whose id is given.

CREATE OR REPLACE PROCEDURE


proc_employee(p_employee_id IN number,

p_name OUT varchar2,

p_salary OUT number)

IS

BEGIN

select first_name,salary into p_name, p_salary from employees

where employee_id = p_employee_id;

END;

--The call:

DECLARE

v_name varchar2(50);

v_salary number;

BEGIN

proc_employee(150, v_name, v_salary);

dbms_output.put_line('The employee '||v_name||' has the salary: '||v_salary);

END;

--Create a procedure that calculates the average salary and returns it. Use a host variable.

create or replace procedure

avg_salary(p_salary out number)

is

begin

select avg(salary) into p_salary from employees;

end;

declare

v_salary number;

begin

avg_salary(v_salary);

dbms_output.put_line(v_salary);

end;
--Write a SP that display for a specific employee his name, hire date and seniority

create or replace procedure

display_employee(p_id in number, p_name OUT varchar2, p_seniority OUT number)

IS

begin

select first_name, round((sysdate-hire_date)/365,0) into p_name, p_seniority from employees

where employee_id = p_id;

end;

declare

v_name varchar2(20);

v_seniority number;

begin

display_employee(100,v_name,v_seniority);

dbms_output.put_line(v_name || ' ' || v_seniority);

end;

--Create a procedure that modifies the salary of all employees if their salary is smaller than the
average salary.

--The procedure receives the average salary and returns it after the updates have been made. It calls
the modify_salary procedure and uses 15 for the percentage.

create or replace procedure

modify_salary2(avg_salary in out number)

is

cursor c is select employee_id, salary from employees where salary<avg_salary;

begin

for emp in c loop

modify_salary(emp.employee_id,15);

end loop;

select avg(salary) into avg_salary from employees;

end;

declare
avg_salary number;

begin

select avg(salary) into avg_salary from employees;

dbms_output.put_line('The initial average salary: '||round(avg_salary));

modify_salary2(avg_salary);

dbms_output.put_line('The final average salary: '||round(avg_salary));

end;

: Create a function that returns TRUE/FALSE if the employee whose id is given has the salary
higher/smaller than the average. The function returns NULL if the employee doesn’t exist.

create or replace function check_salary(p_id IN employees.employee_id%type)

return boolean

is

v_avg_salary number;

v_salary number;

begin

select avg(salary) into v_avg_salary from employees;

dbms_output.put_line('Avg salary: ' || v_avg_salary);

select salary into v_salary from employees where employee_id = p_id;

if v_salary < v_avg_salary then

return true;

else

return false;

end if;

EXCEPTION

WHEN no_data_found THEN

return NULL;

end;

BEGIN

if check_salary(100) then
dbms_output.put_line('the salary is higher');

elsif (not check_salary(100)) then

dbms_output.put_line('the salary is smaller');

else

dbms_output.put_line('the employee doesn''t exist');

end if;

end;

-- a subprogram that will calculate the total income by department

create or replace procedure

calc_income is

v_sum number;

cursor c is select distinct department_id from employees order by department_id desc;

cursor c2(v_dep number) is select sum(salary) suma from employees where department_id = v_dep;

begin

for r in c loop

dbms_output.put_line(r.department_id);

for r2 in c2( r.department_id) loop

dbms_output.put_line (' ' || r2.suma);

end loop;

end loop;

end;

begin

calc_income;

end;

-- a subprogram that will calculate the total income by department -> nb employees, total income

-- variable for total income by sum of dep

create or replace procedure


calc_income_dep(p_department_id departments.department_id%type, nb_employees out number,
total_income out number) is

v_total_salaries number;

begin

select count(employee_id), sum(income_employee2(salary, commission_pct)) into nb_employees,


total_income

from employees where department_id = p_department_id;

v_total_salaries := v_total_salaries + total_income;

exception

when no_data_found then

dbms_output.put_line('It doesn''t exist a department with this ID!');

end calc_income_dep;

begin

v_total_salaries := 0;

end;

declare

v_nb number;

v_sal_tot number;

begin

p_employee_management.v_total_salaries := 0;

dbms_output.put_line('The department salary ' || p_employee_management.v_total_salaries);

p_employee_management.calc_income_dep(90, v_nb, v_sal_tot);

dbms_output.put_line('In the dep with id=90 are ' || v_nb || ' employees that have salary of ' ||
v_sal_tot);

dbms_output.put_line('The salary of departments is ' ||


p_employee_management.v_total_salaries);

end;
PACKAGE
set serveroutput on

create or replace package p_employee_management is

function search_employee(p_employee_id employees.employee_id%type) return


employees.first_name%type;

function search_employee(p_first_name employees.first_name%type, p_dep_id


departments.department_id%type)

return number;

function income_employee(p_employee_id employees.employee_id%type) return number;

function income_employee(p_salary employees.salary%type, p_com employees.commission_pct


%type) return number;

procedure calc_income_dep(p_department_id departments.department_id%type,

nb_employees out number, total_income out number);

v_total_salaries number;

end;

create or replace package body p_employee_management is

function search_employee(p_employee_id employees.employee_id%type) return


employees.first_name%type is

v_first_name employees.first_name%type;

begin

select first_name into v_first_name from employees where employee_id = p_employee_id;

return v_first_name;

exception

when no_data_found then

return null;

when too_many_rows then

v_first_name := 'Too many employees!';


return v_first_name;

end search_employee;

function search_employee(p_first_name employees.first_name%type, p_dep_id


departments.department_id%type)

return number is

v_sal number;

begin

select salary into v_sal from employees where first_name = p_first_name and department_id =
p_dep_id;

return v_sal;

exception

when no_data_found or too_many_rows then

return null;

end search_employee;

function income_employee(p_employee_id employees.employee_id%type) return number is

v_com employees.commission_pct%type;

v_sal number;

begin

select salary, commission_pct into v_sal, v_com from employees where employee_id =
p_employee_id;

return v_sal * (1 + nvl(v_com, 0)); -- nvl -> it will put a value everywhere where is null

exception

when no_data_found then

return null;

end income_employee;

function income_employee(p_salary employees.salary%type, p_com employees.commission_pct


%type) return number is

begin

return p_salary * (1 + nvl(p_com, 0));


end income_employee;

procedure calc_income_dep(p_department_id departments.department_id%type,

nb_employees out number, total_income out number) is

begin

select count(employee_id), sum(income_employee(salary, commission_pct)) into nb_employees,


total_income

from employees where department_id = p_department_id;

v_total_salaries := v_total_salaries + total_income;

exception

when no_data_found then

dbms_output.put_line('It doesn''t exist a department with this ID!');

end calc_income_dep;

begin

v_total_salaries := 0;

end;

-- call the package

declare

v_sal number;

v_nb number;

v_sal_tot number;

v_first_name varchar2(50);

begin

v_first_name := p_employee_management.search_employee(101);

dbms_output.put_line('The name of the employee with the id 101 is ' || v_first_name);


v_sal := p_employee_management.search_employee('King', 90);

dbms_output.put_line('The King salary is ' || v_sal);

p_employee_management.v_total_salaries := 0;

dbms_output.put_line('The department salary ' || p_employee_management.v_total_salaries);

p_employee_management.calc_income_dep(90, v_nb, v_sal_tot);

dbms_output.put_line('In the dep with id=90 are ' || v_nb || ' employees that have salary of ' ||
v_sal_tot);

dbms_output.put_line('The salary of departments is ' ||


p_employee_management.v_total_salaries);

p_employee_management.calc_income_dep(110, v_nb, v_sal_tot);

dbms_output.put_line('In the dep with id=110 are ' || v_nb || ' employees that have salary of ' ||
v_sal_tot);

dbms_output.put_line('The salary of departments is ' ||


p_employee_management.v_total_salaries);

p_employee_management.calc_income_dep(50, v_nb, v_sal_tot);

dbms_output.put_line('In the dep with id=50 are ' || v_nb || ' employees that have salary of ' ||
v_sal_tot);

dbms_output.put_line('The salary of departments is ' ||


p_employee_management.v_total_salaries);

end;

TRIGGERS
--avoid delete departments

create or replace trigger t_delete_dep

before delete on departments

begin

raise_application_error(-20000, 'You can''t delete data!');

end;
/

delete from departments where department_id = 90;

--disable trigger

alter trigger t_delete_dep disable;

--enagle trigger

alter trigger t_delete_dep enable;

--select trigger

select * from user_triggers where table_name = 'DEPARTMENTS';

You might also like