views:

39

answers:

1

Hi,

Is there a way i can output in SQL Oracle as follow with a single quote at the beginning and end, plus a comma (,). Many thanks in advance!

original output:

Number
0910000001
0910000002
0910000003
0910000004
0910000018
0910000019
0910000020

Desired output:

Number
'0910000001',
'0910000002',
'0910000003',
'0910000004',
'0910000018',
'0910000019',
'0910000020',
+3  A: 

You have to just add it you your query...

select ''' + number + ''' , ' ' as trailing_comma from table..

the second ' ' is so your output will insert a comma after your 'Number'

Nix
+1 More-or-less correct for SQLServer, as originally requested. Oracle uses `||` for string concatenation instead of `+`, so the equivalent query should be `select '''' || number || ''', ' as trailing_comma from table`.
Mark Bannister