Oracle DBMS_FILE_TRANSFER
Version 11.2.0.3
 
General Information
Note: Provides procedures to copy a binary file within a database or to transfer a binary file between databases. File sizes must be a multiple of 512K..
Source {ORACLE_HOME}/rdbms/admin/dbmsxfr.sql
First Available 10.1
Constants package_flag BINARY_INTEGER;
Dependencies
DBMS_FILE_TRANSFER_LIB DBMS_SYS_ERROR
DBMS_SNAP_INTERNAL DBMS_UTILITY
DBMS_STREAMS_TABLESPACE_ADM GLOBAL_NAME
DBMS_STREAMS_TBS_INT  
Error Messages invalid_parameter EXCEPTION;
PRAGMA exception_init(invalid_parameter, -31600);
invalid_parameter_num NUMBER := -31600;
Security Model Owned by SYS with no privileges granted
Subprograms
 
COPY_FILE
Reads a local file and creates a copy of it in the local file system dbms_file_transfer.copy_file(
source_directory_object      VARCHAR2,
source_file_name             VARCHAR2,
destination_directory_object VARCHAR2,
destination_file_name        VARCHAR2);
conn / as sysdba

CREATE OR REPLACE DIRECTORY SOURCE_DIR AS 'c:\temp\source';

CREATE OR REPLACE DIRECTORY DEST_DIR AS 'c:\temp\dest';

CREATE TABLESPACE filetxfr LOGGING
DATAFILE 'c:\temp\source\filetxfr1.dbf' SIZE 5120K
BLOCKSIZE 8192
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M
SEGMENT SPACE MANAGEMENT AUTO;

ALTER TABLESPACE filetxfr READ ONLY;

BEGIN
  dbms_file_transfer.copy_file(source_directory_object =>
  'SOURCE_DIR', source_file_name => 'filetxfr1.dbf',
  destination_directory_object => 'DEST_DIR',
  destination_file_name => 'filetxfr1.dbf');
END;
/

ALTER TABLESPACE filetxfr READ WRITE;

SELECT tablespace_name, file_name
FROM dba_data_files;

DROP TABLESPACE filetxfr INCLUDING CONTENTS AND DATAFILES;
 
GET_FILE
Contacts a remote database to read a remote file and then creates a copy of the file in the local file system dbms_file_transfer.get_file(
source_directory_object      VARCHAR2,
source_file_name             VARCHAR2,
source_database              VARCHAR2,
destination_directory_object VARCHAR2,
destination_file_name        VARCHAR2);
-- login to the local machine
conn / as sysdba

CREATE TABLESPACE filetxfr LOGGING
DATAFILE 'c:\temp\source\filetxfr1.dbf' SIZE 5120K
BLOCKSIZE 8192
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M
SEGMENT SPACE MANAGEMENT AUTO;

-- create database link
CREATE DATABASE LINK remote
CONNECT TO system
IDENTIFIED BY password USING 'REMOTE';

-- add to tnsnames.ora

-- create directory
CREATE OR REPLACE DIRECTORY remote_dir AS 'c:\temp\remote';

-- Login to the remote server
conn system/password@remote

-- Create the source directory object and switch tablespace mode
CREATE OR REPLACE DIRECTORY remote_dir AS 'c:\temp\remote';

ALTER TABLESPACE filetxfr READ ONLY;

-- login to the local server
conn system/password

-- Create the destination directory object and a database link
CREATE OR REPLACE DIRECTORY db_files_dir2 AS '/u02/oradata/DB10G/';

-- get the file
BEGIN
  DBMS_FILE_TRANSFER.GET_FILE(source_directory_object =>
  'DB_FILES_DIR1', source_file_name => 'USERS01.DBF',
  source_database => 'REMOTE', destination_directory_object =>
  'DB_FILES_DIR2', destination_file_name => 'USERS01.DBF');
END;
/

-- Login to the remote server
CONN system/password@remote

-- switch the tablespace back to read write mode
ALTER TABLESPACE users READ WRITE;
 
PUT_FILE
Reads a local file and contacts a remote database to create a copy of the file in the remote file system dbms_file_transfer.put_file(
source_directory_object      VARCHAR2,
source_file_name             VARCHAR2,
destination_directory_object VARCHAR2,
destination_file_name        VARCHAR2,
destination_database         VARCHAR2);
-- Login to the remote server
conn system/password@remote

-- Create the destination directory object
CREATE OR REPLACE DIRECTORY db_files_dir2 AS '/u02/oradata/DB10G/';

-- Login to the local server.
CONN system/password@local

-- Create the source directory object, database
-- link and switch tablespace mode

CREATE OR REPLACE DIRECTORY db_files_dir1 AS '/u01/oradata/DB10G/';
CREATE DATABASE LINK remote CONNECT TO system IDENTIFIED BY password USING 'REMOTE';

ALTER TABLESPACE users READ ONLY;

-- Put the file
BEGIN
  DBMS_FILE_TRANSFER.PUT_FILE(source_directory_object =>
 'DB_FILES_DIR1', source_file_name =>  'USERS01.DBF',
  destination_directory_object => 'DB_FILES_DIR2',
  destination_file_name => 'USERS01.DBF',
  destination_database => 'REMOTE');
END;
/

-- Switch the tablespace back to read write mode
ALTER TABLESPACE users READ WRITE;
 
 
Morgan's Library Page Footer
This site is maintained by Dan Morgan. Last Updated: This site is protected by copyright and trademark laws under U.S. and International law. © 1998-2013 Daniel A. Morgan All Rights Reserved