Oracle encapsulates the restful interface into the view

In the oracle environment, sometimes it is necessary to access the third-party webservice interface. Sometimes we have a whim, if accessing these interfaces is like accessing a local table, it will be fine. The following is the implementation method

data example

The following is a simple example of an interface return

{
    
    
    "code": 200,
    "data": [
        {
    
    
            "parent": "B01",
            "name": "xxxxx",
            "code": "B0101",
            "enable_flag": "Y",
            "los_date": ""
        },
        {
    
    
            "parent": "B0101",
            "name": "gggggggggg",
            "code": "B010105",
            "enable_flag": "Y",
            "los_date": ""
        }
    ]
}

Implementation

Two tools are used here: oracle apex and the three-party open source library pljson, easy to implement

CREATE OR REPLACE VIEW XXXXX_V AS
SELECT json.status_code,
         budget_dept_code,
         budget_dept_name,
         parent_code,
         enable_flag,
         end_active_date
    FROM TABLE(pljson_table.json_table(apex_web_service.make_rest_request(p_url         => 'https://blog.csdn.net/x6_9x',
                                                                          p_http_method => 'GET',
                                                                          p_wallet_path => xxx_ysx_yyds.get_wallet_path,
                                                                          p_wallet_pwd  => xxx_ysx_yyds.get_wallet_pwd),
                                       pljson_varray('code',
                                                     'data[*].code',
                                                     'data[*].name',
                                                     'data[*].parent',
                                                     'data[*].enable_flag',
                                                     'data[*].los_date'),
                                       pljson_varray('status_code',
                                                     'budget_dept_code',
                                                     'budget_dept_name',
                                                     'parent_code',
                                                     'enable_flag',
                                                     'end_active_date'),
                                       table_mode => 'nested')) json

   ORDER BY 2;

If you want to consume the https interface, you need to configure the oracle wallet to import the certificate. Here, the interface with parameters is also supported. You can put the parameters in the where condition. For details, you can refer to the usage of apex_web_service.make_rest_request, which realizes the same as writing
sql To access webservice data

Guess you like

Origin blog.csdn.net/x6_9x/article/details/126161074