已有的嵌套表赋值方法
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