not able to call insert,update and delete in shell script

February 20, 2012 at 22:33:42
Specs: HP unix
I have a four sql files like insert.sql,delete.sql,update.sql and select.sql,when i am giving a option like 1,2,3,4 based on my option whatever the operation i want to run i am able to run but now i want to place all the sql files within shell script and i want that my script will call the sql file from within shell script so that there is no need to maintain and place the sql files outside the shell script.Below is the example how i am doing right now:-

Enter your option:
read choice
case "$choice" in

1) sqlplus -s username/password@insert.sql (likewise for update,delete and select)

and in insert.sql my insert query is place but now i want to put that insert query in shell script.

Please help....

See More: not able to call insert,update and delete in shell script

February 27, 2012 at 05:42:58
The best way to execute this would be to place the query inside a function, and call the function whenever the corresponding option is selected.

I'd suggest that you place all the code in your insert.sql file into a function called insert, the code of delete.sql into a fucntion called delete and so on.

Use a case statement to call the corresponding function based on the user's input.

Your code can be something like this


function insertsql
# query to insert

function updatesql
# query to update

function deletesql
# query to delete

function selectsql
# query to select

echo -e "\nEnter the option : "
echo -e "1. Insert \n 2. Update \n 3. Delete \n 4. Select
read opt

case $opt in

insertsql # calling insert fucntion

updatesql # calling update fucntion

deletesql # calling delete fucntion

selectsql # calling select fucntion

echo "Invalid option"


Report •
Related Solutions

Ask Question