oracle 集合 nested_table

1、--创建嵌套表类型
      Create Or Replace Type nested_table_type_name Is Table Of element_type;
      --创建嵌套表对象
      nested_table_variabe_name nested_table_type_name;

 注:使用嵌套表对象元素之前必须先初始化。下标从1开始,元素个数没限制

实例:

Create Or Replace Type test_type Is Table Of Varchar2(100)
 
Create Table tmp
(
  Id Number,
  phone  test_type,
  email  test_type
 )
  Nested Table phone Store As phone_table,
  Nested Table email Store As email_table


Insert Into tmp Values(1,test_type('13400000001','13400000002','13400000003'),test_type('a@126.com','b@126.com'));
Insert Into tmp Values(2,test_type('13500000001','13500000002','13500000003'),test_type('a@163.com','b@163.com'));
Insert Into tmp(Id) Values(3);
Update tmp Set phone=test_type('13600000001','13600000002') Where Id=3;
 
Declare
  test_rd test_type;
  i Number;
Begin
  Select phone Into test_rd From tmp Where Id=1;
  For i In 1 .. test_rd.count 
    Loop
      dbms_output.put_line(test_rd(i));
    End Loop;
End;  
输出:
13400000001
13400000002

13400000003


Declare
  test_rd test_type;
Begin 
  test_rd:=test_type('','','');
  test_rd(1):='1';
  test_rd(3):='2';
  dbms_output.put_line('元素个数:'||test_rd.count);
  dbms_output.put_line('元素1:'||test_rd(1));
  dbms_output.put_line('元素2:'||test_rd(2));
  dbms_output.put_line('元素3:'||test_rd(3));
End;
输出:
元素个数:3
元素1:1
元素2:
元素3:2







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值