This section includes an example that uses the COPY_FILE procedure in the
DBMS_FILE_TRANSFER package to copy a file on a local file system. The following example copies a binary file named
db1.dat from the /usr/admin/source directory to the
/usr/admin/destination directory as db1_copy.dat on a local file system:
-
In SQL*Plus, connect as an administrative user who can grant privileges and create directory objects using SQL.(如sys用户)
-
Use the SQL command
CREATE DIRECTORY SOURCE_DIR AS '/usr/admin/source';CREATE DIRECTORYto create a directory object for the directory from which you want to copy the file. A directory object is similar to an alias for the directory. For example, to create a directory object calledSOURCE_DIRfor the/usr/admin/sourcedirectory on your computer system, execute the following statement: -
Use the SQL command
CREATE DIRECTORY DEST_DIR AS '/usr/admin/destination';CREATEDIRECTORYto create a directory object for the directory into which you want to copy the binary file. For example, to create a directory object calledDEST_DIRfor the/usr/admin/destinationdirectory on your computer system, execute the following statement: -
Grant the required privileges to the user who will run the
GRANT EXECUTE ON DBMS_FILE_TRANSFER TO strmadmin;GRANT READ ON DIRECTORY source_dir TO strmadmin;GRANT WRITE ON DIRECTORY dest_dir TO strmadmin;COPY_FILEprocedure. In this example, thestrmadminuser runs the procedure. -
Connect as
CONNECT strmadmin/strmadminpwstrmadminuser: -
Run the
BEGIN DBMS_FILE_TRANSFER.COPY_FILE( source_directory_object => 'SOURCE_DIR', source_file_name => 'db1.dat', destination_directory_object => 'DEST_DIR', destination_file_name => 'db1_copy.dat');END;/COPY_FILEprocedure to copy the file:
Caution:
Do not use the DBMS_FILE_TRANSFER package to copy or transfer a file that is being modified by a database because doing so may result in an inconsistent file.
1993



被折叠的 条评论
为什么被折叠?



