How do I output a CLOB from APEX rest services through an output parameter. which is of string type

I have an apex rest service, which produces a CLOB.

I wanted to output this CLOB through string parameter.

when I try to do this, I am getting "PLSQL value error"

Below is my code, how do I this..

DECLARE
  l_cursor SYS_REFCURSOR;
  v_stmt_str      VARCHAR2(1000);
      
begin

   if (:status is NULL) then 
      v_stmt_str := 'select FROM_USER_NAME as "from_user_name", to_user_name as "to_user_name",  id as "id", type as "type", subject as "subject", message as "message", thread_id as "thread_id", status as "status", to_char(alert_date, ''YYYY-MM-DD"T"HH24:MI:SS"Z"'') as "alert_date" from user_alert where to_user_name = :username';
      OPEN l_cursor FOR v_stmt_str using :username;
   else
      v_stmt_str := 'select FROM_USER_NAME as "from_user_name", to_user_name as "to_user_name",  id as "id", type as "type", subject as "subject", message as "message", thread_id as "thread_id", status as "status", to_char(alert_date, ''YYYY-MM-DD"T"HH24:MI:SS"Z"'') as "alert_date" from user_alert where to_user_name = :username and status = :status';
      OPEN l_cursor FOR v_stmt_str using :username, :status;
   end if;
   

 APEX_JSON.initialize_clob_output;

  APEX_JSON.open_object;
  APEX_JSON.write('user_alert', l_cursor);
  APEX_JSON.close_object;


 
 
-- :output_val :=APEX_JSON.get_clob_output;;
  APEX_JSON.free_output;
  
end;

Open in new window

output_val is an output parameter which is of string type.
sakthikumarAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

flow01Commented:
try
:output_val := dbms_lob.substring(APEX_JSON.get_clob_output,4000,1);
-- the 4000 is a guess for the max length of the bindvariable of type string
-- if  your clob extents  4000 bytes then data will be lost
-- in a pl/sql block you can define a v1 varchar2(32767)  and assign with v1 := dbms_lob.substring(APEX_JSON.get_clob_output,32767,1);
-- warning: there can be characterset  issues
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
REST

From novice to tech pro — start learning today.