any possible solution on sql calling scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting any possible solution on sql calling scripts
# 1  
Old 11-21-2007
any possible solution on sql calling scripts

hi all,

i have a function which will take i/p as a ddl sctipt as i/p and execute it,
let
HTML Code:
function execute_sql
{
db_var="$1"
v_cnt=`sqlplus -s XXXXX/XXXXX@aXXX << ENDSQL | sed -e "s/Connected\.//" -e "/^$/d"
set pagesize 0 feedback off verify off heading off echo off  serveroutput on size 10000
whenever sqlerror exit SQL.SQLCODE;
$db_var
commit;
exit ;
ENDSQL`
db_var=""
}
if i am executing a wrong ddl script, then i am not able to catch the retrun code as 1 rather than it throws me 0 if i am executing the ddl thru the script function.

let my ddl which is wrong is ,
INSERT INTO CBF_CONFIG ( CS_ID, CS_NAME, FIELD_SEP, REC_SEP, FIELDS_NUM, FTPS_FILE, DECSN_FMT_TYPE, DECSN_FIELDS, DECSN_SCHDL_TYPE, DECSN_SCHDL, DECSN_TIME, DECSN_UNITWS, UNIQ_FILE_CONVNS, OUTBOX_RETN, UPDATE_TIME ) VALUES
('MANASMANAS1','SCORENETHERLANDS','|','NULL','15','N','STANDARD','NULL','DAILY','NULL','14:00','N',' Y','1',SYSDATE) ;
the o/p will as follows if i am executing it thru simple sqlplus environment,
('MANASMANAS1','SCORENETHERLANDS','|','NULL','15','N','STANDARD','NULL','DAILY','NULL','14:00','N',' Y','1',SYSDATE)
*
ERROR at line 2:
ORA-12899: value too large for column "XXXXX"."CBF_CONFIG"."CS_ID"
(actual: 11, maximum: 10)

but if i am going to call it thru the above shell functions,
HTML Code:
insert_sql="INSERT INTO CBF_CONFIG ( CS_ID, CS_NAME, FIELD_SEP, REC_SEP, FIELDS_NUM, FTPS_FILE, DECSN_FMT_TYPE, DECSN_FIELDS, DECSN_SCHDL_TYPE, DECSN_SCHDL, DECSN_TIME, DECSN_UNITWS, UNIQ_FILE_CONVNS, OUTBOX_RETN, UPDATE_TIME ) VALUES
('MANASMANAS1','SCORENETHERLANDS','|','NULL','15','N','STANDARD','NULL','DAILY','NULL','14:00','N','Y','1',SYSDATE) ; "
echo $insert_sql

execute_sql "$insert_sql"
rc=$?
echo "exit code $rc"
then rc is 0, but v_cnt is "ERROR at line 2:
ORA-12899: value too large for column "CLIFBACONFIG"."CBF_CONFIG"."CS_ID"
(actual: 11, maximum: 10)"

my question is why i am not able to catch SQL.SQLCODE even though in the function there is a line whenever sqlerror exit SQL.SQLCODE...
any suggestion to improve the error catching session...........

Last edited by manas_ranjan; 11-22-2007 at 05:06 AM.. Reason: remove login/pwd@dbname
# 2  
Old 11-21-2007
It's highly likely that you didn't search the forums for 'sqlplus' .

Whilst this may not answer all your questions, it might put you on the right path.

How to check sqlplus command is successfull or not in HP UX?

Trying to perform SQL in the way you've shown is really hard to manage over time.

In future, make use of the search feature in these forums.
You questions is more than likely to have been asked before in the past.

Cheers,
Cameron Smilie
# 3  
Old 11-22-2007
Hammer & Screwdriver

thankx Cameron.

I have gone thru the all the search...but not reffered anyone......as any of them not met my requirements
since i post it with confusing statements...sorry for that.

actually i should ask, even though whenever sqlerror exit SQL.SQLCODE is there why i am not able to catch that SQL.SQLCODE after executing the function ???? why rc is showing 0 as we all know i am executing wrong ddl(s) , why not SQL.SQLCODE as rc ????? i will be thankful if you can explain me....

NOTE : i have not used any spool file, o/p logging file..rather than i checked the ERROR/output by passing the o/p to v_cnt as follows,

HTML Code:
if [ `echo "$v_cnt" | grep "ORA-" | wc -l` -ne 0 ]
then
echo "`basename $0` wrong execution possible reason is :-`echo "$v_cnt" | grep "ORA-" | awk -F":" '{print $2}'`"
exit 1
fi
again sorry for misleading/confusing statements......next time i will try to take care of this.

Last edited by manas_ranjan; 11-22-2007 at 05:08 AM..
# 4  
Old 11-22-2007
problem with your sed

The problem is with your sed. It runs fine and thats why the return code is zero. Remove the sed and check your results.
# 5  
Old 11-22-2007
MySQL

you are absolutely right......after removing sed ...i got the exact answer as expected.

thanks a lot....ranj......Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX Solution - Calling SQL*Plus scripts

I have a requirement of bash shell script calling SQL*Plus script. Shell Script sqlplus <user>/<pwd> @sqlscript1 parameters sqlplus <user>/<pwd> @sqlscript2 parameters Now I need the values generated by sqlscript1 in sqlscript2. But it is more like a huge dataset in a table and not one... (7 Replies)
Discussion started by: uuuunnnn
7 Replies

2. Shell Programming and Scripting

Calling multiple scripts from another scripts

Dear all, I am working on script which call other shell scripts in a loop but problem is from second script am not able to come out. Here is the snippet:- #!/bin/bash HSFILE=/root/Test/Components.txt LOGFile=/opt/domain/AdminDomain/application/logs... (3 Replies)
Discussion started by: sharsour
3 Replies

3. UNIX for Advanced & Expert Users

Call parallel sql scripts from shell and return status when both sql are done

Hi Experts: I have a shell script that's kicked off by cron. Inside this shell script, I need to kick off two or more oracle sql scripts to process different groups of tables. And when both sql scripts are done, I will continue in the shell script to do other things like checking processing... (3 Replies)
Discussion started by: huasheng8
3 Replies

4. Shell Programming and Scripting

Execute multiple SQL scripts from single SQL Plus connection

Hi! I would like to do a single connection to sqlplus and execute some querys. Actually I do for every query one connection to database i.e echo 'select STATUS from v$instance; exit' > $SQL_FILE sqlplus user/pass@sid @$SQL_FILE > $SELECT_RESULT echo 'select VERSION from v$instance;... (6 Replies)
Discussion started by: guif
6 Replies

5. Shell Programming and Scripting

Calling scripts from other script.

I need to call 3 different shell scripts from 2 different scripts, one is a perl script and other is Shell script. In Case -1 : The perl script is myperlscript.pl and the name of three shell scripts which need to be called from the perl script are a1.sh, a2.sh and a3.sh. Each shell script... (1 Reply)
Discussion started by: siba.s.nayak
1 Replies

6. Shell Programming and Scripting

Calling scripts within script

Hi, I have written a some six scripts to move large files and re-size them. This has been done step by step, taking backup, creating the new files, merging the files, removing the temporary files created. Since these files are around 500 MB, each step takes somewhere between 1 to 5 mins. ... (1 Reply)
Discussion started by: baanprog
1 Replies

7. Shell Programming and Scripting

Difference between calling the sub scripts

What is the difference between calling the sub scripts of below two line. /home/scripts/devdb.sh . /home/scripts/devdb.sh sh /home/scripts/devdb.sh We are using the suse 2.0 version (4 Replies)
Discussion started by: kingganesh04
4 Replies

8. Shell Programming and Scripting

calling .sql in .sh file

Hi All , I have created .sql script in unix.this script contains 4 sql queries. Now I want to craete .sh file based on .sql script. So please let me know the steps to craete .sh file Thank you. (1 Reply)
Discussion started by: user71408
1 Replies

9. Shell Programming and Scripting

Calling SQL LDR and SQL plus scripts in a shell script

Hi- I am trying to achieve the following in a script so I can schedule it on a cron job. I am fairly new to the unix environment... I have written a shell script that reads a flat file and loads the data into an Oracle table (Table1) via SQLLDR. This Works fine. Then, I run a nested insert... (5 Replies)
Discussion started by: rajagavini
5 Replies

10. Shell Programming and Scripting

Calling SQL scripts through Shell Script

Oracle and Scripting gurus, I need some help with this script... I am trying to add the query SELECT * FROM ALL_SYNONYMS WHERE SYNONYM_NAME = 'METADATA' in the current script.... Read the result set and look for the TABLE_NAME field. If the field is pointing to one table eg.... (18 Replies)
Discussion started by: madhunk
18 Replies
Login or Register to Ask a Question