declare
TYPE emp_table_type is table of tbl_emp.n_emp_id%type INDEX BY BINARY_INTEGER;
    emptable  emp_table_type;
    begin
select n_emp_id bulk collect into emptable from tbl_emp where n_emp_id=999;
--如果emptable为空
end;
如何判断表变量emptable为空,也就是没有数据?

解决方案 »

  1.   

    DECLARE
      vCount NUMBER;
    BEGIN
      SELECT COUNT(*) INTO vCount FROM DUAL;
      IF vCount = 0 THEN
        DBMS_OUTPUT.PUT_LINE('TABLE IS EMPTY');
      END IF;
    END;
      

  2.   


    有两个变量emptable.COUNT 和SQL%ROWCOUNT 可以判断:dbms_output.put_line(emptable.COUNT );
    dbms_output.put_line(SQL%ROWCOUNT );
      

  3.   


    declare
    TYPE emp_table_type is table of tbl_emp.n_emp_id%type INDEX BY BINARY_INTEGER;
      emptable emp_table_type;
      begin
    select n_emp_id bulk collect into emptable from tbl_emp where n_emp_id=999;
    --如果emptable为空,(你不就是想判断n_emp_id这个字段存储的变量值吗?)
    if (emptable is null)
    --或者 if (emptable = null)
    end;
      

  4.   

    cowboyhn的方法有效,谢谢。楼上那位简直在瞎扯,你那是C#的写法吧……