0% found this document useful (0 votes)
41 views

To insert bulk records into an Oracle table using Oracle APEX REST API

Uploaded by

Hemant Homkar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

To insert bulk records into an Oracle table using Oracle APEX REST API

Uploaded by

Hemant Homkar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

To insert bulk records into an Oracle table using Oracle APEX REST API, you

can follow these steps:

1. Create a RESTful Web Service in Oracle APEX that accepts a list of


records to insert.
2. Use Python to send a POST request to the RESTful Web Service with
the list of records.
3. Process the request in the Oracle APEX Web Service to insert the
records into the Oracle table.

Here's an example of how you can achieve this:

1. Create a RESTful Web Service in Oracle APEX:

 Create a new RESTful Web Service module in your Oracle APEX


application.
 Add a POST handler that accepts a JSON payload containing the
list of records to insert.
 Write PL/SQL code in the handler to loop through the records and
insert them into the Oracle table.

2. Python code to send the POST request:

import requests

import json

# Sample data

records = [

{"id": 1, "name": "John Doe"},

{"id": 2, "name": "Jane Smith"}

# Convert the list of records to JSON

payload = json.dumps({"records": records})

# Send POST request to the RESTful Web Service


url = 'https://your-apex-url.com/rest/service-name/insert-records'

headers = {'Content-Type': 'application/json'}

response = requests.post(url, headers=headers, data=payload)

print(response.text)

1. Process the request in Oracle APEX:

 Parse the JSON payload in the POST handler to extract the list of records.
 Loop through the records and insert them into the Oracle table using SQL
or PL/SQL.

Please note that you'll need to replace


'https://your-apex-url.com/rest/service-name/insert-records' with the actual URL of
your Oracle APEX RESTful Web Service endpoint. Additionally, ensure that your RESTful
Web Service module is configured correctly to accept and process POST requests.

You
write oracle apex code with reference to above code to insert record in oracle table
ChatGPT
ChatGPT
To insert records into an Oracle table using an Oracle APEX RESTful Web Service, you
can follow these steps:

1. Create a RESTful Web Service in Oracle APEX:

 Create a new RESTful Web Service module in your Oracle APEX


application.
 Add a POST handler that accepts a JSON payload containing the list of
records to insert.
 Write PL/SQL code in the handler to loop through the records and insert
them into the Oracle table.

Here's an example of how you can achieve this:

1. Create a RESTful Web Service module:

 Go to the Shared Components section of your Oracle APEX application.


 Click on "Web Services" and then "RESTful Services."
 Click on "Create" and follow the wizard to create a new RESTful Web
Service module.
 Define a URI Template for your POST handler (e.g., /insert-records).
2. Add a POST handler:

 In the RESTful Web Service module, click on "Resource Templates."


 Click on "Create" and select "POST" as the Method Type.
 Define the URI Template for the POST handler (e.g., /insert-records).

3. Write PL/SQL code to insert records:

 Edit the POST handler and write PL/SQL code to handle the POST request.
Here's an example:

DECLARE

l_data CLOB := :body;

l_records APEX_JSON.t_values;

l_record APEX_JSON.t_value;

BEGIN

APEX_JSON.parse(l_records, l_data);

FOR i IN 1..APEX_JSON.get_count(p_path => 'records') LOOP

l_record := APEX_JSON.get_values(p_values => l_records,

p_path => 'records[%d]',

p0 => i);

INSERT INTO your_table_name (id, name)

VALUES (l_record.get('id').get_number,

l_record.get('name').get_vc2);

END LOOP;

COMMIT;

HTP_RESPONSE_STATUS(200);

EXCEPTION

WHEN OTHERS THEN

HTP_RESPONSE_STATUS(500);

END;

1. Test the RESTful Web Service:


 Use a tool like Postman or curl to send a POST request to your RESTful
Web Service endpoint with a JSON payload containing the list of records to
insert.

Note: Ensure that you replace your_table_name with the actual name of your Oracle
table.

You might also like