很多ERP中需要一个RECORD技术,如下是一个应用比较完整的例子,可以找到对应的RECORD属性:my_dept(i),my_dept.count,my_dept.exists(i),my_dept.first,my_dept.last,my_dept(i).deptno
set serveroutput on
set echo off
select * from dept
/
declare
type dept_table_type is table of dept%rowtype
index by binary_integer;
my_dept dept_table_type;
v_count number(2);
v_rows number(2);
begin
select count(*) into v_count
from dept;
for i in 1..v_count loop
select *
into my_dept(i)
from dept
where deptno = i*10;
end loop;
v_rows:=my_dept.count;
dbms_output.put_line('Contains..... '||to_char(v_rows));
for i in 1..v_rows loop
if my_dept.exists(i) then
dbms_output.put_line('DEPT Name : '||
to_char(i)||' - '||my_dept(i).dname);
end if;
end loop;
dbms_output.put_line('prior(2) : '||to_char(my_dept.prior(2)));
dbms_output.put_line('delete(2)........');
my_dept.delete(2);
for i in 1..v_rows loop
if my_dept.exists(i) then
dbms_output.put_line('LOC : '||
to_char(i)||' - '||my_dept(i).loc);
end if;
end loop;
dbms_output.put_line('delete(4)........');
my_dept.delete(4);
for i in 1..v_rows loop
if my_dept.exists(i) then
dbms_output.put_line('DEPT No : '||
to_char(i)||' - '||my_dept(i).deptno);
end if;
end loop;
v_rows:=my_dept.count;
dbms_output.put_line('Contains '||to_char(v_rows));
dbms_output.put_line('First : '||to_char(my_dept.first));
dbms_output.put_line('Last : '||to_char(my_dept.last));
end;
/
set echo on
set serveroutput off
set echo off
select * from dept
/
declare
type dept_table_type is table of dept%rowtype
index by binary_integer;
my_dept dept_table_type;
v_count number(2);
v_rows number(2);
begin
select count(*) into v_count
from dept;
for i in 1..v_count loop
select *
into my_dept(i)
from dept
where deptno = i*10;
end loop;
v_rows:=my_dept.count;
dbms_output.put_line('Contains..... '||to_char(v_rows));
for i in 1..v_rows loop
if my_dept.exists(i) then
dbms_output.put_line('DEPT Name : '||
to_char(i)||' - '||my_dept(i).dname);
end if;
end loop;
dbms_output.put_line('prior(2) : '||to_char(my_dept.prior(2)));
dbms_output.put_line('delete(2)........');
my_dept.delete(2);
for i in 1..v_rows loop
if my_dept.exists(i) then
dbms_output.put_line('LOC : '||
to_char(i)||' - '||my_dept(i).loc);
end if;
end loop;
dbms_output.put_line('delete(4)........');
my_dept.delete(4);
for i in 1..v_rows loop
if my_dept.exists(i) then
dbms_output.put_line('DEPT No : '||
to_char(i)||' - '||my_dept(i).deptno);
end if;
end loop;
v_rows:=my_dept.count;
dbms_output.put_line('Contains '||to_char(v_rows));
dbms_output.put_line('First : '||to_char(my_dept.first));
dbms_output.put_line('Last : '||to_char(my_dept.last));
end;
/
set echo on
set serveroutput off
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/13941341/viewspace-624017/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/13941341/viewspace-624017/