how to write on error rollback in IBM DB2 WinSQL sql script

210 Views Asked by At

Example :

Let's say, I have 3 INSERT statements. I am using WinSQL to execute the following script:

SAVEPOINT A;

INSERT_STATEMENT 1;

INSERT_STATEMENT 2;

INSERT_STATEMENT 3;

Now, INSERT_STATEMENT 1 is successful.

INSERT_STATEMENT 2 is successful.

INSERT_STATEMENT 3 has got into error, so I want to rollback to SAVEPOINT A;

How can we do that?

Please note: We are allowed to run a SQL script in the production through mainframe, so not sure if writing a function(with condition codes) for this will work because functions work when a language like JAVA is involved. My point is to write script directly into winSQL without any external programming language. Could you please guide me.

Thank you.

1

There are 1 best solutions below

1
user3523268 On

Try enclosing the statements between a BEGIN and END