Parse JSON into Oracle table using PL/SQL

后端 未结 4 1898
误落风尘
误落风尘 2020-12-09 11:06

I have created the following script in order to read data from Mobile App DB (which is based on MongoDB) from Oracle SQL Developer:

DECLARE
  l_param_list     VAR         


        
4条回答
  •  时光说笑
    2020-12-09 11:28

    Since this question scores high in results, I want to post this preferred alternative:

    Oracle has released APEX 5.0 (April 15. 2015). With it you get access to a great API to work with JSON

    I'm using it on 11.2 and have been able to crunch every single json, from simple to very complex objects with multiple arrays and 4/5 levels. APEX_JSON

    If you do not want to use APEX. Simply install the runtime environment to get access to the API.

    Sample usage, data from json.org's example :

    declare
        sample_json   varchar2 (32767)
            := '{
        "glossary": {
            "title": "example glossary",
            "GlossDiv": {
                "title": "S",
                "GlossList": {
                    "GlossEntry": {
                        "ID": "SGML",
                        "SortAs": "SGML",
                        "GlossTerm": "Standard Generalized Markup Language",
                        "Acronym": "SGML",
                        "Abbrev": "ISO 8879:1986",
                        "GlossDef": {
                            "para": "A meta-markup language, used to create markup languages such as DocBook.",
                            "GlossSeeAlso": ["GML", "XML"]
                        },
                        "GlossSee": "markup"
                    }
                }
            }
        }
    }';
    begin
        apex_json.parse (sample_json);
        dbms_output.put_line (apex_json.get_varchar2 ('glossary.GlossDiv.title'));
        dbms_output.put_line (apex_json.get_varchar2 ('glossary.GlossDiv.GlossList.GlossEntry.GlossTerm'));
        dbms_output.put_line (apex_json.get_varchar2 ('glossary.GlossDiv.GlossList.GlossEntry.GlossDef.GlossSeeAlso[%d]', 2));
    end;
    

    Result: PL/SQL block executed

    S
    Standard Generalized Markup Language
    XML
    

提交回复
热议问题