但是有返回值啊。。SQL> SQL> declare 2 rtnvalue number; 3 begin 4 update temp set id = 23344 return id into rtnvalue; 5 dbms_output.put_line(rtnvalue); 6 end; 7 /23344PL/SQL procedure successfully completedSQL>
update 有返回选项的,该选项的返回值代表此次影响的行数!
Mergo Into table a1 using(resultSet) a2 on(条件) when matched then--数据存在 .... when not matched then --数据不存在 insert into table2 ...
使用sql%rowCount 可以知道更新的记录数 0 就是没有,然后把这条记录记录下来不就的了.update table set a = b where id = 'xxxx'; if sql%rowCount = 0 then insert log (a) values ('xxx'); --其他处理. end if;
只能用游标,在循环里面更新,再判断SQL%ROWCOUNT是否为零
如果是根据某一个字段来确定是否要更新 你可以先查看两个结果集里面有哪些数据是不会更新的, 所谓不会更新的就是这个表的数据在另一个表中不存在的数据. 如: select * from table_a a where not exists (select 1 from table_b where a.id = b.id ); 这样不就找出不会更新的记录了嘛?
SQL> declare
2 rtnvalue number;
3 begin
4 update temp set id = 23344 return id into rtnvalue;
5 dbms_output.put_line(rtnvalue);
6 end;
7 /23344PL/SQL procedure successfully completedSQL>
using(resultSet) a2
on(条件)
when matched then--数据存在
....
when not matched then --数据不存在
insert into table2 ...
if sql%rowCount = 0 then
insert log (a) values ('xxx');
--其他处理.
end if;
你可以先查看两个结果集里面有哪些数据是不会更新的,
所谓不会更新的就是这个表的数据在另一个表中不存在的数据.
如:
select * from table_a a where not exists (select 1 from table_b where a.id = b.id );
这样不就找出不会更新的记录了嘛?