LightDB新增使用赋值符号直接为嵌套表元素赋值

已有的嵌套表赋值方法

LightDB 24.1之前的版本中,支持使用bulk collect into语法对嵌套表批量加载数据,也支持select  into对单个嵌套表元素赋值。例如:

drop table t;
create table t(a int,b int);
insert into t values(1,11);
insert into t values(2,22);
select dbms_output.serveroutput('t');

create or replace procedure p1 is 
  TYPE array_table IS TABLE OF t%rowtype;
  a_table array_table := array_table();
BEGIN

  SELECT t.* BULK COLLECT INTO a_table FROM t;
  FOR i IN a_table.first..a_table.last LOOP
    dbms_output.put_line('a_table(i).a = '||a_table(i).a||', a_table(i).b = '||a_table(i).b);
  END LOOP;

EXCEPTION
   WHEN OTHERS THEN
      ROLLBACK;
END;
/

call p1();
a_table(i).a = 1, a_table(i).b = 11
a_table(i).a = 2, a_table(i).b = 22
CALL

drop table t;
create table t(a int,b int);
insert into t values(1,11);
insert into t values(2,22);
select dbms_output.serveroutput('t');

create or replace procedure p1 is 
  TYPE array_table IS TABLE OF t%rowtype;
  a_table array_table := array_table();
BEGIN

  SELECT t.* BULK COLLECT INTO a_table FROM t;
  select 100,200 into a_table(2).a, a_table(2).b;
  FOR i IN a_table.first..a_table.last LOOP
    dbms_output.put_line('a_table(i).a = '||a_table(i).a||', a_table(i).b = '||a_table(i).b);
  END LOOP;

EXCEPTION
   WHEN OTHERS THEN
      ROLLBACK;
END;
/

call p1();
a_table(i).a = 1, a_table(i).b = 11
a_table(i).a = 100, a_table(i).b = 200
CALL

本期新增的嵌套表赋值方法

从24.1版本开始,LightDB还支持使用赋值符号(:=)直接对嵌套表元素赋值:

drop table t;
create table t(a int,b int);
insert into t values(1,11);
insert into t values(2,22);
select dbms_output.serveroutput('t');

create or replace procedure p1 is 
  TYPE array_table IS TABLE OF t%rowtype;
  a_table array_table := array_table();
BEGIN

  a_table.extend();
  a_table(1).a := 11;
  a_table(1).b := 22;
  a_table.extend();
  a_table(2).a := 111;
  a_table(2).b := 222;
  FOR i IN a_table.first..a_table.last LOOP
    dbms_output.put_line('a_table(i).a = '||a_table(i).a||', a_table(i).b = '||a_table(i).b);
  END LOOP;

EXCEPTION
   WHEN OTHERS THEN
      ROLLBACK;
END;
/

call p1();
a_table(i).a = 11, a_table(i).b = 22
a_table(i).a = 111, a_table(i).b = 222
CALL

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值