当前位置:网站首页>Oracle EBS interface development - quick generation of JSON format data
Oracle EBS interface development - quick generation of JSON format data
2022-07-02 07:05:00 【Virtuous time】
When it comes to interface development , If many fields or complex nested structures are involved , In order to avoid artificial patchwork json data , Here are some common json How data is generated .
plug-in unit pljson The way
Avoid Chinese Unicode transformation
modify :pljson_printer.escapeChar as follows :
function escapeChar(ch char) return varchar2 deterministic is
result varchar2(20);
begin
--backspace b = U+0008
--formfeed f = U+000C
--newline n = U+000A
--carret r = U+000D
--tabulator t = U+0009
result := ch;
case ch
when chr( 8) then result := '\b';
when chr( 9) then result := '\t';
when chr(10) then result := '\n';
when chr(12) then result := '\f';
when chr(13) then result := '\r';
when chr(34) then result := '\"';
when chr(47) then if (escape_solidus) then result := '\/'; end if;
when chr(92) then result := '\\';
/* WARNING: ascii() returns PLS_INTEGER and large unicode code points can be negative */
else /*if (ascii(ch) >= 0 and ascii(ch) < 32) then result := '\u' || replace(substr(to_char(ascii(ch), 'XXXX'), 2, 4), ' ', '0'); elsif (ascii_output) then result := replace(asciistr(ch), '\', '\u'); end if;*/ [email protected] Avoid transcoding Chinese
null;
end case;
return result;
end;
Print directly
Although the table field type is varchar2 type , But if the stored values are all numbers , Will be automatically converted to number Format , That is, there are no double quotes , You can add single quotation marks , Then replace the single quotation marks to avoid this implicit conversion .
declare
ret pljson_list;
dyn_ref sys_refcursor;
begin
open dyn_ref for
select h.BATCH_NO,
h.INVOICE_TYPE,
h.SEQ,
h.DOC_SEQUENCE_NUM,
h.DOC_NUM,
h.DOC_TYPE,
h.APPROVE_EMPLOYEE_NO,
h.MAKER_EMPLOYEE_NO,
h.REQUESTOR_NO,
h.CURRENCY_CODE,
h.CURRENCY_CODE_BEG,
h.EXCHANGE_RATE,
h.VENDOR_NUM,
h.PAY_FLAG,
to_char(h.GL_DATE,'YYYY-MM-DD') GL_DATE,
to_char(h.BUSINESS_DATE,'YYYY-MM-DD') BUSINESS_DATE,
h.PREPAYMENT_FLAG,
h.INVOICE_AMOUNT,
h.INVOICE_AMOUNT_BEG,
h.SIG_FLAG,
TO_CHAR(h.FINISHED_DATE,'YYYY-MM-DD') FINISHED_DATE,
h.PAYMENT_CURRENCY_CODE,
/*h.ORGANIZATION_NAME,*/
''''||hou.short_code || '''' short_code,
h.SOURCE_LINE_ID,
h.CREATION_DATE,
h.ATTRIBUTE1,
h.ATTRIBUTE2,
h.ATTRIBUTE3,
h.ATTRIBUTE4,
h.ATTRIBUTE5,
h.ATTRIBUTE6,
cursor (select NVL(l.LINE_NUM,0) LINE_NUM,
l.IFACE_TYPE,
l.DR_CR_DIRECTOR,
l.AMOUNT,
l.AMOUNT_BEG,
l.INVOICE_COMMENTS,
'''' || l.COA_COMPANY || '''' COA_COMPANY,
'''' || l.COA_DEPT || '''' COA_DEPT,
'''' || l.COA_ACCOUNt || '''' COA_ACCOUNT,
l.COA_SUB_ACCOUNT,
'''' ||l.COA_PRODUCT || '''' COA_PRODUCT,
'''' ||l.COA_PROJECT || '''' COA_PROJECT,
'''' ||l.COA_INTERCOMPANY || '''' COA_INTERCOMPANY,
to_char(l.PAYMENT_DATE,'YYYY-MM-DD') PAYMENT_DATE,
l.PAYMENT_AMOUNT,
l.PAYMENT_BANK_NUM,
l.VERIFICATION_AMOUNT,
l.VERIFICATION_AMOUNT_BEG,
l.VERIFICATION_DOC_NUM,
l.SOURCE_LINE_ID,
l.ATTRIBUTE1,
l.ATTRIBUTE2,
l.ATTRIBUTE3,
l.ATTRIBUTE4,
l.ATTRIBUTE5,
l.ATTRIBUTE6
from cux_ap_amt_to_ebs_iface_l l
where h.header_id = l.header_id
order by l.line_id
) item_lines
from cux_ap_amt_to_ebs_iface_h h,hr_operating_units hou
where h.process_status = 'S'
and h.organization_name = hou.name
and h.header_id = 10149;
ret := pljson_util_pkg.ref_cursor_to_json(dyn_ref);
/*ret.print;*/
dbms_output.put_line(replace(ret.to_char(true),'''',null));
end;
To clob The large capacity
The direct print above may exceed the print buffer setting , The following can be changed to clob The way
create or replace function ufx_plson_get_json_from_sql (i_sql in varchar2)
return clob
as
-- Local variables here
tstjson_list pljson_list;
l_Result_json_clob clob;
begin
-- Test statements here
dbms_lob.createtemporary(l_Result_json_clob, true);
tstjson_list := pljson_util_pkg.sql_to_json(i_sql);
tstjson_list.to_clob(l_Result_json_clob);
return l_Result_json_clob;
exception
when others then raise;
end;
/
/* example */
select ufx_plson_get_json_from_sql (i_sql =>
q'[ select sysdate, systimestamp, user from dual]') sql_result_as_json
from dual;
oracle apex The way
cursor The way
somewhat : You can realize nested printing
defects : If the field is null value , Then the field is not displayed , Cannot control whether to print vacant .
DECLARE
c sys_refcursor;
BEGIN
open c for select deptno,
dname,
cursor(select empno,
ename
from emp e
where e.deptno=d.deptno) emps
from dept d;
apex_json.open_object;
apex_json. write('departments', c);
apex_json.close_object;
END;
{ "departments":[
{
"DEPTNO":10,
"DNAME":"ACCOUNTING",
"EMPS":[{
"EMPNO":7839,"ENAME":"KING"}]},
...
,{
"DEPTNO":40,"DNAME":"OPERATIONS","EMPS":null}] }
WRITE_CONTEXT Procedure
advantage : adopt write_context Parameters p_write_null You can control whether to print null values
shortcoming :If the query contains object type, collection or cursor columns, an error is raised. If the column is VARCHAR2 and the uppercase value is ‘TRUE’ or ‘FALSE’, boolean values are generated.
DECLARE
l_context apex_exec.t_context;
begin
l_context := apex_exec.open_query_context(
p_location => apex_exec.c_location_local_db,
p_sql_query => q'#select * from dept#' );
apex_json.open_object;
apex_json.write_context( p_name => 'departments', p_context => l_context);
apex_json.close_object;
end;
{ "departments":[
{ "DEPTNO":10 ,"DNAME":"ACCOUNTING" ,"LOC":"NEW YORK" }
,{ "DEPTNO":20 ,"DNAME":"RESEARCH" ,"LOC":"DALLAS" }
,{ "DEPTNO":30 ,"DNAME":"SALES" ,"LOC":"CHICAGO" }
,{ "DEPTNO":40 ,"DNAME":"OPERATIONS" ,"LOC":"BOSTON" } ] }
边栏推荐
- 2021-07-05c /cad secondary development create arc (4)
- php中在二维数组中根据值返回对应的键值
- IDEA2020中测试PySpark的运行出错
- Tool grass welfare post
- 数仓模型事实表模型设计
- ORACLE 11G SYSAUX表空间满处理及move和shrink区别
- Sentry construction and use
- CAD secondary development object
- oracle-外币记账时总账余额表gl_balance变化(上)
- The win10 network icon disappears, and the network icon turns gray. Open the network and set the flash back to solve the problem
猜你喜欢
Network security -- intrusion detection of emergency response
图解Kubernetes中的etcd的访问
PHP Session原理简析
SQLI-LABS通关(less1)
Only the background of famous universities and factories can programmers have a way out? Netizen: two, big factory background is OK
Sqli-labs customs clearance (less6-less14)
CSRF攻击
The use of regular expressions in JS
SQL注入闭合判断
The default Google browser cannot open the link (clicking the hyperlink does not respond)
随机推荐
Flex Jiugongge layout
MapReduce与YARN原理解析
Brief analysis of PHP session principle
Sqli-labs customs clearance (less2-less5)
JS judge whether the object is empty
UEditor .Net版本任意文件上传漏洞复现
In depth study of JVM bottom layer (V): class loading mechanism
Tool grass welfare post
Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"
In depth study of JVM bottom layer (II): hotspot virtual machine object
SQLI-LABS通关(less6-less14)
pm2简单使用和守护进程
PXC high availability cluster summary
js判断数组中对象是否存在某个值
Sqli labs customs clearance summary-page4
Changes in foreign currency bookkeeping and revaluation general ledger balance table (Part 2)
搭建frp进行内网穿透
php中的数字金额转换大写数字
ORACLE 11.2.0.3 不停机处理SYSAUX表空间一直增长问题
2021-07-19c CAD secondary development creates multiple line segments