案例剖析网站,wordpress 显示用户名,宁波网站建设优化,时尚类网站建设开篇立意
oracle在函数中使用dml语句时#xff0c;有两者情况。即#xff1a;#xff08;1#xff09;直接使用select调用该函数#xff1b;#xff08;2#xff09;在匿名块中调用该函数。 针对第一种情况我们测试一下 简单的函数#xff1a;
create table nested_t…开篇立意
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
beginupdate 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针对第二种情况我们测试一下
declareretcode int : 1;
beginretcode : support_dml();dbms_output.put_line(retcode);
end;
/
12PL/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
beginupdate nested_tab set id 4 where name uyiy;return 12;
end;
/lightdbtest_hs_oracle# select support_dml() from dual;support_dml
-------------12
(1 row)lightdbtest_hs_oracle# select dbms_output.serveroutput(t);serveroutput
--------------(1 row)lightdbtest_hs_oracle# declare
lightdbtest_hs_oracle$# retcode int : 1;
lightdbtest_hs_oracle$# begin
lightdbtest_hs_oracle$# retcode : support_dml();
lightdbtest_hs_oracle$# dbms_output.put_line(retcode);
lightdbtest_hs_oracle$# end;
lightdbtest_hs_oracle$# /
12
DO