Wednesday, 20 January 2016

XML : Export XMLType columns from table to multiple files using Oracle SQL

I have a table with a schema that looks something like this:

  Name         Null     Type                          ------------ -------- ---------------------------   ID           NOT NULL NUMBER                        XML_DOCUMENT          XMLTYPE()                     CREATED_TS            TIMESTAMP(6) WITH TIME ZONE  TRAN_ID               NUMBER     

What I want to do is something like export every XML_DOCUMENT column to a file where TRAN_ID = (something).

So for example if I want TRAN_ID=10, if there are 20 rows with TRAN_ID=10 then I want to get 20 xml files that correspond with the XML_DOCUMENT column.

I tried:

  create or replace directory exp_dir as '/path/to/something';    begin    for c in (select xml_document,id from my_table where tran_id=10) loop      dbms_xslprocessor.clob2file(c.xml_document.getClobVal(), 'EXP_DIR', 'document' || c.id);   end loop;  end;    

This runs for awhile leading me to believe it's doing something, then says it finished successfully. However, when I check the directory '/path/to/something' it's empty.

I'm just looking for some to help to get this working. Thanks.

No comments:

Post a Comment