Print CLOB content out as is in Oracle SQL script

后端 未结 4 1348
一向
一向 2021-01-25 18:09

To start with here is the bigger picture of the task I\'m trying to do. I need to create a xml file from the results of the particular SQL request and store it in a file on the

相关标签:
4条回答
  • 2021-01-25 18:11

    One possible approach is to do the following:

    1. Create a database table with a single column and row of type CLOB.
    2. On server, insert the produced XML into that table.
    3. On client run the SQL*PLus script like this:

      SET WRAP OFF  
      SET HEADING OFF  
      SET ECHO OFF  
      SPOOL file_name.xml
      
      SELECT your\_clob\_column FROM your\_table;
      
      SPOOL OFF
      

    That will dump your XML into file_name.xml After that, you will need to truncate you table by issuing:

    TRUNCATE TABLE your\_table DROP STORAGE;
    

    otherwise the table won't shrink even if you delete the line with CLOB.

    0 讨论(0)
  • 2021-01-25 18:12

    Check APC's CLOB workaround for dbms_output on http://forums.oracle.com/forums/thread.jspa?threadID=306557

    0 讨论(0)
  • 2021-01-25 18:31

    Why don't you use DBMS_OUTPUT.PUT instead of DBMS_OUTPUT.PUT_LINE? Give it a try. The trick is to add a newline character after printing your content. You can do it by calling DBMS_OUTPUT.NEW_LINE.

    0 讨论(0)
  • 2021-01-25 18:33

    You can add a delimiter and print out 254 characters, then in notepad++ (in extended mode ~\r\n) replace this delimiter :

     loop exit when l_offset > dbms_lob.getlength(v_xml);
       DBMS_OUTPUT.PUT_LINE (dbms_lob.substr( v_xml, 254, l_offset) || '~');
       l_offset := l_offset + 255;
      end loop;
    
    0 讨论(0)
提交回复
热议问题