5

在大多数 SQL 产品中,我可以从无表或从虚拟表中进行选择,如下所示:

-- Oracle
SELECT 1 FROM DUAL

-- Many other SQL products (including Ingres)
SELECT 1

有时,我想在上面的语句中添加一个条件,以便检索 0 或 1 条记录,具体取决于条件

-- Oracle
SELECT 1 FROM DUAL WHERE 1 = 0

-- Many other SQL products (but not Ingres)
SELECT 1 WHERE 1 = 0

但以上不适用于 Ingres 10.0。我该怎么做?

4

2 回答 2

5

我没有使用过 Ingres,但我从你的问题中假设 aFROM是强制性的,如果有 a WHERE?这种情况下怎么办

SELECT 1 FROM (SELECT 1 AS C) AS T WHERE 1 = 0

或者

SELECT CASE WHEN 1 = 0 THEN 1 ELSE 0 END

(最后一个将始终返回一行,但允许您检查条件)

于 2011-10-15T11:28:36.880 回答
0

AFAIK 系统目录 iidbconstants 只有一行,所以你可以使用它。我想不出有多行的情况,但您可能想添加一个 DISTINCT 以防万一:

select distinct 1 from iidbconstants
Executing . . .


+------+
|col1  |
+------+
|     1|
+------+
(1 row)
continue
* select distinct 1 from iidbconstants where 1 = 0
Executing . . .


+------+
|col1  |
+------+
+------+
(0 rows)
于 2014-08-19T14:39:15.040 回答