请教一个plsql语句的写法

taney 2009-11-28 04:52:38
数据库的表中有四列id、type、 status、time
查找100个type=“给定值“、status=“1“的记录,并修改它们的status=”2“
最后要返回status被修改了的记录的id号
...全文
161 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhangwonderful 2009-11-29
  • 打赏
  • 举报
回复
2楼、3楼的方案可行
maitianhust 2009-11-29
  • 打赏
  • 举报
回复
学习。
Blaider 2009-11-29
  • 打赏
  • 举报
回复
学习了
lovenl058 2009-11-28
  • 打赏
  • 举报
回复
我也来学习一下
crazylaa 2009-11-28
  • 打赏
  • 举报
回复
in_type i 表名.id%TYPE,
o_idlst o varchar2
改为
in_type in 表名.id%TYPE,
o_idlst out varchar2
crazylaa 2009-11-28
  • 打赏
  • 举报
回复
create or replace procedure test_upd(
in_type i 表名.id%TYPE,
o_idlst o varchar2
)as
cur sys_refcursor;
rec 表名%ROWTYPE;
begin
open cur for
select id,status
from 表名
where rownum<=100
and type= in_type
and status='1'
for update;
loop
fetch cur into rec;
exit when cur%NOTFOUND;
update 表名 set status='2' where id = rec.id;
o_idlst := o_idlst+",";
end loop;
close cur;
end;
/
BenChiM888 2009-11-28
  • 打赏
  • 举报
回复

set serveroutput on

declared
cursor cur is
select id,status
from 表名
where rownum<=100
and type='给定值'
and status='1'
for update;
begin
for rec in cur loop
update 表名 set status='2' where current of cur;
dbms_output.put_line('更新的id为:['id']');
end loop;
end;
/


3,496

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧