oracle 存储过程循环执行update语句()
admin
2023-07-14 00:11:18
其实二楼写的最简单,但对于新手,最好别那么写,至于1楼,如果数据不是很多,没必要搞个游标。你也可以看看我写的
create or replace procedure P_Update(o_vc_message out varchar2)
is
type column1 is table of table1.column1%type index by binary_integer;
col1s column1;
type rid is table of rowid index by binary_integer;
rids rid;
temp table1.column1%type;
begin
select column1,rowid bulk collect into col1s,rids from table1;
if (column1.count != 0) then
for i in col1s.first..col1s.last loop
temp := col1s(i);--处理 col1s(i) 想干嘛干嘛
update table1 set column1 = temp where rowid = rids(i);
end loop;
end if;
o_vc_message := 'OK!';
exception
when others then
o_vc_message := 'exception happend.' || sqlcode || sqlerrm;
rollback;
return;
end P_Update;
如果仅仅是简单处理column1,比如加1什么的,就别搞那么复杂,一个sql就ok了。
后面是必须跟commit的,
看下是不是打开了自动提交
show autocommit;
如果是on的话,就能解释你这个是什么情况了。
还有就是你在执行之后是不是做了用户切换,切换用户,用的是connect命令,是会提交事务的。
1、不要用before试一试。
2、“ntwriter in varchar2,pkid in long”,这个数据类型 long 改成number试一下。
3、测试一下所有的同义词是否可以操作,执行更新操作,看是否可以进行。
你把你想要的东西写出来吧
现在看你的语句没明白你想要做什么。
ID 是否为 t_user 的主键?
id = 42 又 set id = 42 这就没懂
如果想把ID 为 42的 所有列都将名字改成 'bb'
可以直接这样写:
update t_user set name='bb' where id=42;
这个UPDATE语句肯定是没任务问题的,关键是你的表数据,还有其它逻辑,或操作造成
可能这个表被别的用户锁了;
select sess.sid,
sess.serial#,
lo.oracle_username,
lo.os_user_name,
ao.object_name,
lo.locked_mode
from v$locked_object lo, dba_objects ao, v$session sess
where ao.object_id = lo.object_id
and lo.session_id = sess.sid;
--杀掉会话
alter system kill session 'sid,serial#';
create or replace procedure TESTis
begin
--遍历记录 for table1model in (select column1 from table1) loop --更新列(当前值加1) update table1 set column1=table1model.column1+1 where column1=table1model.column1; end loop;
commit;exception when others then rollback; return;
end TEST;
相关内容