为什么只从数据库视图中选择时会得到一个打开的事务?

2023-11-28数据库问题
3

本文介绍了为什么只从数据库视图中选择时会得到一个打开的事务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

如果我在 pl/sql developer 中对一个数据库表执行一个简单的 select 语句,我会按照我的预期得到一组标准的结果.

最近,我粘贴了一个来自存储过程的查询,该查询碰巧从视图中选择,并注意到一个事务似乎保持打开状态.这是明显的回滚和提交选项在 PL/SQL 开发人员中可用.

对其他开发人员的调查显示,这似乎影响了一些但不影响其他开发人员,这让我怀疑 PL/SQL Developer 设置.

到底为什么会这样?视图 itelf 有一个到另一个数据库的 DBLink,但我不希望这有任何影响.

有什么想法吗?

解决方案

Any SQL 语句在 Oracle 中启动一个事务.

来自手册:><块引用>

一个事务从第一个可执行的 SQL 语句开始.事务在提交或回滚时结束,无论是使用 COMMIT 或 ROLLBACK 语句显式还是在发出 DDL 语句时隐式.[...] 可执行 SQL 语句是生成对实例的调用的 SQL 语句,包括 DML 和 DDL 语句

那些没有看到这一点的人很可能在自动提交模式下运行,在该模式下,由语句启动的事务在语句完成后立即提交.

其他人声称 SELECT 不是 DML,但再次声明 手册明确指出:

<块引用>数据操作语言 (DML) 语句查询或操作现有模式对象中的数据.它们使您能够:

   * 从一个或多个表或视图中检索或获取数据 (SELECT)
   * 将新数据行添加到表或视图中 (INSERT)
[...]

If I execute a simple select statement in pl/sql developer against a database table, I get a standard set of results back as I would expect.

Recently, I pasted a query from a stored procedure that happened to select from a view, and noticed that a transaction was seemingly left open. This was appraent by the rollback and commit options were available in PL/SQL developer.

A poll of other developers revealed that this seems to affect some but not others, which lead me to suspect PL/SQL Developer settings.

Why on earth would this be the case? The view itelf has a DBLink to another database, but I wouldn't expect this to have any effect.

Any thoughts?

解决方案

Any SQL Statement starts a transaction in Oracle.

From the manual:

A transaction begins with the first executable SQL statement. A transaction ends when it is committed or rolled back, either explicitly with a COMMIT or ROLLBACK statement or implicitly when a DDL statement is issued. [...] An executable SQL statement is a SQL statement that generates calls to an instance, including DML and DDL statements

Most probably those who are not seing this are running in auto-commit mode where the transaction started by a statement is immediately committed after the statement has finished.

Others have claimed that a SELECT is not DML, but again the manual clearly states:

Data manipulation language (DML) statements query or manipulate data in existing schema objects. They enable you to:

   * Retrieve or fetch data from one or more tables or views (SELECT)
   * Add new rows of data into a table or view (INSERT)
[...]

这篇关于为什么只从数据库视图中选择时会得到一个打开的事务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

Mysql目录里的ibtmp1文件过大造成磁盘占满的解决办法
ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致...
2025-01-02 数据库问题
151

按天分组的 SQL 查询
SQL query to group by day(按天分组的 SQL 查询)...
2024-04-16 数据库问题
77

SQL 子句“GROUP BY 1"是什么意思?意思是?
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)...
2024-04-16 数据库问题
62

MySQL groupwise MAX() 返回意外结果
MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)...
2024-04-16 数据库问题
13

MySQL SELECT 按组最频繁
MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)...
2024-04-16 数据库问题
16

在 Group By 查询中包含缺失的月份
Include missing months in Group By query(在 Group By 查询中包含缺失的月份)...
2024-04-16 数据库问题
12