ITPub博客

首页 > 数据库 > Oracle > UTL_FILE应用

UTL_FILE应用

原创 Oracle 作者:eworm 时间:2007-09-18 16:15:07 0 删除 编辑

Security Model

UTL_FILE is available for both client-side and server-side PL/SQL. Both the client (text I/O) and server implementations are subject to server-side file system permission checking.

....................

[@more@]

UTL_FILE应用

2007.09.18

Security Model

UTL_FILE is available for both client-side and server-side PL/SQL. Both the client (text I/O) and server implementations are subject to server-side file system permission checking.

In the past, accessible directories for the UTL_FILE functions were specified in the initialization file using the UTL_FILE_DIR parameter. However, UTL_FILE_DIR access is not recommended. It is recommended that you use the CREATE DIRECTORY feature, which replaces UTL_FILE_DIR. Directory objects offer more flexibility and granular control to the UTL_FILE application administrator, can be maintained dynamically (that is, without shutting down the database), and are consistent with other Oracle tools. CREATE DIRECTORY privilege is granted only to SYS and SYSTEM by default.

Note:

Use the CREATE DIRECTORY feature instead of UTL_FILE_DIR for directory access verification.

On UNIX systems, the owner of a file created by the FOPEN function is the owner of the shadow process running the instance. Normally, this owner is ORACLE. Files created using FOPEN are always writable and readable using the UTL_FILE subprograms, but non privileged users who need to read these files outside of PL/SQL may need access from a system administrator.

一、函数FOPEN


FOPEN Function

This function opens a file. You can specify the maximum line size and have a maximum of 50 files open simultaneously. See also FOPEN_NCHAR Function.

Syntax

UTL_FILE.FOPEN (

location IN VARCHAR2,

filename IN VARCHAR2,

open_mode IN VARCHAR2,

max_linesize IN BINARY_INTEGER)

RETURN file_type;

Parameters

Table 167-8 FOPEN Function Parameters

Parameter

Description

location

Directory location of file. This string is a directory object name and is case sensitive. The default is uppercase. Read privileges must be granted on this directory object for the UTL_FILE user to run FOPEN.

filename

File name, including extension (file type), without directory path. If a directory path is given as a part of the filename, it is ignored by FOPEN. On Unix, the filename cannot end with /.

open_mode

Specifies how the file is opened. Modes include:

r -- read text

w -- write text

a -- append text

rb -- read byte mode

wb -- write byte mode

ab -- append byte mode

If you try to open a file specifying 'a' or 'ab' for open_mode but the file does not exist, the file is created in write mode.

max_linesize

Maximum number of characters for each line, including the newline character, for this file (minimum value 1, maximum value 32767). If unspecified, Oracle supplies a default value of 1024.

Return Values

FOPEN returns a file handle, which must be passed to all subsequent procedures that operate on that file. The specific contents of the file handle are private to the UTL_FILE package, and individual components should not be referenced or changed by the UTL_FILE user.

Table 167-9 FOPEN Function Return Values

Return

Description

file_type

Handle to open file.

Usage Notes

The file location and file name parameters must be supplied to the FOPEN function as quoted strings so that the file location can be checked against the list of accessible directories as specified by the ALL_DIRECTORIES view of accessible directory objects.

Exceptions

INVALID_PATH: File location or name was invalid.

INVALID_MODE: The open_mode string was invalid.

INVALID_OPERATION: File could not be opened as requested.

INVALID_MAXLINESIZE: Specified max_linesize is too large or too small.


注:使用UTL_FILE.FOPEN出现“ORA-29280: invalid directory path”错误时,有以下几种原因

a、 指定的路径参数不存在;

b、 直接指定路径名,但数据库初始化参数文件中参数UTL_FILE_DIR不包含该路径;

c、 利用CREATE DIRECTORY创建目录后,用目录指定路径,但是未给用户该目录的读写权限。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7988176/viewspace-969937/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 经典搭讪
下一篇: 一起来加班
请登录后发表评论 登录
全部评论
  • 博文量
    29
  • 访问量
    336418