ORACL存储过程

--创建一个存储过程
create or replace procedure j_pro(xhs number,names out varchar2)
--注意这里没有return返回值
is
--多条数据可以用游标来处理
cursor yb is select xh,t_names from test2021_0606 where xh=xhs;
--声明一个变量去记录
x varchar2(400);
begin
--if完后记得加';'号
for c in yb loop
if (c.xh = 5) then x:='5new.name';
elsif (c.xh = 4) then x:='4new.name';
else x:='x.name';
end if;
--执行更新语句
update test2021_0606 set t_names=x where test2021_0606.xh=c.xh;
--存储此时x的值
names:=x;
end loop;
end;

定义一个存储过程,存储过程和函数的不同在于,存储过程不需要有return返回值。
调用存储过程并完成更新操作,并给予参数值,并使out类型的值也返还到调用的变量中。
declare
names varchar2(400);
begin
j_pro(4,names);
dbms_output.put_line(names);
end;
调用函数,并输出给定参数后的值names
此时输出的值为:4new.name
更新操作也已经生效。

文章转载自超人网页作坊,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。