[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1384
  • Last Modified:

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.
0
IT_ETL
Asked:
IT_ETL
2 Solutions
 
Gerwin Jansen, EE MVETopic 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 RaySenior Technical Engineer Commented:
Check another good example on :

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

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now