Я создаю процедуру, которая принимает JSON CLOB в качестве аргумента IN OUT.Мой вопрос, хотя, как привести JSON_OBJECT_T к CLOB?Я хочу сохранить структуру JSON в CLOB, а не только хранить значение json (см. JSON_OBJECT_T.GET_CLOB ('firstname') ниже).
Мой тестовый код:
CREATE TABLE employees
( employee_id NUMBER(6)
, first_name VARCHAR2(20)
, last_name VARCHAR2(25)
CONSTRAINT emp_last_name_nn NOT NULL
, email VARCHAR2(25)
CONSTRAINT emp_email_nn NOT NULL
, phone_number VARCHAR2(20)
, hire_date DATE
CONSTRAINT emp_hire_date_nn NOT NULL
, job_id VARCHAR2(10)
CONSTRAINT emp_job_nn NOT NULL
, salary NUMBER(8,2)
, commission_pct NUMBER(2,2)
, manager_id NUMBER(6)
, department_id NUMBER(4)
, CONSTRAINT emp_salary_min
CHECK (salary > 0)
, CONSTRAINT emp_email_uk
UNIQUE (email)
) ;
INSERT INTO EMPLOYEES VALUES (123,'John','Doe','John.Doe@Test.Com',99999999,TRUNC(SYSDATE),234,60000,null,null,null)
--CREATE OR REPLACE PROCEDURE GETEMPLOYEE (P_CLOB IN OUT CLOB)
--AS
DECLARE
P_CLOB CLOB :=
'{
"employee_id":123
}';
V_JSON_IN JSON_OBJECT_T := JSON_OBJECT_T.PARSE(P_CLOB);
V_EMP_ID NUMBER := V_JSON_IN.GET_NUMBER('employee_id');
V_EMP_REC EMPLOYEES%ROWTYPE;
V_JSON_OUT JSON_OBJECT_T := NEW JSON_OBJECT_T;
BEGIN
P_CLOB := EMPTY_CLOB();
SELECT * INTO V_EMP_REC FROM EMPLOYEES WHERE EMPLOYEE_ID = V_EMP_ID;
V_JSON_OUT.PUT('firstname',V_EMP_REC.First_Name);
V_JSON_OUT.PUT('lastname',V_EMP_REC.Last_Name);
V_JSON_OUT.PUT('salary',V_EMP_REC.Salary);
P_CLOB := V_JSON_OUT.GET_CLOB('firstname');
DBMS_OUTPUT.put_line(TO_CHAR(P_CLOB)); -- JOHN
---How to cast V_JSON_OUT to Clob and store in P_CLOB?
END;