I have an issue where I need to create a very large .xml from data in Oracle db. I've got everything working just fine, except that I need to specify a record type...where each record is an A(dd), C(hange), or D(elete).
I'm extracting a total of 8 fields, but only 5 fields will actually display in the file...the last 3 are to be used to determine the record type. The code that is giving me trouble is the portion in bold below. How can I produce a variable to be used in the first dynamic "utl_file.put_line"?
The code below produces the error:
then stg_action = 'A'
*
ERROR at line 162:
ORA-06550: line 162, column 15:
PLS-00103: Encountered the symbol "=" when expecting one of the following:
:= . ( @ % ;
I'm extracting a total of 8 fields, but only 5 fields will actually display in the file...the last 3 are to be used to determine the record type. The code that is giving me trouble is the portion in bold below. How can I produce a variable to be used in the first dynamic "utl_file.put_line"?
The code below produces the error:
then stg_action = 'A'
*
ERROR at line 162:
ORA-06550: line 162, column 15:
PLS-00103: Encountered the symbol "=" when expecting one of the following:
:= . ( @ % ;
Code:
set feedback off;
set long 99000;
set serveroutput on size 1000000;
declare
cursor c1 is
select
fld1,
fld2,
fld3,
fld4,
fld5,
fld6,
fld7,
fld8
from tblA
where fld1 = 'Value';
fld1 tblA.fld1%;
fld2 tblA.fld2%;
fld3 tblA.fld3%;
fld4 tblA.fld4%;
fld5 tblA.fld5%;
fld6 tblA.fld6%;
fld7 tblA.fld7%;
fld8 tblA.fld8%;
l_file_hdl utl_file.file_type;
BEGIN
l_file_hdl:= utl_file.fopen('/u01/app/data','ccs45.txt','W',32767);
utl_file.put_line(l_file_hdl,'<?xml version="1.0" encoding="UTF-8"?>');
utl_file.put_line(l_file_hdl,'<merchant_import xsi:noNamespaceSchemaLocation="[URL unfurl="true"]http://xml.here_v1.2.xsd"[/URL] xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance">');[/URL]
open c1;
loop
fetch c1 into
stg_fld1,
stg_fld2,
stg_fld3,
stg_fld4,
stg_fld5,
stg_fld6,
stg_fld7,
stg_fld8;
exit when c1%notfound;
[b]
stg_action:=
if stg_fld6 = TO_CHAR(SYSDATE,'YYYY-MM-DD') and
stg_fld7 = TO_CHAR(SYSDATE,'YYYY-MM-DD') and
stg_fld8 is null
then stg_action = 'A';
else
if stg_fld6 <> TO_CHAR(SYSDATE,'YYYY-MM-DD') and
stg_fld7 = TO_CHAR(SYSDATE,'YYYY-MM-DD') and
stg_fld8 is null
then stg_action = 'C';
else
if stg_fld7 = TO_CHAR(SYSDATE,'YYYY-MM-DD') and
not(stg_fld8 is null)
then stg_action = 'D';
End if
[/b]
utl_file.put_line(l_file_hdl, '<merchant>');
utl_file.put_line(l_file_hdl, ' <action>' || [b]stg_action[/b] || '</action>');
utl_file.put_line(l_file_hdl, ' <alternate_id>' || stg_fld1 || '</alternate_id>');
utl_file.put_line(l_file_hdl, ' <customer_id>' || stg_fld2 || '</customer_id>');
utl_file.put_line(l_file_hdl, ' <merchant_id>' || stg_fld3 || '</merchant_id>');
utl_file.put_line(l_file_hdl, ' <merchant_name>' || stg_fld4 || '</merchant_name>');
utl_file.put_line(l_file_hdl, ' <merchant_add1>' || stg_fld5 || '</merchant_add1>');
utl_file.put_line(l_file_hdl, '</merchant>');
end loop;
utl_file.put_line(l_file_hdl, '</merchant_import>');
utl_file.fflush(l_file_hdl);
close c1;
utl_file.fclose(l_file_hdl);
end;
/