Using Shell Variables in SQLPLUS
I am trying to find a way to use a variable in my shell (Korn) in a simple select statement in sqlplus.
$ sqlplus '/ as sysdba'
SQL> select name from v$archived_log
2> where seqeunce# = $SHELLVAR
This is basically what I want to do. In the way is it written here, I get an error from SQLPLUS.
Is there any way to use the value of shell variable in sqlplus?
I think I found my answer ....
I should use positional parameters! As in:
sqlplus '/ as sysdba' @myscript.sql $SHELLVAR
And myscript.sql would like this:
select name from v$archived_log
where sequence# = &1
$ export SHELLVAR=222
$ sqlplus /@yourdb <
select * from xyz where id = $SHELLVAR;
Click Here to Expand Forum to Full Width