You are on page 1of 5

PL/SQL Assignment – 3

1.W.A.P to transfer all employee names from emp table and store it into index_by__table and
display the data

A. declare

Type INDEX_TABLE_ENAME is table of varchar2(10)

index by binary_integer;

v1 INDEX_TABLE_ENAME;

cursor c1 is select ename from emp;

N number(5):=1;

begin

open c1;

loop

fetch c1 into v1(n);

exit when c1%notfound;

DBMS_OUTPUT.PUT_LINE(v1(N));

N:=N+1;

end loop;

close c1;

end;

2.W.A.P to retrieve all join dates of emp from emp table and store it into index_by__table and
display the data

A.

declare

type INDEX_TABLE_HIRE is table of varchar2(10)

index by binary_integer;

V1 INDEX_TABLE_HIRE;

cursor c1 is select hiredate from emp;

N number(5):=1;

begin

open c1;

loop

GE Internal
fetch c1 into v1(n);

exit when c1%notfound;

DBMS_OUTPUT.PUT_LINE(v1(N));

N:=N+1;

end loop;

close c1;

end;

3.Select ename into bulk collect and display data

A. declare

type BULK_COLLECT is table of emp%rowtype

index by binary_integer;

v BULK_COLLECT;

begin

select * bulk collect into v from emp;

for i in v.first..v.last

loop

DBMS_OUTPUT.PUT_LINE(v(i).ename);

end loop;

end;

4.Using refcursor whenever user enter dept no display

(i) when 10 – display 10 dept from emp table

(ii) when 20 – display 20 dept from dept table

A.

declare 
type REF_CURSOR is ref cursor;
v1 REF_CURSOR;
i emp%rowtype;
j emp%rowtype;
v_deptno number(10):=:deptno;
begin
if v_deptno=10 then
open V1 for select * from emp where deptno=10;

GE Internal
loop
fetch v1 into i;
exit when v1%notfound;
dbms_output.put_line(i.ename||','||i.deptno);
end loop;
close v1;
elsif v_deptno=20 then 
open v11 for select * from dept where deptno=20;
loop
fetch v1 into j;
exit when v1%notfound;
dbms_output.put_line(j.ename||','||j.deptno);
end loop;
close v1;
end;
5.W.A.P to transfer all empnames from emp table and store it into nested table and display data

A. declare

type NESTED_TABLE is table of varchar2(25);

v NESTED_TABLE:=NESTED_TABLE();

cursor E_NAME is select ename from emp;

n number(10):=1;

begin

for

i in E_NAME

loop

v.extend();

v(n):=i.ename;

n:=n+1;

end loop;

for i in v.first..v.last

loop

dbms_output.put_line(v(i));

end loop;

end;

6.W.A.P to transfer first 10 empname from emp and export into varray and display data

A. declare

GE Internal
type V_ARRAY is varray(50) of emp%rowtype;

v V_ARRAY:=V_ARRAY();

begin

select * bulk collect into v from emp;

for i in v.first..v.next(9)

loop

DBMS_OUTPUT.PUT_LINE(v(i).ename);

end loop;

end;

7.W.A.P in PL/SQL stored procedure to modify salary of clerk from emp table and this modified value
should be stored into index_by_table and display data

A. create or replace procedure INDEX_BY_TABLE is

type STORED_INDEX_TABLE is table of emp%rowtype

index by binary_integer;

V1 STORED_INDEX_TABLE;

begin

update emp set sal=sal+500 where job='CLERK'

returning empno,ename,job,mgr,hiredate,sal,comm,deptno

bulk collect into V1;

DBMS_OUTPUT.PUT_LINE('The row count is '||sql%rowcount);

for i in v1.first..v1.last

loop

DBMS_OUTPUT.PUT_LINE(v1(i).empno||','||v1(i).ename||','||v1(i).deptno);

end loop;

end;

8.W.A.P W.A.P in PL/SQL stored procedure to modify salary of clerk from emp table and this
modified value should be stored into index_by_table and display data using bulk bind process

(HINT: Use index_by and then use bulk bind)

A. create or replace procedure BULK_BIND is

declare
type BULK_BIND is table of emp%rowtype

GE Internal
index by binary_integer;
v1 BULK_BIND;
begin
select empno bulk collect into v1 from emp where job='CLERK';
forall i in v1.first..v1.last
update emp set sal=sal+500 where empno=v1(i);
end;

GE Internal

You might also like