Oracle's Utl_file. fopen Study Notes

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.