我试图在while循环中使用select作为条件。 我想使用while循环来比较随机数和table09中的数字,而数字不在table09中。但我的脚本以错误结束。如何在while循环中使用select作为条件? 我有这段代码:
declare
my_idadh varchar(14);
n number;
begin
n:=round(dbms_random.value(10000000000000,99999999999999));
my_idadh:=to_char(n);
while exists(select idadh from table09 where idadh=my_idadh)
loop
n:=round(dbms_random.value(10000000000000,99999999999999));
idadh:=to_char(n);
end loop;
end;
谢谢,彼得
答案 0 :(得分:1)
you can put your query inside the loop and check the condition with a variable like this:
V_dummy :=1;
While (v_dummy = 1) loop
Begin
select 1
Into v_dummy
from table09
where idadh=my_idadh
Exception when no_data_found then
Exit;
End;
-- you loop code here...
End loop;