SQL Oracle 中的字符串连接运算符是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/278189/
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
What is the string concatenation operator in Oracle?
提问by AJ.
What is the string concatenation operator in Oracle SQL?
Oracle SQL 中的字符串连接运算符是什么?
Are there any "interesting" features I should be careful of?
有什么我应该注意的“有趣”功能吗?
(This seems obvious, but I couldn't find a previous question asking it).
(这似乎很明显,但我找不到之前提出的问题)。
回答by Tony Andrews
It is ||
, for example:
这是||
,例如:
select 'Mr ' || ename from emp;
The only "interesting" feature I can think of is that 'x' || null
returns 'x'
, not null
as you might perhaps expect.
我能想到的唯一“有趣”功能是'x' || null
返回'x'
,而不是null
您可能期望的那样。
回答by Gary Myers
There's also concat, but it doesn't get used much
还有 concat,不过用的不多
select concat('a','b') from dual;
回答by Fabio Fantoni
I would suggest concat when dealing with 2 strings, and || when those strings are more than 2:
在处理 2 个字符串时,我建议使用 concat,而 || 当这些字符串大于 2 时:
select concat(a,b)
from dual
or
或者
select 'a'||'b'||'c'||'d'
from dual
回答by Ankur
DECLARE
a VARCHAR2(30);
b VARCHAR2(30);
c VARCHAR2(30);
BEGIN
a := ' Abc ';
b := ' def ';
c := a || b;
DBMS_OUTPUT.PUT_LINE(c);
END;
output:: Abc def
输出:: Abc def
回答by Grant Shannon
Using CONCAT(CONCAT(,),)
worked for me when concatenating more than two strings.
CONCAT(CONCAT(,),)
连接两个以上的字符串时,使用对我有用。
My problem required working with date strings (only) and creating YYYYMMDD
from YYYY-MM-DD
as follows (i.e. without converting to date format):
我的问题需要使用日期字符串(仅)并YYYYMMDD
从YYYY-MM-DD
以下创建(即不转换为日期格式):
CONCAT(CONCAT(SUBSTR(DATECOL,1,4),SUBSTR(DATECOL,6,2)),SUBSTR(DATECOL,9,2)) AS YYYYMMDD