Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Building JSON object from PL/SQL select statement

Guil Sa-OracleFeb 16 2017 — edited Feb 23 2017

On APEX 5 RESTful services [1] I need to dynamically build a JSON object inside PL/SQL. Not sure if using htp.p is the best solution. In the first example below line 7 returns a proper JSON. All good. Now the second example does not. It seems htp.p only takes a string as input. Is there another way of doing this?

A static JSON:

returns {"status":"success"}

DECLARE

rvalue varchar2(200);

BEGIN

rvalue := adduser(:email, :password);

IF rvalue = 1 THEN

htp.p('{"status":"success"}');

END IF;

END;

A dynamic JSON:

returns {"status": l.employee.first_name} when {"status": "Bella"} is expected [2]

DECLARE

l_employee pdb3_participants%ROWTYPE;

BEGIN

SELECT *

 INTO l\_employee

 FROM pdb3\_participants

WHERE id = 17;

htp.print('{"status": l.employee.first_name}');

END;

[1]

pastedImage_46.png

[2]

pastedImage_43.png

This post has been answered by Aldo Escamilla-Oracle on Feb 23 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 23 2017
Added on Feb 16 2017
10 comments
1,790 views