如何获取格式化的SQL查询结果

时间:2016-11-08 13:08:42

标签: sql oracle

考虑这个表

Code Name   City    Salary
---------------------------
1   Mark    LA      12000
2   Selena  NY       6000
3   Justin  USA     50000
4   John    CN       3000

我想要这样的结果

John lives in `CN` and his salary is 3000.
Justin lives in `USA` and his salary is 50000.

我怎样才能在Oracle中这样做?

如果有不同的方法,那么也要解释它们。

2 个答案:

答案 0 :(得分:0)

最好能够创建并调用过程。

在程序中,您可以根据您的要求制作if else条件并添加以下查询:

select (Name || ' lives in '|| City || 'and his/her salary is' || Salary || '.') from tablename;

答案 1 :(得分:0)

要在SQL中连接值,请使用||。字符值使用单引号提供:'

将它们放在一起你需要使用:

select name ||' lives in "'||city||'" and his/her salary is '||salary
from the_table;