Handson PLSQL
Handson PLSQL
declare
V_RADIUS number(5);
V_AREA number(7,2);
pi constant number(3,2) :=3.14;
begin
V_RADIUS:=3;
while V_RADIUS<=7
loop
V_AREA:=pi*V_RADIUS*V_RADIUS;
insert into CIRCLE values(V_RADIUS,V_AREA );
V_RADIUS:=V_RADIUS+1;
end loop;
end;
/
-----------------------------------
------------------------------
Update Location
DECLARE
v_department_id number(5);
v_department_name varchar2(25);
v_location_id varchar2(15);
begin
select DEPARTMENT_ID,DEPARTMENT_NAME into v_department_id,v_department_name from
DEPARTMENT where LOCATION_ID LIKE 'HQ%';
UPDATE DEPARTMENT SET LOCATION_ID='HQ-BLR-101' WHERE DEPARTMENT_ID=v_department_id
AND DEPARTMENT_NAME=v_department_name;
end;
/
----------------------------
----------------------------------------
-----------------------------------
------------------------------
Department Details
set serveroutput on;
declare
cursor c_dept is select * from department order by department_id;
v_dept c_dept%rowtype;
begin
open c_dept;
dbms_output.put_line('Department Details are :');
loop
fetch c_dept into v_dept;
exit when c_dept%notfound;
dbms_output.put_line(v_dept.department_id||', '||v_dept.Department_name||', '||
v_dept.location_id);
end loop;
close c_dept;
end;
/
-------------------------------------------
Procedure with exception handling
---------------------------------------
---------------------------------------
Remove Employee records - Procedures
set serveroutput on;
create or replace procedure DELETE_EMPLOYEE(v_dept IN EMPLOYEE.DEPT%TYPE)
is
DeptNotFoundException exception;
begin
delete from employee where dept=v_dept;
if sql%found then
dbms_output.put_line(sql%rowcount||' Employee record(s) got deleted.');
else
raise DeptNotFoundException;
end if;
exception
when DeptNotFoundException then
dbms_output.put_line('No Records found.');
end;
/
------------------------
-------------------------------------------------
Package with a Procedure to Update Salary
-------------------------
insert a record-TRIGGER
------------------------------------
delete a record- TRIGGERS