关闭

Oracle与Mysql的字符连接函数concat与||

969人阅读 评论(0) 收藏 举报
分类:

1Oracle版本:

1.1、执行语句:SELECT 'k' as a1,'a' as a2 ,'y' as a3 FROM sr_main

--------------------------------------------------------------------------------------------

1 k a y

2 k a y

3 k a y

--------------------------------------------------------------------------------------------

1.2执行语句:SELECT concat( 'k','a') as pj FROM sr_main

--------------------------------------------------------------------------------------------

1 ka

2 ka

3 ka

--------------------------------------------------------------------------------------------

1.3执行语句:SELECT concat( 'k','a','y') as pj FROM sr_main

--------------------------------------------------------------------------------------------

Errorinvalid number of arguments

--------------------------------------------------------------------------------------------

ReasonConcat只能连接两个字符串

1.4执行语句:SELECT  'k'||'a'||'y' as pj  FROM sr_main

--------------------------------------------------------------------------------------------

1 kay

2 kay

3 kay

--------------------------------------------------------------------------------------------

2Mysql版本:

2.1执行语句:SELECT concat( 'k','a') as pj FROM sr_main

--------------------------------------------------------------------------------------------

ka

ka

Ka

--------------------------------------------------------------------------------------------

2.2执行语句:SELECT concat( 'k','a','y') as pj FROM sr_main

--------------------------------------------------------------------------------------------

kay

kay

Kay

--------------------------------------------------------------------------------------------

2.3执行语句:SELECT  'k'||'a'||'y' as pj  FROM sr_main

--------------------------------------------------------------------------------------------

0

0

0

--------------------------------------------------------------------------------------------

分析两者差异:

Oracle中可以用||拼接多个字符串,但用concat只能拼两个,否则报错

Mysql中可以用concat拼接多个,但用||无法拼接字符串,会显示零

综合两者:SELECT concat(concat( 'k','a'),'y') as pj FROM sr_main

--------------------------------------------------------------------------------------------

kay

kay

Kay

--------------------------------------------------------------------------------------------

此方法可以实现两者通用

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1715次
    • 积分:73
    • 等级:
    • 排名:千里之外
    • 原创:5篇
    • 转载:0篇
    • 译文:1篇
    • 评论:0条
    文章分类
    文章存档