I'm trying to extract some data from my database into a XML file. To do so, in use a bash script that calls sqlplus command and spool the result into a new file.
The problem happens once the result extracted. My xml file isn't valid anymore because there are some unwanted new lines added...
Here is an example of what I want:
<xml>
<element>John</element>
<element>some data</element>
<element>a longer data line</element>
</xml>
And here is what I got:
<xml>
<element>John</element>
<element>some data</eleme
nt>
<element>a longer data
line</element>
</xml>
It seems that the longest lines are cut but I set linesize to 32767 in Sqlplus and these lines aren't so long...
This is what my sqlplus command looks like:
sqlplus -s {connection} << EOF
set serveroutput on size unlimited
set feedback off
set termout off
set linesize 32767
spool file.xml;
DECLARE
l_xmltype XMLTYPE;
l_ctx dbms_xmlgen.ctxhandle;
v_clob CLOB;
v_clob_length INTEGER;
pos INTEGER;
buffer VARCHAR2(32767);
amount BINARY_INTEGER := 32767;
BEGIN
l_ctx := dbms_xmlgen.newcontext('SELECT a.rowid, a.* FROM mytable a');
l_xmltype := dbms_xmlgen.getXmlType(l_ctx);
dbms_xmlgen.closeContext(l_ctx);
v_clob := l_xmltype.getClobVal;
v_clob_length := length(v_clob);
WHILE pos < clob_length LOOP
dbms_lob.read(v_clob, amount, pos, buffer);
dbms_output.put_line(buffer);
pos := pos + amount;
END LOOP;
END;
/
EOF
Spool off;
Do you have any clue to help me solve this problem?
Thanks!