一、使用“||”連接
SELECT user_name,'中文名:'|| china_name as "name" FROM "SYS_USER" where id=2089
結果
二、使用CONCAT()函數連接
SELECT user_name,concat('中文名:', china_name) as "name" FROM "SYS_USER" where id=2078
結果
在使用這個函數時,當拼接的值不是字符串時,oracle會自動轉換成字符串。
需要注意的時,此函數里面只支持兩個參數,不支持超過兩個的參數,否則會報:參數個數無效。當需要多個參數進行拼接時,可以使用多個concat()函數進行嵌套
SELECT user_name,concat(concat(concat('中文名:', china_name),ENTERPRISE_ID),email) as "介紹" FROM "SYS_USER" where id=2027
結果
注意:mysql中不能使用||來連接字符串,只能用concat來連接
<if test="channelType!=null and channelType!=''"> AND t1.channel_type LIKE concat('%',#{channelType},'%') </if>
oracle中concat只支持連接兩個參數的項目案例:
select
concat((select d1.CHI_SHORT_NAME from t_area_code d1 where a.province_code=d1.id and d1.ISVALID='1'), concat(concat((select d2.CHI_SHORT_NAME from t_area_code d2 where a.city_code=d2.id and d2.ISVALID='1'), (select d3.CHI_SHORT_NAME from t_area_code d3 where a.area_code=d3.id and d3.ISVALID='1')), a.detailed_address)) as localAddress from t_agent a
......
注意:mysql中使用concat進行字符串拼接時,參數個數沒有限制。