Checking the Output of SQL Scripts and Commands for Errors

You may also like...

5 Responses

  1. Chris Aldrich says:

    You can also use the -s flag with the db2 command line to get DB2 to stop on error. For example:

    db2 -sv “insert into myschema.table where id = 1”

    This will return an error to the operating system (non-zero in Unix). You can then use

    if [ $? != 0 ] ; then
    echo “Error running command to insert!”
    exit 1
    fi

    The -s will cause DB2 to stop execution and it will return non-zero for both errors (N) and warnings (W) from DB2. So you need to know what could run in each case and be aware of when you want to use -s and when you do not.

  2. Isaac Munoz says:

    Thanks Ember for sharing this with us.

    For those who are lucky to have AIX 🙂 they can use ‘p’ option (paragraph) of the ‘grep’ command and it will help them tremendously to filter paragraphs instead of just lines.

    i.e.
    cat filename.sql.out | grep -vp DB20000I

    Regards!!

  3. Richard McGorman says:

    Well after the discussion but still relevant I think.

    You could search for only lines starting with SQL or DB with this.

    grep -E “^(SQL|DB)” filename.sql.out

Leave a Reply

Your email address will not be published. Required fields are marked *