我必须连接2列(例如FIRSTANME和LASTNAME).
我是这样做的:
FIRSTNAME || ' ' || LASTNAME`.
Run Code Online (Sandbox Code Playgroud)
如果其中一个为null,但另一个不为null,则作为连接结果得到null.
我想要遵循以下行为
FIRSTNAME = null and LASTNAME = "Smith" ==>
FIRSTANME || ' ' || LASTNAME == ' Smith'.
Run Code Online (Sandbox Code Playgroud)
如何在DB2中解决这个问题?
Joh*_*ica 15
使用 coalesce
...
CONCAT( COALESCE(firstname,'') , COALESCE(lastname,'') )
Run Code Online (Sandbox Code Playgroud)
或者使用||
concat运算符
...
COALESCE(firstname,'') || COALESCE(lastname,'')
Run Code Online (Sandbox Code Playgroud)
请注意,IBM建议使用关键字concat
而不是||
运营商.
CONCAT:http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=%2Fcom.ibm.db2.doc.sqlref%2Ffconc.htm
合并:HTTP://publib.boulder. ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=%2Fcom.ibm.db2.doc.sqlref%2Ffcoal.htm
归档时间: |
|
查看次数: |
24762 次 |
最近记录: |