*使用解码..
SELECT ENAME, SAL,
DECODE
(
COMM,
COMM >=0, (SELECT COMM FROM EMP WHERE COMM>=0),--I KNOW THIS IS A MISTAKE
'NO COMM'
) COMMISSION
FROM EMP
ORDER BY COMISSION
DECODE
这是我的错误
COMM >=0, (SELECT COMM FROM EMP WHERE COMM>=0),
*
ERROR at line 5:
ORA-00907: missing right parenthesis
感谢提前
答案 0 :(得分:2)
试试这样..
SELECT ENAME, SAL,
(Case when COMMISSION>0 then Cast(COMMISSION as Varchar2(20)) Else 'Sorry' End) as Comments
FROM EMP
ORDER BY COMISSION
答案 1 :(得分:0)
以下是使用DECODE的示例,但 AmitSingh 的CASE示例更清晰
SELECT ename,
sal,
DECODE(SIGN(comm), 1, TO_CHAR(comm), 'No Comm') commission
FROM emp
如果comm是<>则SIGN函数将返回-1。如果comm为0,则为0;如果为comm,则为1; 0,所以如果SIGN(comm)返回1,则表示comm大于0.否则没有佣金。