oracle我以前的资料2.1
程序员文章站
2022-03-29 12:12:19
...
/********************1用循环计算工资总和******************************/
declare
type emp_cur is ref cursor;
v_cur emp_cur;
v_type naemp%rowtype;
v_sum naemp.EMPSAL%type;
begin
open v_cur for select * from naemp where empdeptno=30;
fetch v_cur into v_type;
while v_cur%found
loop
v_sum:=v_sum+v_type.empsal;
end loop;
close v_cur;
end;
/***************************2用游标列出所有信息******************************/
declare
type emp_cur is ref cursor;
v_cur emp_cur;
v_type naemp%rowtype;
begin
open v_cur for select * from naemp;
fetch v_cur into v_type;
while v_cur%found
loop
dbms_output.PUT_LINE(v_type.empdeptno||' '||v_type.empno);
end loop;
end;
/**********************************3用联合数组打出所有信息**********************/
declare
type t1 is table of naemp%rowtype index by binary_integer;
tt t1;
begin
select empno,empname,empdeptno,empsal,empmanager bulk collect into tt from naemp;
for i in 1..tt.count
loop
dbms_output.PUT_LINE(tt(i).empno||' '||tt(i).empname||' '||tt(i).empdeptno||' '||tt(i).empsal||' '||tt(i).empmanager);
end loop;
end;
declare
type emp_cur is ref cursor;
v_cur emp_cur;
v_type naemp%rowtype;
v_sum naemp.EMPSAL%type;
begin
open v_cur for select * from naemp where empdeptno=30;
fetch v_cur into v_type;
while v_cur%found
loop
v_sum:=v_sum+v_type.empsal;
end loop;
close v_cur;
end;
/***************************2用游标列出所有信息******************************/
declare
type emp_cur is ref cursor;
v_cur emp_cur;
v_type naemp%rowtype;
begin
open v_cur for select * from naemp;
fetch v_cur into v_type;
while v_cur%found
loop
dbms_output.PUT_LINE(v_type.empdeptno||' '||v_type.empno);
end loop;
end;
/**********************************3用联合数组打出所有信息**********************/
declare
type t1 is table of naemp%rowtype index by binary_integer;
tt t1;
begin
select empno,empname,empdeptno,empsal,empmanager bulk collect into tt from naemp;
for i in 1..tt.count
loop
dbms_output.PUT_LINE(tt(i).empno||' '||tt(i).empname||' '||tt(i).empdeptno||' '||tt(i).empsal||' '||tt(i).empmanager);
end loop;
end;