このステップOracle 10g - xml ファイルを作成するためにクエリ結果をファイルに書き込む を使用しました。これは私がロードしたSQLスクリプトです
c:>sqlplus -s ユーザー名/パスワード@database.domain.com < tmp.sql > output.txt
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;
/
結果は次のとおりです。
<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XMLSpy v2010 rel. 2 (http://www.altova.com)-->
<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">
<Header>
<harpeml:technicalIndicator>HDR</harpeml:technicalIndicator>
<harpeml:orderNumber>0000000161</harpeml:orderNumber>
<harpeml:dataSelectionDate>02/07/2012</harpeml:dataSelectionDate>
<harpeml:extractionTimeStamp>06-JUL-12 09.29.01.812631 AM +03:00</harpeml:extractionTimeStamp>2</Header>
<ExchangeRates>
<ExchangeRate>
<harpeml:technicalIndicator>02</harpeml:technicalIndicator>
<harpeml:currencyExchangeRateType>D</harpeml:currencyExchangeRateType>
<harpeml:baseCurrencyCode>BOB</harpeml:baseCurrencyCode>
<harpeml:counterCurrencyCode>SGD</harpeml:counterCurrencyCode>
<harpeml:startValidityDate>02/07/2012<harpeml:startValidityDate>
<harpeml:countryCode>BDI</harpeml:countryCode>
<harpeml:exchangeRate>162</harpeml:exchangeRate>
<harpeml:appreciationOrDepreciationReport>1</harpeml:appreciationOrDepreciationReport>
<harpeml:dataSourceSystem>freetext</harpeml:dataSourceSystem>
</ExchangeRate>
</ExchangeRates>
</HarpeML_CBS_IMX_ExchangeRate_Flow>
**<harpeml:exchangeRate>163</harpeml:exchangeRate>
<harpeml:appreciationOrDepreciationReport>1</harpeml:appreciationOrDepreciationReport>
<harpeml:dataSourceSystem>freetext</harpeml:dataSourceSystem>
</ExchangeRate>
</ExchangeRates>
</HarpeML_CBS_IMX_ExchangeRate_Flow>**
最後のブロックが 2 回表示される理由を知っている人はいますか? また、出力ファイルから空の行を削除する方法について何か提案をいただけますか?