Hartstein's salary is:13000 这样的出巡结果,我们往往在拼接
“'”的时候遇到一些麻烦,以下就讲述三种字符转义方法解决这个问题。
我们就拿实例用户hr的employees表作为查询对象。
1、使用转义字符 ':
hr@PROD>select last_name ||'''s salary is:' || salary as income
2 from employees
3 where salary >10000;
INCOME
------------------------------------------------------------------------------
Hartstein's salary is:13000
Higgins's salary is:12008
King's salary is:24000
Kochhar's salary is:17000
De Haan's salary is:17000
Greenberg's salary is:12008
Raphaely's salary is:11000
Russell's salary is:14000
Partners's salary is:13500
Errazuriz's salary is:12000
Cambrault's salary is:11000
INCOME
------------------------------------------------------------------------------
Zlotkey's salary is:10500
Vishney's salary is:10500
Ozer's salary is:11500
Abel's salary is:11000
15 rows selected.
2、使用q'/ /',或者q'[]',或者q'()'等转义:
hr@PROD>select last_name ||q'/'s salary is:/' || salary as income
2 from employees
3 where salary >10000;
INCOME
------------------------------------------------------------------------------
Hartstein's salary is:13000
Higgins's salary is:12008
King's salary is:24000
Kochhar's salary is:17000
De Haan's salary is:17000
Greenberg's salary is:12008
Raphaely's salary is:11000
Russell's salary is:14000
Partners's salary is:13500
Errazuriz's salary is:12000
Cambrault's salary is:11000
INCOME
------------------------------------------------------------------------------
Zlotkey's salary is:10500
Vishney's salary is:10500
Ozer's salary is:11500
Abel's salary is:11000
15 rows selected.
3、使用“'” 对应的ASCII数字代替:
--在上述的转义方法的基础上查看“'” 对应的ASCII数字:
hr@PROD>select ascii('''') from dual;
ASCII('''')
-----------
39
hr@PROD>select last_name || chr(39) ||'s salary is:' || salary as income
2 from employees
3 where salary >10000;
INCOME
------------------------------------------------------------------------------
Hartstein's salary is:13000
Higgins's salary is:12008
King's salary is:24000
Kochhar's salary is:17000
De Haan's salary is:17000
Greenberg's salary is:12008
Raphaely's salary is:11000
Russell's salary is:14000
Partners's salary is:13500
Errazuriz's salary is:12000
Cambrault's salary is:11000
INCOME
------------------------------------------------------------------------------
Zlotkey's salary is:10500
Vishney's salary is:10500
Ozer's salary is:11500
Abel's salary is:11000
15 rows selected.
解决了转义问题之后,高可读性的查询结果就不难创建。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31392094/viewspace-2128318/ ,如需转载,请注明出处,否则将追究法律责任。