如何获取 DB2 上当前的隔离级别?
我试图了解事务在数据库中如何工作,为此我编写了以下测试 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";
执行此代码后,将一行添加到表中。但是,如果我在开头添加以下行:
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
所有工作都按我的预期进行,即事务正确回滚并且数据库中没有新条目,但是如果我再次运行此代码,Data Studio 在第一行中显示错误:
[SQL0428] SQL statement can not be launched.
所以我的问题是: 有没有办法获取当前隔离级别以及为什么我不能将隔离级别设置超过 1 次?
我将非常感谢所有答案和链接。
附言。我正在使用 DB2/iSeries V5R4。
聚苯硫醚。抱歉我的英语不好
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能可以从特殊寄存器 当前隔离。您将获得 SQL0428 因为您在设置隔离级别之前没有 COMMIT 或 ROLLBACK,并且该会话中仍有事务正在处理。
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.