Reputation: 97
Is there any way to pass a query to SQL*Plus through a variable?
I'm aware SQL*Plus has the capability to execute a file like:
sqlplus user/pass@db @filename
Within a kornshell script I'm trying to do:
query="select * from dual;"
sqlplus user/pass@db $query
Upvotes: 0
Views: 1648
Reputation: 3351
There might have solution to do that BUT I can achieve the same goal using the following method.
[oracle@myserver Desktop]$ $ORACLE_HOME/bin/sqlplus -s jay/passsword@db <<!
select * from dual;
exit
!
D
-
X
Update, you can store the returned result in a variable as shown below.
query="select * from dual;"
var=$($ORACLE_HOME/bin/sqlplus -s jay/pass@db <<!
set pages 0
set head off
set feed off
$query
!
);
Upvotes: 2