POST API Code:
----
declare
ret_msg varchar2(2000);
test_data CLOB;
v_samp varchar2(1) := 'N';
begin
select get_access_token(:ptoken) into v_samp from dual;
if v_samp = 'Y' then
ret_msg := GET_STD_FEE_SINGLE_VOUCHER(fee_voch_no => :fee_voch_no);
htp.print(ret_msg);
end if;
exception
when others then
if v_samp = 'N' then
htp.print('Access Denied');
else
htp.print(ret_msg);
end if;
end
--==========================================================================--
FUNCTION:
---
create or replace FUNCTION GET_STD_FEE_SINGLE_VOUCHER(
p_voch_no IN VARCHAR2
) RETURN CLOB
IS
v_master_json CLOB;
v_detail_json CLOB;
v_final_json CLOB;
v_voch_no VARCHAR2(12);
v_party_user_code VARCHAR2(20);
BEGIN
SELECT DISTINCT fee_voch_no, party_user_code
INTO v_voch_no, v_party_user_code
FROM trans@EDULINKS_253
WHERE fee_voch_no = p_voch_no;
/* master JSON as CLOB */
SELECT JSON_OBJECT(
'fee_voch_no' VALUE t.fee_voch_no,
'party_user_code' VALUE t.party_user_code,
'party_name' VALUE get_party_name@edulinks_253(t.party_user_code),
'father_name' VALUE p.father_name,
'branch_name' VALUE get_branch_name@edulinks_253(t.doc_source),
'class_section' VALUE get_class_name@edulinks_253(t.class_no)
|| ' ' || get_section_desc@edulinks_253(t.section_id),
'session_desc' VALUE get_session_desc@edulinks_253(t.session_id),
'fee_month' VALUE TO_CHAR(t.mon_date,'MON-YYYY'),
'due_date' VALUE TO_CHAR(i.due_date,'DD-MON-YYYY'),
'issue_date' VALUE TO_CHAR(i.iss_date,'DD-MON-YYYY'),
'valid_date' VALUE TO_CHAR(i.valid_till,'DD-MON-YYYY'),
'class_name' VALUE get_class_name@edulinks_253(t.class_no),
'section_desc' VALUE get_section_desc@edulinks_253(t.section_id)
RETURNING CLOB
)
INTO v_master_json
FROM trans@EDULINKS_253 t
JOIN parties@EDULINKS_253 p ON t.party_user_code = p.party_user_code
JOIN invoice_info@EDULINKS_253 i ON t.fee_voch_no = i.fee_voch_no
WHERE t.fee_voch_no = p_voch_no;
/* detail array as CLOB */
SELECT JSON_ARRAYAGG(
JSON_OBJECT(
'title' VALUE t.remarks,
'amount' VALUE t.item_cost
)
RETURNING CLOB
)
INTO v_detail_json
FROM trans@EDULINKS_253 t
WHERE t.fee_voch_no = v_voch_no;
/* final JSON: embed the already-constructed master/detail JSON using FORMAT JSON */
SELECT JSON_OBJECT(
'items' VALUE JSON_OBJECT(
'master' VALUE v_master_json FORMAT JSON,
'detail' VALUE v_detail_json FORMAT JSON
RETURNING CLOB
)
RETURNING CLOB
)
INTO v_final_json
FROM DUAL;
RETURN v_final_json;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN TO_CLOB('{"items":{"master":null,"detail":[]}}');
WHEN OTHERS THEN
RAISE;
END GET_STD_FEE_SINGLE_VOUCHER;
--==========================================================================--
when test it using Postman it is showing error

please help, what is the problem and how t can be resolved? how I can RETURN error a meaningful error because it returns RETURN TO_CLOB('{"items":{"master":null,"detail":[]}}');
in case of NO DATA FOUND?
also please guide / ask if anything else require? and if there is better approach achieve this, please help to learn.
note: on compilation of FUNCTION there was no error shown
with best regards