2026-03-12 21:01:38
This commit is contained in:
131
tiddlywiki/DBMS_FILE_TRANSFER examples.md
Executable file
131
tiddlywiki/DBMS_FILE_TRANSFER examples.md
Executable file
@@ -0,0 +1,131 @@
|
||||
On **target** database create a directory and an user for database link:
|
||||
```sql
|
||||
create directory DIR_DEST as '/mnt/yavin4/tmp/_oracle_/dir_dest';
|
||||
create user USER_DBLINK identified by *****;
|
||||
grant create session to USER_DBLINK;
|
||||
grant read,write on directory DIR_DEST to user_dblink;
|
||||
```
|
||||
|
||||
On **source** database create a directory and a database link:
|
||||
```sql
|
||||
create directory DIR_SOURCE as '/mnt/yavin4/tmp/_oracle_/dir_source';
|
||||
create database link REMOTE_DB connect to USER_DBLINK identified by ***** using 'taris/WEDGEPRD';
|
||||
select * from dual@REMOTE_DB;
|
||||
```
|
||||
|
||||
Use `DBMS_FILE_TRANSFER` from soure database to copy a single file from source directory to target directory:
|
||||
```sql
|
||||
BEGIN
|
||||
DBMS_FILE_TRANSFER.put_file(
|
||||
source_directory_object => 'DIR_SOURCE',
|
||||
source_file_name => 'Full_GREEDOPRD_01.dmp',
|
||||
destination_directory_object => 'DIR_DEST',
|
||||
destination_file_name => 'Full_GREEDOPRD_01.dmp',
|
||||
destination_database => 'REMOTE_DB');
|
||||
END;
|
||||
/
|
||||
```
|
||||
|
||||
`DBMS_FILE_TRANSFER` don't have a **parallel** option, but we can run parallel transfers using `DBMS_SCHEDULER` jobs:
|
||||
```sql
|
||||
create or replace procedure FILECOPY1 as
|
||||
BEGIN
|
||||
DBMS_FILE_TRANSFER.put_file(
|
||||
source_directory_object => 'DIR_SOURCE',
|
||||
source_file_name => 'Full_GREEDOPRD_01.dmp',
|
||||
destination_directory_object => 'DIR_DEST',
|
||||
destination_file_name => 'Full_GREEDOPRD_01.dmp',
|
||||
destination_database => 'REMOTE_DB');
|
||||
END;
|
||||
/
|
||||
|
||||
create or replace procedure FILECOPY2 as
|
||||
BEGIN
|
||||
DBMS_FILE_TRANSFER.put_file(
|
||||
source_directory_object => 'DIR_SOURCE',
|
||||
source_file_name => 'Full_GREEDOPRD_02.dmp',
|
||||
destination_directory_object => 'DIR_DEST',
|
||||
destination_file_name => 'Full_GREEDOPRD_02.dmp',
|
||||
destination_database => 'REMOTE_DB');
|
||||
END;
|
||||
/
|
||||
|
||||
create or replace procedure FILECOPY3 as
|
||||
BEGIN
|
||||
DBMS_FILE_TRANSFER.put_file(
|
||||
source_directory_object => 'DIR_SOURCE',
|
||||
source_file_name => 'Full_GREEDOPRD_03.dmp',
|
||||
destination_directory_object => 'DIR_DEST',
|
||||
destination_file_name => 'Full_GREEDOPRD_03.dmp',
|
||||
destination_database => 'REMOTE_DB');
|
||||
END;
|
||||
/
|
||||
|
||||
create or replace procedure FILECOPY4 as
|
||||
BEGIN
|
||||
DBMS_FILE_TRANSFER.put_file(
|
||||
source_directory_object => 'DIR_SOURCE',
|
||||
source_file_name => 'Full_GREEDOPRD_04.dmp',
|
||||
destination_directory_object => 'DIR_DEST',
|
||||
destination_file_name => 'Full_GREEDOPRD_04.dmp',
|
||||
destination_database => 'REMOTE_DB');
|
||||
END;
|
||||
/
|
||||
|
||||
begin
|
||||
DBMS_SCHEDULER.create_job
|
||||
(
|
||||
job_name => 'JOB_FILECOPY1',
|
||||
job_type => 'PLSQL_BLOCK',
|
||||
job_action => 'BEGIN FILECOPY1; END;',
|
||||
start_date => sysdate,
|
||||
enabled => TRUE,
|
||||
auto_drop => TRUE,
|
||||
comments => 'one-time job');
|
||||
end;
|
||||
/
|
||||
|
||||
begin
|
||||
DBMS_SCHEDULER.create_job
|
||||
(
|
||||
job_name => 'JOB_FILECOPY2',
|
||||
job_type => 'PLSQL_BLOCK',
|
||||
job_action => 'BEGIN FILECOPY2; END;',
|
||||
start_date => sysdate,
|
||||
enabled => TRUE,
|
||||
auto_drop => TRUE,
|
||||
comments => 'one-time job');
|
||||
end;
|
||||
/
|
||||
|
||||
begin
|
||||
DBMS_SCHEDULER.create_job
|
||||
(
|
||||
job_name => 'JOB_FILECOPY3',
|
||||
job_type => 'PLSQL_BLOCK',
|
||||
job_action => 'BEGIN FILECOPY3; END;',
|
||||
start_date => sysdate,
|
||||
enabled => TRUE,
|
||||
auto_drop => TRUE,
|
||||
comments => 'one-time job');
|
||||
end;
|
||||
/
|
||||
|
||||
begin
|
||||
DBMS_SCHEDULER.create_job
|
||||
(
|
||||
job_name => 'JOB_FILECOPY4',
|
||||
job_type => 'PLSQL_BLOCK',
|
||||
job_action => 'BEGIN FILECOPY4; END;',
|
||||
start_date => sysdate,
|
||||
enabled => TRUE,
|
||||
auto_drop => TRUE,
|
||||
comments => 'one-time job');
|
||||
end;
|
||||
/
|
||||
|
||||
drop procedure FILECOPY1;
|
||||
drop procedure FILECOPY2;
|
||||
drop procedure FILECOPY3;
|
||||
drop procedure FILECOPY4;
|
||||
```
|
||||
Reference in New Issue
Block a user