检查oracle中的表是否为空

li9yvcax  于 2023-06-05  发布在  Oracle
关注(0)|答案(3)|浏览(157)
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
h7appiyu

h7appiyu1#

你不能创造这样的条件。尝试在select语句中构建它们,如下所示:

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

vsdwdz232#

这考虑了表为空时的情况。

SELECT CASE WHEN MAX(TRM_CODE) IS NULL THEN 'FALSE' ELSE 'TRUE' END FROM (SELECT * FROM IPA_PRCADJ_HDR WHERE TRM_CODE = 41)
vngu2lb8

vngu2lb83#

你可以试试这个:

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

相关问题