Discussions
Categories
- 197.1K All Categories
- 2.5K Data
- 546 Big Data Appliance
- 1.9K Data Science
- 450.7K Databases
- 221.9K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 552 MySQL Community Space
- 479 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.1K ORDS, SODA & JSON in the Database
- 555 SQLcl
- 4K SQL Developer Data Modeler
- 187.2K SQL & PL/SQL
- 21.3K SQL Developer
- 296.3K Development
- 17 Developer Projects
- 139 Programming Languages
- 293K Development Tools
- 110 DevOps
- 3.1K QA/Testing
- 646.1K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 158 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.2K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 19 Java Essentials
- 162 Java 8 Questions
- 86K Java Programming
- 81 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 204 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 466 LiveLabs
- 39 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 175 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 233 Portuguese
Returning table rows as JSON

Hi,
I'm trying to select rows from the job_history table and returning them as a JSON array. I thought the following should have worked but it's giving me a ORA-01422 () error. What am I doing wrong?
declare
v_response json_object_t;
v_dataclob clob;
begin
SELECT json_object('empid' VALUE employee_id,
'startdate' VALUE start_date,
'enddate' VALUE end_date,
'job_id' VALUE job_id,
'dept' VALUE department_id )
into v_dataclob
FROM job_history;
owa_util.mime_header ('application/json', true);
v_response := json_object_t(v_dataclob);
htp.p(v_response.stringify);
END;
Best Answer
-
My blog has a search feature and a resource page for REST APIs, but here you go
https://www.thatjeffsmith.com/archive/2021/03/four-options-for-working-with-ords-plsql-refcursors/
Answers
-
why would you need to do this?
Just create a SQL handler that runs select * From job_history, ords builds the json array for you.
-
I created the handler using SQL Developer so I thought I had to fill something in the worksheet tab:
-
Also - I wanted to just understand the basics. In my 'real' procedure I'll be processing the incoming JSON payload and performing varying selects/joins based on what's received.
-
if your procedure returns a refcursor, ORDS will auto turn that into a JSON doc as well...
-
are there any examples of a handler doing this?
-
On my blog, yes (https://www.thatjeffsmith.com)
-
can you point me to a specific one please.
-
My blog has a search feature and a resource page for REST APIs, but here you go
https://www.thatjeffsmith.com/archive/2021/03/four-options-for-working-with-ords-plsql-refcursors/
-