Using Create directory & UTL_FILE in Oracle
2011-04-25 16:29
435 查看
Using Create directory & UTL_FILE in Oracle
作者:eygle <http://www.eygle.com/> |【转载时请以超链接形式标明文章出处
<http://www.eygle.com/archives/2005/04/using_create_di.html> 和作者信息及本
声明 <http://www.eygle.com/archives/2006/12/eygle_copyright.html> 】
链接:http://www.eygle.com/archives/2005/04/using_
<http://www.eygle.com/archives/2005/04/using_create_di.html> create_di.html
_____
站内相关文章|Related Articles
* 如何对时间进行简单加减运算
<http://www.eygle.com/archives/2008/04/calculate_datetime.html>
* 并行查询并行度Degree与instances
<http://www.eygle.com/archives/2008/04/parallel_degree_instances.html> 设置
* 关于PARALLEL_MAX_SERVERS参数的设置
<http://www.eygle.com/archives/2007/11/parallel_max_servers.html>
* 使用REF
<http://www.eygle.com/archives/2007/11/oracle_ref_cursor.html> CURSOR处理
Oracle的结果集
* Oracle
<http://www.eygle.com/archives/2007/03/optim_peek_user_binds.html> Peeking绑
定变量的控制
Create directory让我们可以在Oracle数据库中灵活的对文件进行读写操作,极大的提
高了Oracle的易用性和可扩展性。
其语法为:
CREATE [OR REPLACE] DIRECTORY directory AS 'pathname';
本案例具体创建如下:
create or replace directory exp_dir as '/tmp';
目录创建以后,就可以把读写权限授予特定用户,具体语法如下:
GRANT READ[,WRITE] ON DIRECTORY directory TO username;
例如:
grant read, write on directory exp_dir to eygle;
此时用户eygle就拥有了对该目录的读写权限。
让我们看一个简单的测试:
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]$
类似的我们可以通过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 );
10 dbms_output.put_line(fp_buffer );
11 utl_file.fclose(fhandle);
12 end;
13 /
eygle test write one
eygle test write two
PL/SQL procedure successfully completed.
可以查询dba_directories查看所有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
可以使用drop directory删除这些路径.
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
作者:eygle <http://www.eygle.com/> |【转载时请以超链接形式标明文章出处
<http://www.eygle.com/archives/2005/04/using_create_di.html> 和作者信息及本
声明 <http://www.eygle.com/archives/2006/12/eygle_copyright.html> 】
链接:http://www.eygle.com/archives/2005/04/using_
<http://www.eygle.com/archives/2005/04/using_create_di.html> create_di.html
_____
站内相关文章|Related Articles
* 如何对时间进行简单加减运算
<http://www.eygle.com/archives/2008/04/calculate_datetime.html>
* 并行查询并行度Degree与instances
<http://www.eygle.com/archives/2008/04/parallel_degree_instances.html> 设置
* 关于PARALLEL_MAX_SERVERS参数的设置
<http://www.eygle.com/archives/2007/11/parallel_max_servers.html>
* 使用REF
<http://www.eygle.com/archives/2007/11/oracle_ref_cursor.html> CURSOR处理
Oracle的结果集
* Oracle
<http://www.eygle.com/archives/2007/03/optim_peek_user_binds.html> Peeking绑
定变量的控制
Create directory让我们可以在Oracle数据库中灵活的对文件进行读写操作,极大的提
高了Oracle的易用性和可扩展性。
其语法为:
CREATE [OR REPLACE] DIRECTORY directory AS 'pathname';
本案例具体创建如下:
create or replace directory exp_dir as '/tmp';
目录创建以后,就可以把读写权限授予特定用户,具体语法如下:
GRANT READ[,WRITE] ON DIRECTORY directory TO username;
例如:
grant read, write on directory exp_dir to eygle;
此时用户eygle就拥有了对该目录的读写权限。
让我们看一个简单的测试:
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]$
类似的我们可以通过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 );
10 dbms_output.put_line(fp_buffer );
11 utl_file.fclose(fhandle);
12 end;
13 /
eygle test write one
eygle test write two
PL/SQL procedure successfully completed.
可以查询dba_directories查看所有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
可以使用drop directory删除这些路径.
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
相关文章推荐
- Using Create directory & UTL_FILE in Oracle
- Using Create directory & UTL_FILE in Oracle
- Using Create directory & UTL_FILE in Oracle
- Using Create directory & UTL_FILE in Oracle
- Using Create directory & UTL_FILE in Oracle
- Using Create directory & UTL_FILE in Oracle
- prjGetWriteINIFile - How to Read-Write INI file using VB & API - 读取/写入INI文件 - VB6 + API - SourceCode - HackerJLY
- Building a project using a generated make file results in error 'make: 1254-055 Dependency line need
- How to create Oracle ASM devices using device-mapper multipath devices in Red Hat Enterprise Linux 6
- OUI-67076 : OracleHomeInventory was not able to create a lock file" in Unix
- go cannot create <nil>/go.o: No such file or directory的解决办法
- 002-Fatal error in launcher: Unable to create process using '""
- Remote Thread Execution in System Process using NtCreateThreadEx for Vista & Windows7
- How to create an XTR file from XML in Delphi XE4 using XML Mapper?(delphi中如何通过xmlmapper创建xtr文件)
- How&nbsp;to&nbsp;create&nbsp;patch&nbsp;file&nbsp;in&nbsp;Linu…
- Populate A List Item With Record Group In Oracle Forms Using Populate_List And Create_Group_From_Query Command
- Oracle cp: cannot stat `/DISCARD/': No such file or directory 说明
- Populate A List Item With Record Group In Oracle Forms Using Populate_List And Create_Group_From_Query Command
- Data->Iopb->Parameters.Create.Options & FILE_DIRECTORY_FILE 判断是否为路径
- FW: Can’t Create File In The C Drive Root Directory – Windows 8