Below is an example of DBMS_XMLGEN.getxml to generate Dynamic XML Output.
Using Cursor in select query.
DECLARE
--
l_sql2 VARCHAR2(32767);
l_qryctx DBMS_XMLGEN.ctxhandle;
l_length NUMBER(10);
l_xmlstr VARCHAR2(32767);
l_offset NUMBER(10) := 32767;
l_retrieved NUMBER(10) := 0;
l_result CLOB;
l_no_rows NUMBER;
--
BEGIN
l_sql2 :=
( 'SELECT cust_trx_type_id
, primary_salesrep_id
, purchase_order
, customer_trx_id
, customer_transaction_id
, invoice_number
, sob_currency
, invoice_currency
, print_date
, transaction_date
, transaction_type
, email_address
, rep_footer
, line_pmnt_statement
, line_footer1
, line_footer2
, CURSOR(SELECT ract.customer_trx_id customer_trx_id
, oeoh.attribute2 project_name
, SUM(NVL(DECODE(ractt.TYPE, ''CM'', ractl.quantity_credited, ractl.quantity_invoiced),0)) quantity
, zxl.tax_rate_code tax_rate_code
, zxl.tax_rate tax_rate
, SUM(DECODE(line_type, ''LINE'', extended_amount)) VALUE
, SUM(zxl.tax_amt) tax_value
, SUM(DECODE(line_type, ''LINE'', NVL(ract.exchange_rate, 1) * extended_amount)) func_value
, SUM(NVL(ract.exchange_rate, 1) * zxl.tax_amt) func_tax_value
, (SELECT COUNT(1)
FROM oe_order_lines_all oe
WHERE oe.header_id = oeoh.header_id) jobs
FROM ra_customer_trx_all ract
, ra_customer_trx_lines_all ractl
, oe_order_headers_all oeoh
, oe_order_lines_all oeol
, ra_cust_trx_types_all ractt
, zx_lines zxl
WHERE 1 = 1
AND zxl.trx_line_id(+) = ractl.customer_trx_line_id
AND zxl.trx_id(+) = ractl.customer_trx_id
AND ract.org_id = ractt.org_id
AND ract.cust_trx_type_id = ractt.cust_trx_type_id
AND ractl.interface_line_attribute6 = oeol.line_id
AND oeol.header_id = oeoh.header_id
AND ractl.customer_trx_id = ract.customer_trx_id
AND ractl.line_type = ''LINE''
AND ract.customer_trx_id = sv.customer_trx_id
GROUP BY ract.customer_trx_id
, oeoh.attribute2
, zxl.tax_rate_code
, zxl.tax_rate
, oeoh.header_id) G_INVOICE_LINES
,CURSOR(SELECT cust_trx_id
,invoice_number
,bill_cust_name
,party_number
,bill_acc
,contact
,primary_phone_number
,report_date
,CURSOR(SELECT oeh.order_number trx_number
,CURSOR(SELECT C_INV_H1,C_INV_A1
FROM xxar_invoice_details_v WHERE line_id = rctl.interface_line_attribute6) Q_HEADER
FROM oe_order_headers_all oeh
, oe_order_lines_all ool
, ra_customer_trx_lines_all rctl
WHERE 1 = 1
AND oeh.header_id = ool.header_id
AND ool.line_id = rctl.interface_line_attribute6
AND rctl.customer_trx_id = hv.cust_trx_id )Q_HEADERS
FROM xxar_invoice_header_v hv
WHERE 1 = 1
AND cust_trx_id = customer_trx_id)Q_SUMMARY
FROM xxar_invoice_summary_v sv
WHERE 1 = 1
AND sv.customer_trx_id = '|| p_customer_trx_id);
--
fnd_file.put_line(fnd_file.LOG
, 'query = '
|| l_sql2);
--
l_qryctx := DBMS_XMLGEN.newcontext(l_sql2);
--
DBMS_XMLGEN.setrowsettag(l_qryctx, 'XXAR_CONINVREP_XML');
DBMS_XMLGEN.setrowtag(l_qryctx, 'G_INVOICE_HEADER');
--
l_result := DBMS_XMLGEN.getxml(l_qryctx);
l_no_rows := DBMS_XMLGEN.getnumrowsprocessed(l_qryctx);
fnd_file.put_line(fnd_file.LOG
, 'No of rows processed= '
|| l_no_rows);
--
l_length := NVL(DBMS_LOB.getlength(l_result), 0);
fnd_file.put_line(fnd_file.LOG
, 'Length= '
|| l_length);
--
LOOP
EXIT WHEN l_length = l_retrieved;
--
IF (l_length - l_retrieved) < 32000 THEN
SELECT SUBSTR(l_result, l_retrieved + 1) INTO l_xmlstr FROM DUAL;
l_retrieved := l_length;
fnd_file.put_line(fnd_file.output, l_xmlstr);
--
ELSE
SELECT SUBSTR(l_result, l_retrieved + 1, l_offset) INTO l_xmlstr FROM DUAL;
l_retrieved := l_retrieved + l_offset;
fnd_file.put(fnd_file.output, l_xmlstr);
--
END IF;
--
END LOOP;
--
DBMS_XMLGEN.closecontext(l_qryctx);
--
END;
Sample output :
Using Cursor in select query.
DECLARE
--
l_sql2 VARCHAR2(32767);
l_qryctx DBMS_XMLGEN.ctxhandle;
l_length NUMBER(10);
l_xmlstr VARCHAR2(32767);
l_offset NUMBER(10) := 32767;
l_retrieved NUMBER(10) := 0;
l_result CLOB;
l_no_rows NUMBER;
--
BEGIN
l_sql2 :=
( 'SELECT cust_trx_type_id
, primary_salesrep_id
, purchase_order
, customer_trx_id
, customer_transaction_id
, invoice_number
, sob_currency
, invoice_currency
, print_date
, transaction_date
, transaction_type
, email_address
, rep_footer
, line_pmnt_statement
, line_footer1
, line_footer2
, CURSOR(SELECT ract.customer_trx_id customer_trx_id
, oeoh.attribute2 project_name
, SUM(NVL(DECODE(ractt.TYPE, ''CM'', ractl.quantity_credited, ractl.quantity_invoiced),0)) quantity
, zxl.tax_rate_code tax_rate_code
, zxl.tax_rate tax_rate
, SUM(DECODE(line_type, ''LINE'', extended_amount)) VALUE
, SUM(zxl.tax_amt) tax_value
, SUM(DECODE(line_type, ''LINE'', NVL(ract.exchange_rate, 1) * extended_amount)) func_value
, SUM(NVL(ract.exchange_rate, 1) * zxl.tax_amt) func_tax_value
, (SELECT COUNT(1)
FROM oe_order_lines_all oe
WHERE oe.header_id = oeoh.header_id) jobs
FROM ra_customer_trx_all ract
, ra_customer_trx_lines_all ractl
, oe_order_headers_all oeoh
, oe_order_lines_all oeol
, ra_cust_trx_types_all ractt
, zx_lines zxl
WHERE 1 = 1
AND zxl.trx_line_id(+) = ractl.customer_trx_line_id
AND zxl.trx_id(+) = ractl.customer_trx_id
AND ract.org_id = ractt.org_id
AND ract.cust_trx_type_id = ractt.cust_trx_type_id
AND ractl.interface_line_attribute6 = oeol.line_id
AND oeol.header_id = oeoh.header_id
AND ractl.customer_trx_id = ract.customer_trx_id
AND ractl.line_type = ''LINE''
AND ract.customer_trx_id = sv.customer_trx_id
GROUP BY ract.customer_trx_id
, oeoh.attribute2
, zxl.tax_rate_code
, zxl.tax_rate
, oeoh.header_id) G_INVOICE_LINES
,CURSOR(SELECT cust_trx_id
,invoice_number
,bill_cust_name
,party_number
,bill_acc
,contact
,primary_phone_number
,report_date
,CURSOR(SELECT oeh.order_number trx_number
,CURSOR(SELECT C_INV_H1,C_INV_A1
FROM xxar_invoice_details_v WHERE line_id = rctl.interface_line_attribute6) Q_HEADER
FROM oe_order_headers_all oeh
, oe_order_lines_all ool
, ra_customer_trx_lines_all rctl
WHERE 1 = 1
AND oeh.header_id = ool.header_id
AND ool.line_id = rctl.interface_line_attribute6
AND rctl.customer_trx_id = hv.cust_trx_id )Q_HEADERS
FROM xxar_invoice_header_v hv
WHERE 1 = 1
AND cust_trx_id = customer_trx_id)Q_SUMMARY
FROM xxar_invoice_summary_v sv
WHERE 1 = 1
AND sv.customer_trx_id = '|| p_customer_trx_id);
--
fnd_file.put_line(fnd_file.LOG
, 'query = '
|| l_sql2);
--
l_qryctx := DBMS_XMLGEN.newcontext(l_sql2);
--
DBMS_XMLGEN.setrowsettag(l_qryctx, 'XXAR_CONINVREP_XML');
DBMS_XMLGEN.setrowtag(l_qryctx, 'G_INVOICE_HEADER');
--
l_result := DBMS_XMLGEN.getxml(l_qryctx);
l_no_rows := DBMS_XMLGEN.getnumrowsprocessed(l_qryctx);
fnd_file.put_line(fnd_file.LOG
, 'No of rows processed= '
|| l_no_rows);
--
l_length := NVL(DBMS_LOB.getlength(l_result), 0);
fnd_file.put_line(fnd_file.LOG
, 'Length= '
|| l_length);
--
LOOP
EXIT WHEN l_length = l_retrieved;
--
IF (l_length - l_retrieved) < 32000 THEN
SELECT SUBSTR(l_result, l_retrieved + 1) INTO l_xmlstr FROM DUAL;
l_retrieved := l_length;
fnd_file.put_line(fnd_file.output, l_xmlstr);
--
ELSE
SELECT SUBSTR(l_result, l_retrieved + 1, l_offset) INTO l_xmlstr FROM DUAL;
l_retrieved := l_retrieved + l_offset;
fnd_file.put(fnd_file.output, l_xmlstr);
--
END IF;
--
END LOOP;
--
DBMS_XMLGEN.closecontext(l_qryctx);
--
END;
Sample output :
No comments:
Post a Comment