检查oracle中的表是否为空

时间:2014-06-06 08:48:49

标签: sql oracle

IF((SELECT COUNT(*) FROM IPA_PRCADJ_HDR WHERE TRM_CODE = 41) = 0)
THEN
  select '111111' from dual;
ELSE
 SELECT '0000000' FROM DUAL;
END IF;

显示错误..

从命令行第73行开始出错:

END IF
ERROR REPORT:
Unknown Command

3 个答案:

答案 0 :(得分:4)

你无法建立这样的条件。尝试在select语句中构建它们,如下所示:

select case
       when exists
            ( select 1
              from   IPA_PRCADJ_HDR
              where  TRM_CODE = 41
            )
       then '111111'
       else '0000000'
       end
from   dual

答案 1 :(得分:-1)

你可以试试这个:

IF NOT EXISTS (SELECT 1 FROM IPA_PRCADJ_HDR)
 SELECT '111111' FROM DUAL;
ELSE
 SELECT '0000000' FROM DUAL;

答案 2 :(得分:-2)

试试这个

IF((SELECT COUNT(*) FROM IPA_PRCADJ_HDR WHERE TRM_CODE = 41) == 0)
THEN
  select '111111' from dual;
ELSE
 SELECT '0000000' FROM DUAL;
END IF;

如果你必须使用条件" ==" INSTEAD OF" ="。