ORACLE Directory directory

Source: Internet
Author: User
Tags create directory
Create directory gives us the flexibility to read and write files in an Oracle database, greatly improving the ease of use and scalability of Oracle. The syntax is: CREATE [OR REPLACE] Directory directory as ' pathname '; This case is specifically created as follows: Create or replace directory Exp_dir as '/tmp '; After the directory is created, you can grant read and write permissions to specific users in the following syntax: Grant Read[,write] on directory directory to username; For example: Grant read, write on directory exp_dir to Eygle; At this point, the user eygle has read and write access to the directory. Let's look at a simple test: sql> Create or replace directory Utl_file_dir as '/opt/oracle/utl_file '; Directory created. Sql> declare 2 fhandle utl_file.file_type; 3 begin 4 Fhandle: = Utl_file.fopen (' Utl_file_dir ', ' example.txt ', ' W '); 5 Utl_file.put_line (Fhandle, ' eygle test write one '); 6 Utl_file.put_line (fhandle, ' eygle test write two '); 7 Utl_file.fclose (Fhandle); 8 End; 9/pl/sql procedure successfully completed. Sql>! [Oracle@jumper 9.2.0]$ more/opt/oracle/utl_file/example.txt eygle test write one Eygle test write two [Oracle@jumper 9.2. 0]$ Similar we can read files through Utl_file: sql> declare 2 fhandle utl_file.file_type; 3 Fp_buffer varchar2 (4000); 4 Begin 5 Fhandle: = Utl_file.fopen (' Utl_file_dir ', ' example.txt ', ' R '); 6 7 utl_file.get_line (Fhandle, Fp_buffer); 8 Dbms_output.put_line (Fp_buffer); 9 Utl_file.get_line (Fhandle, Fp_buffer); Dbms_output.put_line (Fp_buffer); One utl_file.fclose (fhandle); End; 13/eygle Test Write one eygle test write two Pl/sql procedure successfully. You can query dba_directories to view all your directory. Sql> select * from Dba_directories; OWNER directory_name directory_path----------------------------------------------------------------------------- -------------sys utl_file_dir/opt/oracle/utl_file SYS bdump_dir/opt/oracle/admin/conner/bdump SYS exp_dir/opt/ Oracle/utl_file can use drop directory to remove these paths. sql> Drop directory Exp_dir; Directory dropped sql> select * from Dba_directories; OWNER directory_name directory_path----------------------------------------------------------------------------- -------------SYS utl_file_dir/opt/oracle/utl_file SYS bdump_dir/opt/oracle/admin/conner/bdump
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.