I have a small PL/SQL script that I'm using to try and copy data between two Oracle database instances.
I'm calling the SQL script with (sanitised):
sqlplus username/password@server.com:1434/SERVICENAME @copyTables.sql source_username source_password source_connstring destination_username destination_password destination_connstring
The copyTables.sql script:
SET SERVEROUTPUT ON;
DECLARE
source_username VARCHAR2(20) := &1
source_password VARCHAR2(20) := &2
source_connstring VARCHAR2(2) := &3
destination_username VARCHAR2(20) := &4
destination_password VARCHAR2(20) := &5
destination_connstring VARCHAR(20) := &6
CURSOR user_table_cur IS
SELECT table_name
FROM user_tables
ORDER BY table_name DESC;
BEGIN
FOR user_table IN user_table_cur LOOP
dbms_output.put_line(source_username);
dbms_output.put_line(user_table.table_name);
COPY FROM {source_username}/{source_password}@{source_connstring} TO {destination_username}/{destination_password}@{destination_connstring} APPEND user_table.table_name user_table.table_name USING SELECT* FROM user_table.table_name;
END LOOP;
END;
The only issue is that when I run this, it seems to misinterpret a colon (:) in the connection string for something to do with bind variables:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
old 2: source_username VARCHAR2(20) := &1
new 2: source_username VARCHAR2(20) := SANITISED
old 3: source_password VARCHAR2(20) := &2
new 3: source_password VARCHAR2(20) := SANITISED
old 4: source_connstring VARCHAR2(2) := &3
new 4: source_connstring VARCHAR2(2) := server.com:3630/SANITISED
old 5: destination_username VARCHAR2(20) := &4
new 5: destination_username VARCHAR2(20) := SANITISED
old 6: destination_password VARCHAR2(20) := &5
new 6: destination_password VARCHAR2(20) := SANITISED
old 7: destination_connstring VARCHAR(20) := &6
new 7: destination_connstring VARCHAR(20) := server.com:3630/SANITISED
SP2-0552: Bind variable "3630" not declared.
SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
I've already escape the above with braces ({}), but it still seems to complain about bind variables.
Also - as a addendum - the way I'm doing above, is this the best practice in passing command-line arguments through to a PL/SQL script? I'm open to suggestions on better methods of doing this.
Cheers, Victor