I am running query like this for 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.? 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. 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:
'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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.