[英]Show special characters in concat with db2 sql
I am running query like this for db2 sql 我正在为db2 sql运行这样的查询
SELECT CONCAT(CONCAT('Order_no is =', Order_no), ' for line') FROM orders;
And result is coming like this: 结果是这样的:
Order_no is =123456 for line
But I want to fetch result as 但我想获取结果为
Order_no is ='6640354' for line
I need to apply special characters to output, so can you please help me in this. 我需要将特殊字符应用于输出,因此您能在这方面帮助我吗。
Use two single quotes together to escape a single quote: 一起使用两个单引号可以转义一个单引号:
SELECT CONCAT(CONCAT('Order_no is =''', Order_no), ''' for line')
FROM orders;
您也可以使用它;
select 'Order_no is=''' || trim(Order_no) || ''' for line' from orders;
Not sure why the use of nested CONCAT scalar is shown so pervasively in db2-tagged discussions, to concatenate more than one value.? 不知道为什么在db2标签的讨论中如此普遍地显示了使用嵌套CONCAT标量来连接多个值。 Perhaps caused by how sometimes the documentation separates expressions and scalar functions , and in the latter docs might only offer a tiny Note: 'The CONCAT function is identical to the CONCAT operator.
可能是由于文档有时将表达式和标量函数分开的原因所致,而在后一文档中,文档可能仅提供了一个很小的注释: 'CONCAT函数与CONCAT运算符相同。 For more information, see "Expressions".'
有关更多信息,请参见“表达式”。
I personally find the following use of the CONCAT operator, to be a much more readable way to compose the same character-string expression: 我个人发现CONCAT运算符的以下用法,是组成相同字符串表达式的更易读的方式:
'Order_no is =''' CONCAT Order_no CONCAT ''' for line'
You can escape special character using \\
or using another single quote like 您可以使用
\\
或其他单引号将特殊字符转义
select CONCAT( CONCAT('Order_no is =\'', Order_no), '\' for line') from orders;
Check DB2 documentation on Escaping special characters 查看有关转义特殊字符的 DB2文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.