So using that I have first to export the queries to a file and then export the data from it in the XML.
Is there a way to export sql queries directly to the xml?
Could you suggest me what to use in order to add the fixed values such as <<?xml version="1.0" encoding="UTF-8"?>> and how to export both(fixed values + result of queries) in a file?
---------- Post updated at 12:00 PM ---------- Previous update was at 10:42 AM ----------
I try to use this:
SQL> spool test2.txt
SQL> set serveroutput on
SQL> begin
2 dbms_output.put_Line('<?xml version="1.0" encoding="UTF-8"?>');
3 end;
4 /
<?xml version="1.0" encoding="UTF-8"?>
PL/SQL procedure successfully completed.
SQL> SELECT '<ns1:messageId>' || ' ' || imk.nextval || '</ns1:messageId>' FROM dual;
'<NS1:MESSAGEID>'||''||IMK.NEXTVAL||'</NS1:MESSAGEID>'
--------------------------------------------------------------------------------
<ns1:messageId> 47</ns1:messageId>
SQL> spool off
And here is the result:
cat test2.txt:
SQL> set serveroutput on
SQL> begin
2 dbms_output.put_Line('<?xml version="1.0" encoding="UTF-8"?>');
3 end;
4 /
<?xml version="1.0" encoding="UTF-8"?>
PL/SQL procedure successfully completed.
SQL> SELECT '<ns1:messageId>' || ' ' || imk.nextval || '</ns1:messageId>' FROM dual;
'<NS1:MESSAGEID>'||''||IMK.NEXTVAL||'</NS1:MESSAGEID>'
--------------------------------------------------------------------------------
<ns1:messageId> 47</ns1:messageId>
SQL> spool off
As I want to have only the marked in red I tried to turn off some of the settings
set termout off
set echo off
set verify off
set heading off
but it seems it didnt take effect.
Where <?xml version="1.0" encoding="UTF-8"?> is fixed text which I just want to store in the file and <ns1:messageId> 47</ns1:messageId> is the result of the following select: SELECT '<ns1:messageId>' || ' ' || imk.nextval || '</ns1:messageId>' FROM dual;
set pagesize 0;
set serveroutput on
set termout off
set verify off
set heading off
set long 999
set lines 999
SET FEEDBACK OFF
SET HEAD OFF
SELECT '<?xml version="1.0" encoding="UTF-8"?>' || chr(10) ||
'<!--Sample XML file generated by XMLSpy v2010 rel. 2 (http://www.altova.com)-->' || chr(10) ||
'<HarpeML_CBS_IMX_ExchangeRate_Flow xsi:noNamespaceSchemaLocation="HarpeML_CBS_IMX_ExchangeRate(REF-IMX-1)_v0.0.00.xsd" xmlns:harpeml="http://www.harpeml.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'||chr(10)||
'<Header>'||chr(10)||
'<harpeml:technicalIndicator>'||'HDR'||'</harpeml:technicalIndicator>'||chr(10)||
'<harpeml:orderNumber>'||''||lpad ( imk.nextval, 10, '0' )||'</harpeml:orderNumber>'||chr(10)||
'<harpeml:dataSelectionDate>'||''||to_char(sysdate - 4,'DD/MM/YYYY')||''||'</harpeml:dataSelectionDate>'||chr(10)||
'<harpeml:extractionTimeStamp>'||''||CURRENT_TIMESTAMP||''||'</harpeml:extractionTimeStamp>'||chr(50)||'</Header>'
FROM dual;
SELECT '<ExchangeRates>'||chr(10)||'<ExchangeRate>'||chr(10)||
'<harpeml:technicalIndicator>'||'02'||'</harpeml:technicalIndicator>'||chr(10)||
'<harpeml:currencyExchangeRateType>'||''||'D'||'</harpeml:currencyExchangeRateType>'||chr(10)
FROM dual;
SELECT '<harpeml:baseCurrencyCode>'||abrev||'</harpeml:baseCurrencyCode>' FROM(SELECT abrev FROM v_domaine where type = 'DEVISE' ORDER BY dbms_random.normal)WHERE rownum = 1;
SELECT
'<harpeml:counterCurrencyCode>'||abrev||'</harpeml:counterCurrencyCode>'FROM(SELECT abrev FROM v_domaine where type = 'DEVISE' ORDER BY dbms_random.normal)WHERE rownum = 1;
SELECT
'<harpeml:startValidityDate>'||''||to_char(sysdate - 4,'DD/MM/YYYY')||''||'<harpeml:startValidityDate>'||chr(10)||
'<harpeml:countryCode>'||abrev||'</harpeml:countryCode>'FROM(SELECT abrev FROM v_domaine where type = 'pays' ORDER BY dbms_random.normal)WHERE rownum = 1;
SELECT
'<harpeml:exchangeRate>'||rpad ( imk.nextval, 3, '51' )||'</harpeml:exchangeRate>'||chr(10)||
'<harpeml:appreciationOrDepreciationReport>'||'1'||'</harpeml:appreciationOrDepreciationReport>'||chr(10)||
'<harpeml:dataSourceSystem>'||'freetext'||'</harpeml:dataSourceSystem>'||chr(10)||
'</ExchangeRate>'||chr(10)||
'</ExchangeRates>'||chr(10)||
'</HarpeML_CBS_IMX_ExchangeRate_Flow>'
from dual;
/