Inside script I have SQL queries which I execute. But I would like to do a variable which indicates what exact SQL script I want to run. For example:
#!/bin/bash
SQL1 = "Select * from dual"
SQL1 = "Select sysdate from dual"
SQL3 = "Select sysdate+1 from dual"
Now, I would like to run a script eg. ./script.sh 2
- > which indicates that I want to run second SQL query.
Probably the easiest way is to do it this way:
if [ $1 = 1 ] then
SQL1 = "Select * from dual"
if [ $1 = 2] then
SQL2 = "Select sysdate from dual"
if [ $1 = 3] then
SQL3 = "Select sysdate+1 from dual"
fi fi fi
Now, the question is, what if I want to run all of them, so I will run my script: ./script.sh
(without variable).
I know I cant use [-z] but, I don't want to repeat SQL queries eg.
if [ $1 = 1 ] then
SQL1 = "Select * from dual"
if [ $1 = 2] then
SQL2 = "Select sysdate from dual"
if [ $1 = 3] then
SQL3 = "Select sysdate+1 from dual"
fi fi fi
if [ -z $1 ] then
SQL1 = "Select * from dual"
and so on... How to handle with that ?