Quantcast
Channel: Question and Answer » oracle
Viewing all articles
Browse latest Browse all 717

execute .sql script inside an anonymous pl/sql block which is invoked by a shell script

$
0
0

I got a shell script which connects to SQLPLUS and executes the .sql file like below:

 read a
 x=`echo $a | cut -d , -f 1`
 y=`echo $a | sed 's/.*,//'`
 c=`echo $USER | cut -c -2`"OPR"`echo $USER | cut -c 6-`
 sqlplus -s `echo $c`/`echo $c`@$OPERATIONAL_DB_NAME @dbl.sql $x $y

Below is the SQL (dbl.sql)

SET SERVEROUTPUT ON
DECLARE
x varchar2(100):='&&1';
y varchar2(100):='&&2';
BEGIN
execute immediate 'CREATE DATABASE LINK  SSS_DBL CONNECT TO ' || x || ' IDENTIFIED BY ' || x || ' USING ''' || y || '''';
@1_a.sql
@1_b.sql
@1_c.sql
END;
/
EXIT;

In the above sql, 1_a.sql,1_b.sql,1_c.sql are three sql files in which there are a set of insert statements, taking the data from a remote db, using the link created
above.

Now, I can not run these sql’s inside the pl/sql block using @ symbol as written above. What is the other way to do this? If I use 3 procedures for each insert files, then, should
these procedures be run and compiled before using in this pl/sql, in each session or how should I use these?
I want to keep this script as independent of any session or db.


Viewing all articles
Browse latest Browse all 717