Oracle查询结果逗号拼接与单引号拼接

1.oracle查询数据结果用“,”拼接

select  listagg (y.id, ',')    WITHIN GROUP (ORDER BY y.id) 
as id from  tb_demo y where y.zjzt = '1' 

结果如下:

0903B16D3B3D53824C29F3BFA9F7FC59,095FB1823B3D53820E9EC7873B5DD5FF,185363E03B3D53826E9FD5F95219D0EB,46AA37053B3D538206160BAB5007B03B

2.在上面的基础上,加上单引号

select  listagg (to_char(y.id), ''',''')    WITHIN GROUP (ORDER BY y.id) 
as id from  tb_demo y where y.zjzt = '1' 

两个单引号就是转义,会将一个引号留下

结果如下:

0903B16D3B3D53824C29F3BFA9F7FC59’,‘095FB1823B3D53820E9EC7873B5DD5FF’,‘185363E03B3D53826E9FD5F95219D0EB’,'46AA37053B3D538206160BAB5007B03B

你可能感兴趣的:(数据库,oracle,数据库,database)