如果只有一行受到影响,返回值存放在PL/SQL变量中,如果有多行受到影响,则返回值放在数组中。
declare
SQLstring varchar2(1000);
v_phone_name varchar2(20);
v_producer varchar2(20);
v_price number:=0;
begin
SQLstring:='update phone_infor set price=1200 where price=:a returning phone_name,producer,price into :b,:c,:d';
execute immediate SQLstring using v_price returning into v_phone_name,v_producer,v_price;
commit;
dbms_output.put_line(v_phone_name||' '||v_producer||' '||v_price);
end;
输入绑定变量放在using之后,输出绑定变量放在returning into之后。
另外一种方法,使用静态SQL
begin
update phone_infor set price=1200 where price=0;
commit;
select phone_name,producer,price into v_phone_name,v_producer,v_price from phone_infor where price=1200;
dbms_output.put_line(v_phone_name||' '||v_producer||' '||v_price);
end;
此篇博客主要为了记录有returning into的语法,方便以后查看。
在动态SQL中调用函数
注意点:函数有返回值。
create or replace function f_call(p1 in varchar2)
return varchar2 as
begin
return p1||'is from function f_call';
end;
declare
v_return varchar2(50);--用于存放函数的返回值
begin
execute immediate 'call f_call(''huangbaokang'') into :hbk' using out v_return;
dbms_output.put_line(v_return);
end;
必须带带上out关键字,表示输出参数。
博客介绍了Oracle存储过程中有返回值的DML操作。若一行受影响,返回值存于PL/SQL变量;多行受影响,存于数组。输入绑定变量在using后,输出在returning into后,还提及静态SQL及动态SQL调用函数的注意点,记录相关语法方便查看。
&spm=1001.2101.3001.5002&articleId=95176258&d=1&t=3&u=fc8784911fe74a61929737bec758f643)
382

被折叠的 条评论
为什么被折叠?



