我有一個表格,每次進入回圈時我都會減少一行。如何在回圈之前檢查表長度是否為零并洗掉我得到的行?
declare
l_temp number;
begin
insert into l_tem(select toy_id from toys);
if l_temp > 0 then
for rw in (select toy_id from( select toy_id
from toys
order by dbms_random.value)
where rownum =1 )
loop
dbms_output.put_line(toy_id);
delete from toys where toy_id(rw);
end loop;
else
dbms_output.put_line('no more toys');
end if;
end;
uj5u.com熱心網友回復:
我不太明白你為什么要那樣做,而不是簡單地
delete from toys;
但別介意我。
你不必檢查任何東西。如果表為空,FOR回圈將不會運行任何回圈并簡單地跳出回圈。
如果你必須檢查它,那么它是
select count(*) into l_temp from toys;
此外,您應該使用游標變數和列名來參考值,例如
delete from toys where toy_id = rw.toy_id;
---------
this
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/367877.html
