Oracle SQL,连接多列+添加文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1619259/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Oracle SQL, concatenate multiple columns + add text
提问by Thundordan
So I basically wanna display this (whole row in ONE column):
所以我基本上想显示这个(一列中的整行):
I like [type column] cake with [icing column] and a [fruit column].
我喜欢 [类型栏] 蛋糕与 [糖霜栏] 和 [水果栏]。
The result should be:
结果应该是:
Cake_Column
----------------
I like chocolate cake with whipped_cream and a cherry.
I like strawberry cake with vanilla_cream and a lemon_slice.
etc.
etc.
I need some sort of TO_CHAR statement that does ([column] "some text" [column]) "new_column_name";
我需要某种 TO_CHAR 语句来执行 ([column] "some text" [column]) "new_column_name";
What am I supposed to know?
我应该知道什么?
回答by OMG Ponies
You have two options for concatenating strings in Oracle:
在 Oracle 中连接字符串有两个选项:
CONCAT example:
CONCAT 示例:
CONCAT(
CONCAT(
CONCAT(
CONCAT(
CONCAT('I like ', t.type_desc_column),
' cake with '),
t.icing_desc_column),
' and a '),
t.fruit_desc_column)
Using ||
example:
使用||
示例:
'I like ' || t.type_desc_column || ' cake with ' || t.icing_desc_column || ' and a ' || t.fruit_desc_column
回答by Shankar R10N
回答by Dani
select 'i like' || type_column || ' with' ect....
回答by Chaits
Below query works for me @Oracle 10G ----
以下查询适用于我@Oracle 10G ----
select PHONE, CONTACT, (ADDR1 || '-' || ADDR2 || '-' || ADDR3) as Address
from CUSTOMER_DETAILS
where Code='341';
O/P -
订单/订单 -
1111 [email protected] 4th street-capetown-sa
1111 [email protected] 第 4 街-开普敦-sa
回答by Dulith De Costa
The Oracle/PLSQL
CONCAT
function allows to concatenate two strings together.
该Oracle/PLSQL
CONCAT
函数允许将两个字符串连接在一起。
CONCAT( string1, string2 )
string1
The first string to concatenate.
string2
The second string to concatenate.
字符串 1
要连接的第一个字符串。
字符串2
要连接的第二个字符串。
E.g.
例如
SELECT 'I like ' || type_column_name || ' cake with ' ||
icing_column_name || ' and a ' fruit_column_name || '.'
AS Cake FROM table;
回答by SandPiper
Try this:
尝试这个:
SELECT 'I like ' || type_column_name || ' cake with ' ||
icing_column_name || ' and a ' fruit_column_name || '.'
AS Cake_Column FROM your_table_name;
It should concatenate all that data as a single column entry named "Cake_Column".
它应该将所有数据连接为一个名为“Cake_Column”的单列条目。