集合赋值

本文介绍PL/SQL中嵌套表的操作方法,包括赋值、去除重复值、合并表、求交集及差集等实用技巧,并通过具体实例进行演示。

/集合赋值/

/:= 赋值/
declare
type v_varray_type is varray(100) of int;
v_t v_varray_type;
v_t2 v_varray_type;

begin
v_t := v_varray_type(1,2,3,4,3,2,1);
dbms_output.put_line(‘v_t的原数据’);
for i in 1..v_t.count loop
dbms_output.put_line(v_t(i));
end loop;
v_t := v_t2;–赋空值
if v_t is null then
dbms_output.put_line(‘是空的’);
end if;
end;

/————————————-嵌套表———————————————/
/set 去除嵌套表中的重复值/

declare
type v_varray_type is table of int;
v_t v_varray_type;
v_t2 v_varray_type;

begin
v_t := v_varray_type(1,2,3,4,3,2,1);
dbms_output.put_line(‘v_t的原数据’);
for i in 1..v_t.count loop
dbms_output.put_line(v_t(i));
end loop;
v_t := set(v_t);
dbms_output.put_line(‘v_t的新数据’);
for i in 1..v_t.count loop
dbms_output.put_line(v_t(i));
end loop;
end;

/multiset union 合并嵌套表, 包含重复值 /
declare
type v_varray_type is table of int;
v_t v_varray_type := v_varray_type(‘1’,’2’,’3’);
v_t2 v_varray_type := v_varray_type(‘2’,’3’,’4’);
v_result v_varray_type;
begin
v_result := v_t multiset union v_t2;
for i in 1 ..v_result.count loop
dbms_output.put_line(v_result (i));
end loop;
end;

/multiset union distinct 合并嵌套表,去除重复值 /
declare
type v_varray_type is table of int;
v_t v_varray_type := v_varray_type(‘1’,’2’,’3’);
v_t2 v_varray_type := v_varray_type(‘2’,’3’,’4’);
v_result v_varray_type;
begin
v_result :=set(v_t multiset union v_t2);
for i in 1 ..v_result.count loop
dbms_output.put_line(v_result (i));
end loop;
end;

declare
type v_varray_type is table of int;
v_t v_varray_type := v_varray_type(‘1’,’2’,’3’);
v_t2 v_varray_type := v_varray_type(‘2’,’3’,’4’);
v_result v_varray_type;
begin
v_result :=v_t multiset union distinct v_t2;
v_result := set (v_result);
for i in 1 ..v_result.count loop
dbms_output.put_line(v_result (i));
end loop;
end;

/multiset intercect 交集 /
declare
type v_varray_type is table of int;
v_t v_varray_type := v_varray_type(‘1’,’2’,’3’);
v_t2 v_varray_type := v_varray_type(‘2’,’3’,’4’);
v_result v_varray_type;
begin
v_result :=v_t multiset intersect v_t2;
v_result := set (v_result);
for i in 1 ..v_result.count loop
dbms_output.put_line(v_result (i));
end loop;
end;

/multiset except 差集 /
declare
type v_varray_type is table of int;
v_t v_varray_type := v_varray_type(‘1’,’2’,’3’);
v_t2 v_varray_type := v_varray_type(‘2’,’3’,’4’);
v_result v_varray_type;
begin
v_result :=v_t multiset except v_t2;
v_result := set (v_result);
for i in 1 ..v_result.count loop
dbms_output.put_line(v_result (i));
end loop;
end;
/————————————-嵌套表———————————————/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值