Any clues on this please
trveor welch, May 28, 2003 - 8:33 am UTC
Tom
A very simple SQL script called from a shell script
which checks the return status.
Trouble is IF NO ROWS FOUND occurs it errors of course
but in my case I can live with that
Any ideas of another approach??
Regards
Trevor
WHENEVER SQLERROR EXIT 255
SPOOL &1
UPDATE F1 SET grp_name = '$UNKNOWN'
WHERE substr(grp_name,1,1) <> '$';
SPOOL OFF
EXIT
May 28, 2003 - 6:35 pm UTC
why does it error? it is never an error to update zero rows.
there will never never ever be "no rows found" thrown by an update (unless a trigger or some side effect throws it).
update t set x = 5 where 1=0;
that will be successful (assuming t exists and all...)
My mistake
A reader, May 28, 2003 - 7:10 pm UTC
Tom,
Thanks for your reply
I'll look at it furthe and let you know
Regards
Trevor
SP2 errors
SC, December 23, 2004 - 3:17 am UTC
Hi Tom.
1.Is there any way to catch SP2 errors the same way sql/os errors are captured?
2. In SQL PLUS guide page 13-154 - is commit going to happen (underlined) after exit when "whenever sqlerror" by default?
Thanks.
December 23, 2004 - 11:22 am UTC
you have whenever and that is about it.
Control propagation in Pro* C
Kuldeep, August 18, 2005 - 6:15 am UTC
Dear Tom,
I have this piece of Pro* C code
void error_handler();
main() {
/* . . . */
EXEC SQL WHENEVER SQLERROR DO error_handler();
/* Query 1 */
EXEC SQL SELECT . . .;
/* Query 2 */
EXEC SQL SELECT . . .;
EXEC SQL WHENEVER SQLERROR GOTO error_label;
/* Query 3 */
EXEC SQL SELECT . . .;
/* Query 4 */
EXEC SQL SELECT . . .;
return;
error_label:
printf(Error Label);
}
void error_handler() {
printf(Error occurred);
return;
}
Sir, here I know if my third query is causing some error my fourth query is not going to be run, because control is skipping that statement and directly jumping to the error_label. But I have some confusion. If my first query is causing some error and the error handler function is going to be invoked then what after that. Where would be the control be. Will it run my second query and other statements after the first query.
Please give some more information on this topic.
Thanks and regards
August 18, 2005 - 4:02 pm UTC
control returns to the place the function error_handler() was called from
(hint: read the generated C code, you'll see that error_handler is just a function call, control returns right there)
unless error_handler does a longjump or exit or something like that, control will return right there.
WHENEVER SQLERROR
Hans, December 29, 2005 - 5:02 pm UTC
I have a table say test(id number(5), col1 varchar2(10), col2 varchar2(10))
I have a sql file with following
WHENEVER SQLERROR EXIT 99
update test
set col1 = 'A'
where id = 1;
update test
set col2 = 'B'
where i = 2 ; ---- DELIBERATELY making a wrong column
name
EXIT
The above .sql file is called from shell script
When I run the above script the first update is successful even the following gives error, It seems Oracle does commit after each statement.
How do i rollback and issue a exit code to be caught in shell script
Regards,
Hans
December 29, 2005 - 5:44 pm UTC
sqlplus commits by default upon exit. It is not commiting each row (not unless you use the sqlplus command to set autocommit on - then it would)
http://docs.oracle.com/docs/cd/B19306_01/server.102/b14357/ch12052.htm#i2700066
ops$tkyte@ORA10GR2> create table t ( id number, col1 varchar2(10), col2 varchar2(10) );
Table created.
ops$tkyte@ORA10GR2> insert into t values ( 1, 'xxxx', 'xxxx' );
1 row created.
ops$tkyte@ORA10GR2> commit;
Commit complete.
ops$tkyte@ORA10GR2><b>
ops$tkyte@ORA10GR2> whenever sqlerror exit 99 ROLLBACK</b>
ops$tkyte@ORA10GR2>
ops$tkyte@ORA10GR2> update t set col1 = 'a' where id = 1;
1 row updated.
ops$tkyte@ORA10GR2> update t set col1 = 'a' where i = 1;
update t set col1 = 'a' where i = 1
*
ERROR at line 1:
ORA-00904: "I": invalid identifier
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[tkyte@dellpe ~]$ plus
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Dec 29 17:41:04 2005
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
ops$tkyte@ORA10GR2> select * from t;
ID COL1 COL2
---------- ---------- ----------
1 xxxx xxxx
Oracle Guy
A reader, May 18, 2006 - 2:16 pm UTC