如何获取 DB2 上当前的隔离级别?

发布于 2024-10-16 12:36:47 字数 647 浏览 3 评论 0原文

我试图了解事务在数据库中如何工作,为此我编写了以下测试 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

睫毛上残留的泪 2024-10-23 12:36:47

您可能可以从特殊寄存器 当前隔离。您将获得 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文