How to pass a shell variables to sql or pl/sql block?

In a shell script, I like to pass a shell variable (date parameter) to a sql block that will be used to update a table in a database. Please advise how I can pass a shell variable to a sql block.
IT_ETLAsked:
Who is Participating?
 
Gerwin Jansen, EE MVEConnect With a Mentor Topic Advisor Commented:
Hi IT_ETL, you can use variables, like this:

#!/bin/sh
user="system"
pass="manager"
var="$1"
sqlplus -S ${user}/${pass} <<EOF
 SELECT * FROM tableName WHERE username=${var};
 exit;
EOF

Open in new window

The <<EOF construction is know as a 'here' document.

You can substitute your date variable (passed as a string I presume) with a to_date function.
0
 
Swadhin RayConnect With a Mentor Senior Technical Engineer Commented:
Check another good example on :

http://www.orafaq.com/forum/t/36769/0/

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.