| File and operating system interaction with SQL and PLSQL | |||||
SUMMARY: FIELD | TYPE | METHOD | DETAIL: FIELD | TYPE | METHOD |
file_path | VARCHAR2(4000) | The full path to the file |
file_name | VARCHAR2(4000) | The simple name of the file |
file_size | NUMBER | The size of the file in bytes |
is_dir | CHAR(1) | 'Y' when the file is a directory, 'N' otherwise |
is_writeable | CHAR(1) | 'Y' when the file is writeable, 'N' otherwise |
is_readable | CHAR(1) | 'Y' when the file is readable, 'N' otherwise |
file_exists | CHAR(1) | 'Y' when the handle points a an existing file; 'N' otherwise |
SQL> select file_pkg.get_file('/tmp') from dual;Example II: Obtaining a file handle for the (nonexisting) /tmp1 directory (see documentation for FILE_PKG)
FILE_PKG.GET_FILE('/TMP')(FILE_PATH, FILE_NAME, FILE_SIZE, LAST_MODIFIED, IS_DIR -------------------------------------------------------------------------------- FILE_TYPE('/tmp', 'tmp', 77824, '26.03.08', 'Y', 'Y', 'Y', 'Y')
SQL> select file_pkg.get_file('/tmp1') from dual;
FILE_PKG.GET_FILE('/TMP1')(FILE_PATH, FILE_NAME, FILE_SIZE, LAST_MODIFIED, IS_DI -------------------------------------------------------------------------------- FILE_TYPE('/tmp1', NULL, NULL, NULL, NULL, NULL, NULL, 'N')
beginTo grant read and write access to the whole file system, issue ...
dbms_java.grant_permission(
grantee => 'SCOTT',
permission_type => 'SYS:java.io.FilePermission',
permission_name => '/tmp/*',
permission_action => 'read'
);
end;
begin
dbms_java.grant_permission(
grantee => 'SCOTT',
permission_type => 'SYS:java.io.FilePermission',
permission_name => '/-',
permission_action => 'read,write'
);
end;
Field Summary | |
char(1) | file_exists
Flag whether this file exists - if a file does not exist, all attributes except this and the full pathname are set to SQL NULL. |
varchar2(4000) | file_name
Filename |
varchar2(4000) | file_path
Full absolute path to this file |
number | file_size
File size in bytes |
char(1) | is_dir
Flag whether this file is a directory ("Y"); "N" otherwise |
char(1) | is_readable
Flag whether this file is readable |
char(1) | is_writeable
Flag whether this file is writeable |
date | last_modified
LastModified date of this file |
Method Summary | |
number | append_to_file(p_content clob)
appends to a file |
number | append_to_file(p_content blob)
appends to a file |
number | append_to_file(p_content varchar2)
appends to a file |
| close_stream()
Closes the "Input Stream". |
file_type | copy(p_target_file file_type)
copies the file. |
FILE_TYPE | create_dir(p_dirname varchar2)
Creates a new empty directory. |
file_type | create_file(p_filename varchar2)
Creates a new empty file. |
file_type | delete_file()
deletes the file or directory. |
file_type | delete_recursive()
deletes the file or directory. |
bfile | get_bfile(p_directory_name varchar2)
returns a BFILE object, which represents this file handle. |
blob | get_content_as_blob()
Returns the file contents as a BLOB. |
clob | get_content_as_clob(p_charset varchar2)
Returns the file contents as a CLOB. |
varchar2 | get_directory()
Looks up a directory object which represents either, if the file handle is a directory, the handle itself, or the folder in which the file handle resides in. |
file_type | get_file(p_file_path varchar2)
gets a simple file handle. |
number | get_free_space()
returns the space (in bytes), which is available on the device containing this file handle. |
file_type | get_parent()
Returns the parent directory |
number | is_stream_open()
Checks whether an Input Stream is open on the file. |
file_type | make_all_dirs()
Creates a new empty directory similar to MAKE_DIR. |
FILE_TYPE | make_dir()
Creates a new empty directory. |
FILE_TYPE | make_file()
Creates a new empty file. |
file_type | move(p_target_file file_type)
performs a "move" / "rename" operation |
| open_stream()
Opens an "Input Stream" on the file. |
number | read_byte()
Reads a single byte from the file input stream. |
raw | read_bytes(p_amount number)
Reads the given amount of bytes from the file input stream. |
raw | read_bytes(p_amount number, p_position number)
reads the specified amount of bytes at the specified position from the file. |
varchar2 | read_string(p_amount number, p_charset varchar2)
Reads the given amount of characters from the file input stream |
varchar2 | read_string(p_amount number, p_position number, p_charset varchar2)
reads the specified amount of bytes at the specified position from the file and returns them as a string. |
| skip_bytes(p_amount number)
Skips the given amount of bytes in the file input stream i.e. moves the "pointer" the given amount of bytes forward. |
number | write_bytes(p_bytes raw, p_offset number)
writes bytes at the specified position to the file. |
number | write_string(p_string varchar2, p_offset number, p_charset varchar2)
writes a string at the specified position to the file. |
number | write_to_file(p_content clob)
writes to a file - existing file content is being overwritten |
number | write_to_file(p_content blob)
writes to a file - existing file content is being overwritten |
Field Detail |
public varchar2(4000) file_path
public varchar2(4000) file_name
public number file_size
public date last_modified
public char(1) is_dir
public char(1) is_writeable
public char(1) is_readable
public char(1) file_exists
Method Detail |
public file_type move(p_target_file file_type)
p_target_file
-
FILE_TYPE object denoting the new file name and path.public file_type delete_file()
SQL> select file_pkg.get_file('/home/oracle/old_file.txt') file_exists from dual; FILE_EXISTS ----------------------------------------------------------------------------------------- FILE_TYPE('/home/oracle/old_file.txt', 'old_file.txt', 0, '03.02.10', 'N', 'Y', 'Y', 'Y') SQL> select file_pkg.get_file('/home/oracle/old_file.txt').delete_file() file_not_exists from duaL; FILE_NOT_EXISTS -------------------------------------------------------------------------------- FILE_TYPE('/home/oracle/old_file.txt', NULL, NULL, NULL, NULL, NULL, NULL, 'N')
public file_type delete_recursive()
public FILE_TYPE make_file()
SQL> select file_pkg.get_file('/home/oracle/new_file.txt') file_not_exists from duaL; FILE_NOT_EXISTS -------------------------------------------------------------------------------- FILE_TYPE('/home/oracle/new_file.txt', NULL, NULL, NULL, NULL, NULL, NULL, 'N') SQL> select file_pkg.get_file('/home/oracle/new_file.txt').make_file() file_exists from dual; FILE_EXISTS ----------------------------------------------------------------------------------------- FILE_TYPE('/home/oracle/new_file.txt', 'new_file.txt', 0, '03.02.10', 'N', 'Y', 'Y', 'Y')
public FILE_TYPE make_dir()
public FILE_TYPE create_dir(p_dirname varchar2)
p_dirname
-
absolute path to the new directorypublic file_type create_file(p_filename varchar2)
p_filename
-
absolute path to the new filepublic file_type copy(p_target_file file_type)
p_target_file
-
FILE_TYPE object pointing to the target file and path.public file_type make_all_dirs()
public clob get_content_as_clob(p_charset varchar2)
p_charset
-
encoding of the file contents in IANA notation (e.g. "iso-8859-1")public number write_to_file(p_content clob)
p_content
-
CLOB content to be written to the file.public number append_to_file(p_content clob)
p_content
-
CLOB content to be appended to the file.public number write_to_file(p_content blob)
p_content
-
BLOB content to be written to the file.public number append_to_file(p_content blob)
p_content
-
BLOB content to be appended to the file.public number append_to_file(p_content varchar2)
p_content
-
VARCHAR2 content to be appended to the file.public blob get_content_as_blob()
public file_type get_parent()
public open_stream()
public close_stream()
public number is_stream_open()
public raw read_bytes(p_amount number)
p_amount
-
amount of bytes to read from the stream. Values between 1 and 32767 are allowed.public varchar2 read_string(p_amount number,
p_charset varchar2)
p_amount
-
amount of bytes to read from the stream. Values between 1 and 32767 are allowed.p_charset
-
encoding of the file contents in IANA notation (e.g. "iso-8859-1")public number read_byte()
public skip_bytes(p_amount number)
p_amount
-
amount of bytes to skippublic number write_bytes(p_bytes raw,
p_offset number)
p_bytes
-
bytes to write to the filepublic number write_string(p_string varchar2,
p_offset number,
p_charset varchar2)
p_string
-
bytes to write to the filep_charset
-
encoding of the stringpublic raw read_bytes(p_amount number,
p_position number)
p_amount
-
amount of bytes to readp_position
-
position in the filepublic varchar2 read_string(p_amount number,
p_position number,
p_charset varchar2)
p_amount
-
amount of bytes to readp_position
-
position in the filep_charset
-
encoding of the stringpublic file_type get_file(p_file_path varchar2)
SQL> select file_pkg.get_file('/home/oracle/nonexisting_file.txt') file_handle from duaL; FILE_HANDLE ---------------------------------------------------------------------------------------------- FILE_TYPE('/home/oracle/nonexisting_file.txt', NULL, NULL, NULL, NULL, NULL, NULL, 'N') SQL> select file_pkg.get_file('/home/oracle/existing_file.txt') file_handle from dual; FILE_EXISTS --------------------------------------------------------------------------------------------------- FILE_TYPE('/home/oracle/existing_file.txt', 'existing_file.txt', 0, '03.02.10', 'N', 'Y', 'Y', 'Y')
p_file_path
-
the absolute path to the filepublic bfile get_bfile(p_directory_name varchar2)
SQL> select file_pkg.get_file('/home/oracle/exttab-files/test.txt').get_bfile() from dual; FILE_PKG.GET_FILE('/HOME/ORACLE/EXTTAB-FILES/TEST.TXT').GET_BFILE() -------------------------------------------------------------------------------- bfilename('DIR_EXTTAB_FILES', 'test.txt') SQL> select file_pkg.get_file('/home/oracle/exttab-files/test.txt').get_bfile('OTHER_DIR') from dual; FILE_PKG.GET_FILE('/HOME/ORACLE/EXTTAB-FILES/TEST.TXT').GET_BFILE('OTHER_DIR') -------------------------------------------------------------------------------- bfilename('OTHER_DIR', 'test.txt') 1 Zeile wurde ausgewählt. SQL> select file_pkg.get_file('/home/oracle/exttab-files/subdir').get_bfile('OTHER_DIR') from dual; select file_pkg.get_file('/home/oracle/exttab-files/subdir').get_bfile() from dual ERROR at line 1: ORA-20000: CANNOT CONVERT DIRECTORY INTO BFILE ORA-06512: at "SYS.FILE_TYPE", line 9 ORA-06512: at line 1
p_directory_name
-
Name of a directory object to create the BFILE - if given, the function will not try to find one.public varchar2 get_directory()
public number get_free_space()
| File and operating system interaction with SQL and PLSQL | |||||
SUMMARY: FIELD | TYPE | METHOD | DETAIL: FIELD | TYPE | METHOD |