1. 程式人生 > >mysql查詢欄位為null時,返回空字串

mysql查詢欄位為null時,返回空字串

原始資料:


第一種:使用case  when判斷

SELECT
	username AS virtualCardNum,
	realname AS realName,
	authenticated AS SMZ,
	(
		CASE
		WHEN idnumber IS NULL THEN
			''
		WHEN idnumber = "1" THEN
			"0"
		ELSE
			idnumber
		END
	) AS encIdNumber
FROM
	appuser
WHERE
	realname = "測試王寧"

第二種:

使用IFNULL函式