我在以下声明中遇到了一些问题:
SELECT 1
FROM dual
WHERE DECODE(1,
0,
(SELECT COUNT(*) from tbl),
1) > 0
如果'tbl'为空,则执行此查询会以某种方式返回任何内容。
另一方面,执行查询:
SELECT 1
FROM dual
WHERE DECODE(1,
0,
(SELECT COUNT(*) from tbl),
1) = 1
返回1.
此外,这:
SELECT 1
FROM dual
WHERE DECODE(1,
0,
(SELECT COUNT(*) from tbl),
1) = 0
也会返回1.我缺少什么?
编辑1 sqlplus列表
SQL> select count(*) from ids;
COUNT(*)
----------
0
SQL> SELECT 1
2 FROM dual
3 WHERE DECODE(1,
4 0,
5 (SELECT COUNT(*) from ids),
6 1) > 0;
no rows selected
SQL> SELECT 1
2 FROM dual
3 WHERE DECODE(1,
4 0,
5 (SELECT COUNT(*) from ids),
6 1) =1;
1
----------
1
SQL> SELECT 1
2 FROM dual
3 WHERE DECODE(1,
4 0,
5 (SELECT COUNT(*) from ids),
6 1) =0;
1
----------
1
答案 0 :(得分:0)
通过将其嵌套在选择中来解决原因。它不会有效率,但应该有效。你真的想在这做什么?你能举个例子来说明数字:)。
SELECT 1 来自双重 WHERE(选择DECODE(1, 0, (从ids中选择COUNT(*)), 1) 来自dual)= 0;