用于检查 table 中数据可用性的 PLSQL 循环

PLSQL loop for checking data availability in table

应该有脚本检查一个table中的count(),如果count()为NULL则退出,否则休眠一段时间然后再次进行在 count(*) 为 NULL 时检查 table。我的努力白费了:

declare

    v_cnt pls_integer;

begin

    while v_cnt >0 
    loop

        select count(*) into v_cnt from TestTable;

        if v_cnt is Null
        then
            exit;
        else 
            dbms_lock.sleep(6);
            dbms_output.put_line('Count is greater then Null. Current values: ' || v_cnt);

    end loop;

    dbms_output.put_line('TestTable does not have any data');

end;

总是 returns 计算一个数字,不为空。将 if 更改为零而不是 null,它应该可以工作。我改变了你的逻辑,所以如果记录为零,它就不会启动。除非您要从 table 中删除记录,否则我假设没有任何记录只会发生一次。如果您正在删除记录并且 table 可能有多次零记录,那么通过一个您喜欢运行的作业开始这个过程并删除 while 循环。

declare
v_cnt pls_integer;
begin
select count(*) into v_cnt from TestTable;
if v_cnt > 0 then
   while v_cnt > 0 
   loop
      select count(*) into v_cnt from TestTable;
      dbms_lock.sleep(6);
      dbms_output.put_line('Count is greater than zero . Current values: ' || v_cnt);
   end loop;

else
   dbms_output.put_line('TestTable does not have any data');

 end if;
end;