日常工作中,时常需要将两个或多个字符串拼接在一起,组合成一个新的字符串。而字符串拼接地实现在各个关系型数据库中略有差异。 1.Oracle中,使用 “||”拼接符或concat函数实现字符串拼接: select concat('hello','oracle') from dual; 输出结果为:hellooracle 在Oracle中concat函数只能拼接两个字符串,如果想拼接两个以上的字符串可以使用 “||”拼接符:
输出结果为:hellosqloracle 2. SQL Server中,使用“+”或concat 函数(SQLServer 2012 新增) 实现字符串拼接: select concat('hello','sql','SQLSERVER'); 或
输出结果均为:hellosqlSQLSERVER 3.MySQL中,使用concat函数拼接字符串: select concat('hello','sql','Mysql'); 输出结果为:hellosqlMysql 4.PostGreSQL中,使用 “||” 或concat函数实现字符串拼接:
或 select 'hello'||'sql'||'PostgreSQL'; 输出结果为: hellosqlPostgreSQL。 查询输出结果 |
|