Lightdb 23.3 plorasql函数支持DML

开篇立意

oracle在函数中使用dml语句时,有两者情况。即:(1)直接使用select调用该函数;(2)在匿名块中调用该函数。
针对第一种情况我们测试一下
简单的函数:

create table nested_tab(id int, name varchar2(100), job varchar2(100), age int);
insert into nested_tab values (1, 'asda', 'gfdgd', 12);
insert into nested_tab values (2, 'sdfsd', 'cvxvx', 14);
insert into nested_tab values (3, 'uyiy', 'mmbv', 16);

create or replace function support_dml return int as
begin
	update nested_tab set id = 4 where name = 'uyiy';
	return 12;
end;
/
报错如下
SQL> select support_dml() from dual;
select support_dml() from dual
       *
ERROR at line 1:
ORA-14551: cannot perform a DML operation inside a query
ORA-06512: at "SYS.SUPPORT_DML", line 3

针对第二种情况我们测试一下

declare
	retcode int := 1;
begin
    retcode := support_dml();
	dbms_output.put_line(retcode);
end;
/
12

PL/SQL procedure successfully completed.

由此可以知道定义在函数中的dml,只能在plsql中使用。

plorasql实现

lightdb 在兼容的过程中,上面描述的oracle的两种情况都支持。

plorasql测试

create table nested_tab(id int, name varchar2(100), job varchar2(100), age int);
insert into nested_tab values (1, 'asda', 'gfdgd', 12);
insert into nested_tab values (2, 'sdfsd', 'cvxvx', 14);
insert into nested_tab values (3, 'uyiy', 'mmbv', 16);

create or replace function support_dml return int as
begin
	update nested_tab set id = 4 where name = 'uyiy';
	return 12;
end;
/

lightdb@test_hs_oracle=# select support_dml() from dual;
 support_dml 
-------------
          12
(1 row)

lightdb@test_hs_oracle=# select dbms_output.serveroutput('t');
 serveroutput 
--------------
 
(1 row)

lightdb@test_hs_oracle=# declare
lightdb@test_hs_oracle$# retcode int := 1;
lightdb@test_hs_oracle$# begin
lightdb@test_hs_oracle$#     retcode := support_dml();
lightdb@test_hs_oracle$# dbms_output.put_line(retcode);
lightdb@test_hs_oracle$# end;
lightdb@test_hs_oracle$# /
12
DO
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值