Copying a file on a local File System
This section includes an example which uses the Copy_file procedure in the Dbms_file_transfer to COPY a FILE on a l Ocal file System. The following example copies a binary file named Db1.dat from The/usr/admin/source directory to The/usr/admin/destinatio N Directory as Db1_copy.dat on a local file system:
In Sql*plus, connect as a administrative user who can grant privileges and create directory objects using SQL. (for example, SYS user)
Use the SQL command CREATE directory to 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 called Source_dir for The/usr/admin/source directory on your computer system, E Xecute the following statement:create DIRECTORY source_dir as '/usr/admin/source ';
Use the SQL command CREATE directory to create a directory object for the directory into which your want to copy the binary File. For example, to create a directory object called Dest_dir for the/usr/admin/destination directory on your computer system , execute the following statement:create DIRECTORY dest_dir as '/usr/admin/destination ';
Grant the required privileges to the user who would run the copy_file procedure. In this example, the Strmadmin user runs the procedure. GRANT EXECUTE on Dbms_file_transfer to Strmadmin; GRANT READ on DIRECTORY source_dir to Strmadmin; GRANT WRITE on DIRECTORY dest_dir to Strmadmin;
Connect as Strmadmin user:connect STRMADMIN/STRMADMINPW
Run the Copy_file procedure to COPY the File: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;/
Caution: Do isn't use the Dbms_file_transfer package to copy or TRANSFER a FILE this is being modified by a database because g so may, in a inconsistent file.