Return results of a sql query as JSON in oracle 12c

后端 未结 9 1631
误落风尘
误落风尘 2020-11-29 05:42

Background

I need to fetch a few thousands rows from Oracle and convert them to JSON for use in SlickGrid. Currently I am fetching the rows in PHP,

9条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 06:35

    Just try this:

    :) life is happy

    with data as
      ( select 
        xmlelement(e,regexp_replace('{"name":"'||colname||'"}', '[[:cntrl:]]', ''),',') col1
        from tblname
      )
      select
            rtrim(replace(replace(replace(xmlagg(col1).getclobval(),'&'||'quot;','"'),'',''),'',''),',')
            as very_long_json
      from data;
    

提交回复
热议问题