Results 1 to 4 of 4
Hi all,
I need to know if it's possible to pass variables from a shell script to sqlplus.
The script reads a Table Name from user input & executes a ...
- 01-30-2009 #1Just Joined!
- Join Date
- Jan 2009
- Posts
- 2
Pass Variables from Shell to Sql
Hi all,
I need to know if it's possible to pass variables from a shell script to sqlplus.
The script reads a Table Name from user input & executes a Select statement based on
that input.
Script:
Inside script SELECT.SQL , i need to use the variable "answer" to run the query.Code:.... echo "Enter table name: \c " read answer sqlplus 'oracle/*** ' <<! spool columns.sql @select.sql spool off exit !
($answer doesn't do the job...
)
Any help would be highly appreciated.
Thanks in advance...
- 01-30-2009 #2Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
You are already using a here document to provide sql statements to the standard input of sqlplus. Instead of using "@select.sql" to include that file, you could include the statements it contains, and use variables in these statements, e.g.:
Code:echo "Enter table name: \c " read answer sqlplus 'oracle/*** ' <<END spool columns.sql select whatever from wherever where some_value=$answer spool off exit END
- 01-30-2009 #3Just Joined!
- Join Date
- Jan 2009
- Posts
- 2
- 01-30-2009 #4Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
Assuming that "select.sql" contains shell-variable references, like "$answer", for example, you could do something like this:
IMPORTANT NOTE: You must use the less-than operator rather than < But I was not able to enter that character in the edit field.Code:eval echo $(< select.sql ) | sqlplus 'oracle/*** '


Reply With Quote
