5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Oracle SQLの結果をXMLで出力

Last updated at Posted at 2015-01-19

内容

dbms_xmlgenパッケージのgetxmlファンクションを使用し、SQLの実行結果をXMLで出力する。

手順

"select * from v$database"の実行結果をXMLで出力する。

  1. SQLの実行結果をXMLで出力するSQLファイル"xmlout.sql"を作成する。

    xmlout.sql
    set pages 0
    set lines 10000
    set long 10000000
    set trimspool on
    col xml for a1000
    
    spool result.xml
    select dbms_xmlgen.getxml('select * from v$database') as xml from dual;
    spool off
    
    exit
    
  2. xmlout.sqlをsqlplusで実行する。

    sqlplus -S / as sysdba @xmlout.sql
    
  3. 出力結果ファイル(result.xml)の内容を確認する。

    result.xml
    <?xml version="1.0"?>
    <ROWSET>
     <ROW>
      <DBID>12345678</DBID>
      <NAME>TEST</NAME>
      <CREATED>14-11-15</CREATED>
      <RESETLOGS_CHANGE_x0023_>1</RESETLOGS_CHANGE_x0023_>
      <RESETLOGS_TIME>14-11-15</RESETLOGS_TIME>
      <PRIOR_RESETLOGS_CHANGE_x0023_>0</PRIOR_RESETLOGS_CHANGE_x0023_>
      <LOG_MODE>ARCHIVELOG</LOG_MODE>
      …(省略)…
     </ROW>
    </ROWSET>
    

以上。

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?