Select PL/SQL选择while循环中的条件
我试图在while循环中使用select作为条件。 我想使用while循环将随机数与表09中的数字进行比较,而数字不在表09中。但我的脚本以错误结束。如何在while循环中使用select作为条件? 我有以下代码:Select PL/SQL选择while循环中的条件,select,plsql,while-loop,conditional-statements,Select,Plsql,While Loop,Conditional Statements,我试图在while循环中使用select作为条件。 我想使用while循环将随机数与表09中的数字进行比较,而数字不在表09中。但我的脚本以错误结束。如何在while循环中使用select作为条件? 我有以下代码: declare my_idadh varchar(14); n number; begin n:=round(dbms_random.value(10000000000000,99999999999999)); my_idadh:=to_char(n); while e
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;
谢谢,Peter您可以将查询放入循环中,并使用如下变量检查条件:
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;
exists子句仅在sql语句中有效。select将需要INTO子句来获取值,然后在while中使用。