sql - Oracle sql中的if语句

标签 sql oracle select syntax-error

我想要一个仅根据条件显示好或坏的列:

select (if (salary>10000) then 'good' else 'bad')as "Grade" from employees;

它给了我

ORA-00907: missing right parenthesis
00907. 00000 -  "missing right parenthesis"
*Cause:    
*Action:
Error at Line: 14 Column: 19

错误出现在“>”处。我该怎么写呢?

最佳答案

您可以(应该?)使用 ANSI-SQL case 表达式:

SELECT CASE WHEN salary > 10000 THEN 'good' ELSE 'bad' END AS "Grade"
FROM   employees;

关于sql - Oracle sql中的if语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47821623/

相关文章:

php - 如何为 php mysql 驱动的数据库生成下一个 ID 号

sql - SELECT * FROM t WHERE t.x OR t.y IN (SELECT id FROM z)

sql - 获取任何给定日期的库存产品列表

javax.net.ssl.SSLHandshakeException : Received fatal alert: handshake_failure only in server

.net - 从 Dapper ORM 调用 Oracle 存储过程时,无法将类型 'System.Int32[]' 的对象转换为类型“System.IConvertible”

带有 xmlagg 函数的 SQL 多 SELECT 查询 - 未以所需方式提取数据

mysql - 创建 ID 介于 1-999999 之间的数据库

sql - 盘点记录问题

MySQL - 选择 N 个不同记录所在的所有行

javascript - 有标签时最大化表格中的选择宽度