Database Interaction with PL/SQL, User-defined Packages - Database interaction using a PACKAGE
(Page 2 of 5 )
There would be nothing new in this section apart from the syntax of package. All the procedures and functions being implemented inside the package have been thoroughly discussed in my previous articles. So, let us have a good example of using a package interacting with a database.
create or replace package SamplePkg as
procedure dispEmp;
procedure dispDept;
end SamplePkg;
/
create or replace package body SamplePkg as
procedure dispEmp as
cursor c_emp is
select ename, sal from emp;
begin
for r_emp in c_emp
loop
dbms_output.put_line (r_emp.ename || ',' || r_emp.sal);
end loop;
end;
procedure dispDept as
cursor c_dept is
select deptno,dname from dept;
begin
for r_dept in c_dept
loop
dbms_output.put_line (r_dept.deptno || ',' ||
r_dept.dname);
end loop;
end;
end SamplePkg;
/
To execute each of those procedures separately, you can use the following commands:
execute SamplePkg.dispEmp;
execute SamplePkg.dispDept;
Next: Overloading sub-programs in a PACKAGE >>
More Oracle Articles
More By Jagadish Chatarji