Tuesday 25 June 2013

PL/SQL PACKAGE

PL/SQL PACKAGE

DEFINITION

A package is a schema object that groups logically related PL/SQL types, items, and subprograms. Packages usually have two parts, a specification and a body, although sometimes the body is unnecessary. 

EXAMPLE

select * from tb1;

create or replace package packs
is
procedure ab(x in number,y in number,z out number);

function bb(eid tb1.id%type)
return varchar;
end packs;


create or replace package body packs
is
procedure ab(x in number,y in number,z out number)
is
begin
z:=x+y;
dbms_output.put_line(z);
end;
function bb(eid tb1.id%type)
return varchar
is
ename tb1.name%type;
begin
select name into ename from tb1 where id=eid;
return (ename);
end;
end packs;


declare
x  number;
y  number;
z  number;
begin
x:=10;
y:=20;
packs.ab(x,y,z);
end;

declare
retname varchar2(20);
eid number;
begin
eid:=1217;
retname:=techebs.packs.bb(eid)

;
dbms_output.put_line(retname);
end;


select techebs.packs.bb(1217) from dual;

declare
z1 number;
begin
techebs.packs.ab(60,50,z1);
end;

No comments: