What is the string concatenation operator in Oracle?

限于喜欢 提交于 2019-11-26 01:15:42

问题


What is the string concatenation operator in 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).


回答1:


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.




回答2:


There's also concat, but it doesn't get used much

select concat('a','b') from dual;



回答3:


I would suggest concat when dealing with 2 strings, and || when those strings are more than 2:

select concat(a,b)
  from dual

or

  select 'a'||'b'||'c'||'d'
        from dual



回答4:


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



来源:https://stackoverflow.com/questions/278189/what-is-the-string-concatenation-operator-in-oracle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!