支持游标作为插入值

功能描述

A模式的plsql中,游标可以作为插入值实现插入。

示例

set behavior_compat_options = 'allow_procedure_compile_check';
create table source(c1 int,c2 varchar2(100));
insert into source values(1,'aa');
insert into source values(2,'bb');
create table target(c1 int,c2 varchar2(100));
-- INSERT
declare
  cursor cur is
    select c1,c2 from source;
begin
  for data in cur loop
    INSERT INTO target values(data.c1,data.c2);
  end loop;
end;
/
select * from target order by c1;
 c1 | c2 
----+----
  1 | aa
  2 | bb
(2 rows)

-- UPDATE
declare
  cursor cur is
    select c1,c2 from source;
begin
  for data in cur loop
    UPDATE TARGET SET c1 = data.c1, c2 = data.c2;
  end loop;
end;
/
select * from target order by c1;
 c1 | c2
----+----
  2 | bb
  2 | bb
(2 rows)

-- DELETE
declare
  cursor cur is
    select c1,c2 from source;
begin
  for data in cur loop
    DELETE FROM TARGET WHERE c1 = data.c1 AND c2 = data.c2;
  end loop;
end;
/
select * from target order by c1;
 c1 | c2
----+----
(0 rows)

drop table source;
drop table target;
reset behavior_compat_options;
意见反馈
编组 3备份
    openGauss 2024-10-08 01:19:39
    取消