output with single quote in sql

2019-10-10 07:07发布

问题:

Table Values

CNAME

Firstname
Amount
Postalcode
Lastname
Accountnumber

REQUIRED O/P

CNAME

'Firstname'
'Amount'
'Postalcode'
'Lastname'
'Accountnumber'

回答1:

In mysql you can use the function concat():

SELECT CONCAT("'", CNAME, "'") FROM yourTable

In oracle you can use the same function as above concat() or the concatenation operator:

SELECT '''' || CNAME || '''' FROM yourTable;
SELECT CONCAT('''', CNAME, '''') FROM yourTable;