匯出ddl定義.sql

Nalternative發表於2011-04-02

create or replace directory UTL_DIR as 'D:\wang';
/
create or replace procedure p_exportDLL(p_table_name varchar2,p_filename varchar2) is
begin

  declare
    l_file     UTL_FILE.FILE_TYPE;
    l_buffer   VARCHAR2(1000);
    l_amount   BINARY_INTEGER := 100;
    l_pos      INTEGER := 1;
    l_clob     clob;
    l_clob_len INTEGER;
  begin
    select dbms_metadata.get_ddl('TABLE',p_table_name )||';' into l_clob from dual;
    l_clob_len := DBMS_LOB.GETLENGTH(l_clob);
    l_file     := UTL_FILE.FOPEN('UTL_DIR', p_filename||'.sql', 'a', 1000);
   
  

    WHILE l_pos < l_clob_len LOOP
      DBMS_LOB.READ(l_clob, l_amount, l_pos, l_buffer);
      UTL_FILE.put(l_file, l_buffer);
      l_pos := l_pos + l_amount;
    END LOOP;
    UTL_FILE.FCLOSE(l_file);
    --if @@error
  end;
end p_exportDLL;
/
CREATE OR REPLACE PROCEDURE p_whole AS
BEGIN
  FOR x IN (SELECT table_name FROM user_tables) LOOP
       p_exportDLL(x.table_name,'paul');
  END LOOP;
END  p_whole;
/
begin
  p_whole;
end;
/

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25323853/viewspace-691546/,如需轉載,請註明出處,否則將追究法律責任。

相關文章