我有一组数字需要在2个查询中使用。这些是11g服务器的同一个oracle SQL脚本的一部分:
更新table1设置some_column = 1其中user_id为(1,2,3,4,5,6,7,8,9,10);
更新table2设置some_other_column = 17其中user_id为(1,2,3,4,5,6,7,8,9,10);
如何将数字列表分解为变量并在两个更新语句中使用它?
答案 0 :(得分:1)
您可以使用collections:
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;