问题
I am trying to learn how transactions work in DB and to do this I wrote the following test SQL:
SAVEPOINT STOP_HERE ON ROLLBACK RETAIN CURSORS;
INSERT INTO TESTSCHEMA."test" (ID, NAME) VALUES (89898, 'SDFASDFASD');
ROLLBACK TO SAVEPOINT STOP_HERE;
SELECT * FROM TESTSCHEMA."test";
After execution of this code the one row is added into the table. But if I add the following line at the beginning:
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
all work as I expected, i.e. transaction correctly rolled back and no new entries in DB, but if I run this code again the Data Studio shows me error in the first line:
[SQL0428] SQL statement can not be launched.
So my questions are: Is there a way to obtain current isolation level and why I can't set isolation level more than 1 time?
I would be very thankful for all answers and links.
PS. I am using DB2/iSeries V5R4.
PPS. Sorry for my bad English
回答1:
You can probably get the current isolation level from special register current isolation. You get the SQL0428 because you didn't COMMIT or ROLLBACK before setting the isolation level, and there were transactions still in process in that session.
来源:https://stackoverflow.com/questions/4946986/how-to-obtain-current-isolation-level-on-db2