如何检查 table 的长度并用它做一个 if 条件并在之后删除一行?

How to check the length of a table and the make an if condition with it and delete a row after?

我有一个 table,每次进入循环我都会减少一行。如果 tables 长度为零并删除我之后得到的行,如何在循环之前检查?

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;

我不太明白为什么你会那样做,而不是简单地

delete from toys;

但别管我。

您无需检查任何内容。如果 table 为空,FOR 循环将不会 运行 任何 循环 并且只是跳出循环。

如果你一定要勾选,那就是

select count(*) into l_temp from toys;

此外,您应该使用游标变量和列名来引用值,例如

delete from toys where toy_id = rw.toy_id;
                                ---------
                                this