首页 > 数据库 > 数据库开发技术 > PLSQL学习-【4复合数据类型】
记录record:(变量存放一行值)
declare type tp_emp is record(ename emp.ename%type ,empno emp.empno%type,sal emp.sal%type); v_tp tp_emp; begin select ename,empno,sal into v_tp from emp where empno = 7788; dbms_output.put_line(v_tp.ename ||' '|| v_tp.empno ||' ' || v_tp.sal); end;
rowtype:(select后必须全部列出来
)
declare v_tp emp%rowtype; begin select empno,ename,job,mgr,hiredate,sal,comm,deptno into v_tp from emp where empno = 7788; dbms_output.put_line(v_tp.ename); end;
table:
索引表:
declare 14:31:07 2 type tp_emp is table of emp.ename%type index by binary_integer; 14:39:28 3 v_tp tp_emp; 14:39:36 4 begin 14:39:38 5 select ename into v_tp(1) from emp where empno = 7788; 14:40:01 6 dbms_output.put_line(v_tp(1)); 14:40:18 7 end; 14:40:21 8 /
嵌套表:(得初始化)
declare type tp_emp is table of emp.ename%type; v_tp tp_emp:=tp_emp(); begin v_tp.extend; select ename into v_tp(1) from emp where empno = 7788; dbms_output.put_line(v_tp(1)); end;
declare
type tp_emp is table of emp.ename%type index by binary_integer;
v_tp tp_emp;
begin
select ename into v_tp(1) from emp where empno = 7788;
select ename into v_tp(2) from emp where empno = 7900;
select ename into v_tp(3) from emp where empno = 7369;
dbms_output.put_line(v_tp(1)||' '||v_tp(2)||' '||v_tp(3));
dbms_output.put_line('count'|| v_tp.count); --总计多少个角标。
dbms_output.put_line('first'|| v_tp.first);
dbms_output.put_line('last'|| v_tp.last);
dbms_output.put_line('prior(3)'|| v_tp.prior(3));
dbms_output.put_line('next(2)'|| v_tp.next(2));
if v_tp.exists(3) then
dbms_output.put_line('exists(3)'||1);
else
dbms_output.put_line('exists(3)'||);
end if;
v_tp.delete(1);
dbms_output.put_line(v_tp.count);
dbms_output.put_line(v_tp(2)||' '||v_tp(3));
--v_tp.trim(1);
dbms_output.put_line(v_tp.count);
end;
table叫table的原因,其实是存储一列值的,但是当以一行值为元素即rowtype,就会构成table;
打印dept表:
点击( 此处)折叠或打开
declare
type
tp_dept
is
table
of
dept
%rowtype
index
by
binary_integer
;
v_tp tp_dept
;
cursor cu_dept
is
select
*
from
dept
;
v_num
number
;
begin
v_num
:
=1
;
for
i
in
cu_dept loop
select
*
into
v_tp
(v_num
)
from
dept
where
deptno
=
i
.deptno
;
v_num
:
=v_num
+1
;
end
loop
;
for
j
in
1
.
.v_tp
.
count
loop
dbms_output
.put_line
(v_tp
(j
)
.deptno
|
|
\
' \'
|
|
v_tp
(j
)
.dname
|
|
\
' \'
|
|v_tp
(j
)
.loc
)
;
end
loop
;
end ;
可变数组:略
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29990276/viewspace-1341745/ ,如需转载,请注明出处,否则将追究法律责任。