Oracle provides file action packages for utl_file in Utl_file packages. Fopen is responsible for opening a file. Utl_file. FOPEN (varchar2, filename in varchar2, open_mode in varchar2) return file_type; Location is the path parameter, filename is the filename, Open_mode is the open mode, ' R ' is the read text, ' W ' is the text, ' A ' is the appended text, the parameter is not case-sensitive, if the specified ' a ' but the file does not exist, it will be created with ' W ' first, ' W ' There is a function of covering; The location cannot be simply specified as a path such as ' D:\temp ', to establish a directory variable and pay permissions (must be logged in as DBA): SQL code Create or replace directory D_ OUTPUT as ' D:\TEMP '; Grant Read,write on directory d_output to TestDB; GRANT EXECUTE on Utl_file to TestDB; You can then use the Utl_file package to build the file with the SQL code v_file utl_file. File_type; V_file: = Utl_file. FOPEN (' d_output ', ' Data.txt ', ' W '); The Data.txt source document can be established on the D:\TEMP of the database server<http://lveyo.javaeye.com/blog/351416>Create or Replace procedure Pro_to_txt (File_owner varchar2,file_name VARCHAR2) is File_handle utl_file.file_ty Pe Stor_text VARCHAR2 (4000); N Number;i Number;begini:=1; SELECT MAX (line) to N from All_source WHERE owner= ' | | File_owner | | ' and name= ' | | file_name | | "and type= ' PROCEDURE '; File_handle:=utl_file.fopen ('/oradata/procedure_bak ', ' zhfx117.txt ', ' A '); utl_file.put_ Line (File_handle, ' PROCEDURE NAME: ' | | file_name); While I<=nLOOP SELECT TEXT to Stor_text from All_source WHERE OWNER=file_ownerand NAME=file_nameand TYPE= ' PROCEDURE ' and Line= I; I:=i+1; Utl_file.put_line (File_handle,stor_text); END LOOP; Utl_file.fclose (file_handle); commit;end pro_to_txt;
Oracle's Utl_file. fopen Study Notes