Re: SQL Error Checking in Shell Scripts
Posted in 1996
>
> Is there a graceful way to abort a shell script when an SQL error occurs?
> Currently, we are using shell scripts to run SQL to load flat files into tables
> using the following syntax: isql <database> load from "filename" insert into
> "tablename"
>
> One possible error that may result from this statement is: "846: Number of values
> in the load file is not equal to number of columns." What we would like to be able
> to do is trap this error and exit the shell script. All suggestions would be
> appreciated. Please respond via e-mail.
>
> Regards,
>
> Paul Carlton paul_carlton@hp-greeley-om2.om.hp.com
>
>
Hi Paul,
There are two ways I'd go about this.
a) Check out the manual on a utility called dbload - this allows you to load
from files, ignore a predefined number of errors (such as 846), and record
rows that are not loaded in an error file.
b) Run the load statement from a stored procedure, using the on exception and
raise exception routines. Again, check out the manual.
Option a is available from at least v4.0 (maybe earlier). Option b is
available from v5.
HTH,
Richard.
-----------------------------------------------------------------
| _ '\\ | Richard Thomas |
| \\ 0_ | r.thomas@csl.gov.uk |
| \\ / | |
| oo/ | "20 Regal and a four-pack, |
| / \\ | I guess I'm set for the night" |
| \\_/ | - "TV Tan" The Wildhearts |
-----------------------------------------------------------------