四时宝库

程序员的知识宝库

数据库中的字符串拼接(数据库中的字符串拼接是什么)

日常工作中,时常需要将两个或多个字符串拼接在一起,组合成一个新的字符串。而字符串拼接地实现在各个关系型数据库中略有差异。

1.Oracle中,使用 “||”拼接符或concat函数实现字符串拼接:

 select concat('hello','oracle') from dual;

输出结果为:hellooracle

在Oracle中concat函数只能拼接两个字符串,如果想拼接两个以上的字符串可以使用 “||”拼接符:

 select 'hello'||'sql'||'oracle' from dual;

输出结果为:hellosqloracle

2. SQL Server中,使用“+”或concat 函数(SQLServer 2012 新增) 实现字符串拼接:

 select concat('hello','sql','SQLSERVER');

 select 'hello'+'sql'+'SQLSERVER';

输出结果均为:hellosqlSQLSERVER

3.MySQL中,使用concat函数拼接字符串:

 select concat('hello','sql','Mysql');

输出结果为:hellosqlMysql

4.PostGreSQL中,使用 “||” 或concat函数实现字符串拼接:

 select concat('hello','sql','PostgreSQL');

 select 'hello'||'sql'||'PostgreSQL';

输出结果为: hellosqlPostgreSQL。

发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言
    友情链接