我有一组需要在2个查询中使用的数字。这些是11g服务器的相同oracle SQL脚本的一部分:
更新表1设置some_column = 1,其中user_id在(1,2,3,4,5,6,7,8,9,10)中;
更新表2设置some_other_column = 17其中user_id在(1、2、3、4、5、6、7、8、9、10)中;
您如何将数字列表排除到变量中,并在两个更新语句中使用它?
您可以使用集合:
declare
type t_num is table of number;
num t_num;
begin
-- fill collection from query
select rownum
bulk collect into num
from dual connect by level < 10;
-- add one value to collection
num.extend;
num(num.last) := 345;
-- using in an UPDATE statement (the same you can use in INSERT and DELETE)
forall i in num.first..num.last
update table1 set some_column = 1 where user_id = num(i);
end;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句