SELECT CASE WHEN inputNumber != 0 THEN inputNumber
ELSE 111
END as Column_Name
FROM dual
大家好,inputNumber
是输入,基于此我必须创建输出,如果输出为0,则我的结果应包含三行,分别为111、222、333
以上查询有效,但我想在其他部分添加222、333,请提出建议,以便结果将是总共3行,其中输入等于0
现在,如果输入为0,则输出为
Column_Name
111
我想设为
Column_Name
111
222
333
答案 0 :(得分:1)
这是一种方法:
SELECT CASE WHEN :inputnumber = 0 THEN 111 * LEVEL ELSE :inputnumber END column_name
FROM dual
CONNECT BY LEVEL <= CASE WHEN :inputnumber = 0 THEN 3 ELSE 1 END;
With:inputnumber = 0:
COLUMN_NAME
-----------
111
222
333
With:inputnumber = 1:
COLUMN_NAME
-----------
1
答案 1 :(得分:0)
丑陋,但应该可以工作:
SELECT CASE WHEN inputNumber != 0 THEN inputNumber
ELSE 111
END as Column_Name
FROM dual
UNION ALL
SELECT 222
FROM dual
WHERE inputNumber = 0
UNION ALL
SELECT 333
FROM dual
WHERE inputNumber = 0
更新:
也许更具可读性:
SELECT inputNumber as Column_Name
FROM dual
WHERE inputNumber != 0
UNION ALL
SELECT 111
FROM dual
WHERE inputNumber = 0
UNION ALL
SELECT 222
FROM dual
WHERE inputNumber = 0
UNION ALL
SELECT 333
FROM dual
WHERE inputNumber = 0
PS:对不起,我没有对此进行测试...