如何选择所有列,以及oracle 11g中CASE语句的结果? [英] How do you select all columns, plus the result of a CASE statement in oracle 11g?
本文介绍了如何选择所有列,以及oracle 11g中CASE语句的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想选择*,而不必键入所有单独的列,但我也想在case语句中包括一个自定义列.我尝试了以下方法:
I want to select *, and not have to type out all individual columns, but I also want to include a custom column with a case statement. I tried the following:
select *, (case when PRI_VAL = 1 then 'High'
when PRI_VAL = 2 then 'Med'
when PRI_VAL = 3 then 'Low'
end) as PRIORITY
from MYTABLE;
但是它在抱怨
ORA-00923: FROM keyword not found where expected
推荐答案
为mytable添加别名,如下所示:
Add an alias for mytable like this:
select t.*, (case when PRI_VAL = 1 then 'High'
when PRI_VAL = 2 then 'Med'
when PRI_VAL = 3 then 'Low'
end) as PRIORITY
from MYTABLE t;
这不依赖于任何特定的Oracle版本,不确定其他数据库.
This is not dependent on any specific Oracle version, not sure about other databases.
这篇关于如何选择所有列,以及oracle 11g中CASE语句的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文