ON EXCEPTION in an SQL script
Posted in 1999
Topics: General Discussion
I have a script which reads from 3 databases and inserts into a target database. Sometimes a record already exists, so when I get the "duplicate record" error, the script aborts. I want the script to continue. I used the 'on exception' clause, but get 'syntax error' message (I think because it's not inside a stored procedure). Is there a way to continue processing even when there's a SQLERROR? Thanks- Christine
HI Christine,
There is no way in sql run via dbaccess/isql to do any conditional
processing of subsequent sqls based on the result of one sql. Either you
write an esqlc/4gl/stored procedure program.
else you can split your sql script into multiple script. then kick off
each of the script from a shell and output the result of dbaccess into a
file. then do grep on that file and decide what you want to do with the
subsequent sqls. If you have any temporary table create then the sqls
which need data from that temporary sqls will also need to be in the same
sql script.
HTH.
Thanks,
Khem Chander
kchande@yahoo.com
christine waters wrote:
> I have a script which reads from 3 databases and inserts into a target
> database. Sometimes a record already exists, so when I get the
> "duplicate record" error, the script aborts.
>
> I want the script to continue. I used the 'on exception' clause, but
> get 'syntax error' message (I think because it's not inside a stored
> procedure).
>
> Is there a way to continue processing even when there's a SQLERROR?
>
> Thanks-
>
> Christine