Copying files using the Dbms_file_transfer package

Source: Internet
Author: User
Tags create directory
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.