码迷,mamicode.com
首页 > 数据库 > 详细

oracle plsql utl_file

时间:2019-09-16 16:20:35      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:procedure   offset   clob   line   rac   arc   proc   pen   metadata   

set SERVEROUT on
DECLARE
tab_sql varchar2(4000);
tab_lob clob;
TYPE ddl_type IS REF CURSOR;
ddl_cur ddl_type;
type tab_ddl_type is record(
ddl_con clob
);
tab_ddl tab_ddl_type;
cursor tab_cur is select DISTINCT object_type,object_name,OWNER from dba_procedures where owner=‘FWPROD‘ ;
file utl_file.file_type;
clob_length number(20);
clob_part VARCHAR2(1024);
offset NUMBER := 1;
BEGIN
file := utl_file.fopen(‘DATA_PUMP_DIR‘, ‘mes_procedure_ddl.log‘, ‘ab‘);
for i in tab_cur loop
tab_sql := ‘select dbms_metadata.get_ddl(‘‘‘||i.object_type||‘‘‘,‘‘‘||i.object_name||‘‘‘,‘||‘‘‘‘||i.owner||‘‘‘) as ddl_con from dual‘;
DBMS_OUTPUT.PUT_LINE(tab_sql);
open ddl_cur for tab_sql;
FETCH ddl_cur INTO tab_ddl;
--DBMS_OUTPUT.PUT_LINE(tab_ddl.ddl_con);
clob_length := LENGTH(tab_ddl.ddl_con);
offset := 1;
LOOP
EXIT WHEN offset >= clob_length;
clob_part := DBMS_LOB.SUBSTR (tab_ddl.ddl_con, 1024, offset);
UTL_FILE.PUT_RAW(file, utl_raw.cast_to_raw(clob_part));
UTL_FILE.FFLUSH(file);
offset := offset + 1024;
END LOOP;
close ddl_cur;
END LOOP;
utl_file.fclose(file);
END;
/

oracle plsql utl_file

标签:procedure   offset   clob   line   rac   arc   proc   pen   metadata   

原文地址:https://blog.51cto.com/12408798/2438213

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!