Thursday 17 March 2016

Creating Data Block using Package and Procedure in Oracle 10g

As salamo alaikum wa rahmatullah

create table tbl_mst_student (roll number(3),
name varchar2(50),course varchar2(50))

create or replace package mypack
is
type student_rec is record (stud_id tbl_mst_student.roll%type,sname tbl_mst_student.name%type,scourse tbl_mst_student.course%type);
type stub is table of student_rec index by binary_integer;
procedure stuqry(data IN OUT stub);
procedure stuins(data IN stub);
end mypack;


create or replace package body mypack
is
procedure stuqry(data IN OUT stub)
is 
i number;
cursor cstudent is select * from tbl_mst_student;
begin
open cstudent;
i:=1;
loop
fetch cstudent into data(i).stud_id,data(i).sname,data(i).scourse;
exit when cstudent%notfound;
end loop;
close cstudent;
end stuqry;

procedure stuins(data IN stub)
is
i number;
ct number;
begin
ct:=data.count;
for i in 1..ct loop 
insert into tbl_mst_student values(data(i).stud_id,data(i).sname,data(i).scourse);
commit;
end loop;
end stuins;
end mypack;
/



select * from tbl_mst_student






Ma Asalaam
---------------
Passion 4 Oracle

No comments:

Post a Comment