Bash executing Orcale Update statement


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Bash executing Orcale Update statement
# 1  
Old 06-25-2009
Bash executing Orcale Update statement

Hi All,

Using Solaris box
bash-3.00$ echo $BASH_VERSION
3.00.16(1)-release


I have a real bummer of a bug, basically Im running a bash script that executes a bash function "dbase_sql". The bash function accepts a parameter in the form of an Oracle update statement eg



dbase_sql "update dte_batch_details
set row_count='$row_count'
, checksum_value='$checksum_value'
, load_attempts=NVL(load_attempts,0)+1
, pre_stage_errors='$pre_stage_errors'
, message='$sql_err_msg'
where object_name='$source_tabin_name'"





The function itself is as below

dbase_sql()
{

echo "dbase_sql() 1.1 "
local sql="$1"
echo "sql="$sql
echo "showed ECHO!"
sqlplus -s $DBUSER/$DBPASS@$DBNAME<<EOF

set serveroutput on size 1000000
set verify off
set feedback off

VARIABLE vi_err NUMBER

declare

begin
${sql};
commit;
:vi_err:=0;

exception
when others
then
:vi_err:=1;
end;
/
EXIT:vi_err
EOF
}



The perplexing thing is that I cannot get the call to the function to work in my main shell script, so I created a simple script that calls the function and that does seem to work! For some reason, the bug is that the echo does not show the full statement in the function and hence it passes the malformed statement to the oracle call which then fails.

Error from the shell is as follows:

dbase_sql() 1.1
' , load_attempts=NVL(load_attempts,0)+1 , pre_stage_errors='Y' , message='/#SQL Loader Bad File[/export/home/ORACLE/product/10.2.0/TORPEDO/LOGS/SQLLDR_bad_TOS_TABIN218.bad]' where object_name='TOS_TABIN218'
showed ECHO!
Thursday, 25 June 2009 14:06:43 BST #Application Error - Abort: Call to dbase_func.dbase_sql()


The working version shows:

dbase_sql() 1.1
sql=update dte_batch_details set row_count='1' , checksum_value='1' , load_attempts=NVL(load_attempts,0)+1 , pre_stage_errors='Y' , message='None/#SQL Loader Bad File[]/#SQL Loader Bad File[]/#SQL Loader Bad File[]/#SQL Loader Bad File[]/#SQL Loader Bad File[]/#SQL Loader Bad File[]/#SQL Loader Bad File[]/#SQL Loader Bad File[]' where object_name='TOS_TABIN218'
showed ECHO!


Any ideas?!
Kind Regards
Satnam
# 2  
Old 07-06-2009
Is there any difference between the echo syntax in your longer and the working shorter script? Basically you have problems with single and/or double quotation marks it seems. Maybe try playing around by escaping them with a backslash until you get the desired output.
Another way might be putting the statement to a plain file and then hand it over as a parameter to your script to have less hassle.
Also use CODE-tags when posting code, data or logs in future please.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to keep staying on remote server after executing a shell script with if then exit end statement?

i have a "if .. then exit end " in s shell script on remote servers. now the connection to the remote server got killed after i run this script on the remote servers. How do i run this script on remote hosts and still keep remote connections alive after executing the script. Thank you. (10 Replies)
Discussion started by: moonmonk
10 Replies

2. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

3. Shell Programming and Scripting

Storing passing and executing select statement in loop

Hi, i want to do the following: Grep the following kind of strings for the 15digit ID which is stored in filename1: "14:06:51.396 INFO BMCREMEDYSD INPUT-ACTION Failed to retrieve Remedy Incident Modification record: 000000000039047 org.apache.axis2.AxisFault: Read timed out - complete... (9 Replies)
Discussion started by: Khushbu
9 Replies

4. Red Hat

RedHat 5 update 9 BASH update issue

Hi i want to update the BASH because of the "shell shock" vulnerability. my RedHat 5 is clean install with the default mirror site. when im running the command: yum update bash im getting a message saying there is no update. you can see in the attach picture... what am i doing wrong? is... (4 Replies)
Discussion started by: guy3145
4 Replies

5. Homework & Coursework Questions

Problem with executing a possible if or case statement script

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Create a phonebook program. It should use functions to perform the required tasks. It should be menu-based,... (1 Reply)
Discussion started by: Rgasin02
1 Replies

6. Shell Programming and Scripting

Executing sql statement from .sh file

Hi, How to execute sql statements from the .sh file ?? Means, when we run .sh file then the sql statements within it should be get executed one by one from the sqlplus With Regards (3 Replies)
Discussion started by: milink
3 Replies

7. Programming

UPDATE statement: calculating changes

The problem I was working on is solved, but felt it would be worthwhile to ask for some opinions as to whether the approach can actually be improved. I am using the following example and data taken from https://www.unix.com/high-level-programming/119134-sql-datetime-calculations.html and MySQL... (0 Replies)
Discussion started by: figaro
0 Replies

8. Shell Programming and Scripting

executing mysql load statement from shell script

Hi, I have a piece of shell script which will connect to mysql database and execute a load statement(which will load datas in a file to the database table).The code is working and the data is in the tables. Now my requirement is, i need to grab the output from the load statement... (4 Replies)
Discussion started by: DILEEP410
4 Replies

9. Shell Programming and Scripting

Executing a Oracle SQL statement in a UNIX script

Hi All, I need to select one column from a table based upon the passed in parameter. I tried this: sqlplus -silent $MISP_USER << EOF set feedback off; set verify off; set sqlprompt "" SELECT mail_flag FROM dailyjobs WHERE job_name = '$1'; exit 0 EOF exit... (1 Reply)
Discussion started by: ganga.dharan
1 Replies

10. UNIX for Dummies Questions & Answers

installing Orcale 8i on unix

Dear Sir, I am working in a bank and our parent bank has developed an application package which will work with oracle 8i on unix platform. The unix on the server is unix ware 7.1.1 with pro*c compiler. My question is 1. Whether Oracle 8i or above for windows will work on any unix version... (1 Reply)
Discussion started by: Parameswaran.AR
1 Replies
Login or Register to Ask a Question