oracle oracle中的select语句,只读
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24928107/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
select statements in oracle with for read only
提问by
I have a Database Linksin Oracle, and when I query some data like: select * from kfilwrk@something for read only
, I have an error: "missing keyword". I can just write select statement, but the problem is, I need to add for read only
because my select
statement may change some data.
我在Oracle 中有一个数据库链接,当我查询一些数据时:,我有一个错误:“缺少关键字”。我可以只写select语句,但问题是,我需要添加,因为我的语句可能会改变一些数据。select * from kfilwrk@something for read only
for read only
select
UPD: when I write simple select statement and retrieve data, after that I close SQL Developer, it asks me to rollback or commit data. It means the select cursor updates some data
UPD:当我编写简单的选择语句并检索数据时,在关闭 SQL Developer 之后,它要求我回滚或提交数据。这意味着选择光标更新了一些数据
回答by Andreas Fester
The syntax is WITH READ ONLY
, not FOR READ ONLY
and it can only be used with sub queries:
语法是WITH READ ONLY
, notFOR READ ONLY
并且它只能用于子查询:
SQL> CREATE DATABASE LINK MyLink CONNECT TO HR IDENTIFIED BY HR USING 'sampleHost:1521/XE';
SQL> SELECT COUNT(*) FROM (SELECT * FROM Dual@MyLink WITH READ ONLY);
COUNT(*)
----------
1
See also http://docs.oracle.com/database/121/SQLRF/statements_10002.htm#SQLRF55295:
另见http://docs.oracle.com/database/121/SQLRF/statements_10002.htm#SQLRF55295:
subquery_restriction_clauseThe subquery_restriction_clause lets you restrict the subquery in one of the following ways:
WITH READ ONLYSpecify WITH READ ONLY to indicate that the table or view cannot be updated.
subquery_restriction_clausesubquery_restriction_clause 允许您通过以下方式之一限制子查询:
WITH READ ONLY指定 WITH READ ONLY 指示不能更新表或视图。
Alternatively, you can set your transaction into read only mode:
或者,您可以将事务设置为只读模式:
SET TRANSACTION READ ONLY; -- Read only
...
SET TRANSACTION ISOLATION LEVEL READ COMMITTED; -- back to default (read committed)
回答by thatjeffsmith
If you query over a DB_LINK the database assumes there are transactions to COMMIT on close.
如果您通过 DB_LINK 查询,则数据库假定关闭时有要 COMMIT 的事务。
Also, SQL Developer has a shared connection for the Worksheet and the Database Navigator/Object Editors. So if you had opened a table and changed a record - that's on the same connection as your SELECT query on the worksheet.
此外,SQL Developer 具有用于工作表和数据库导航器/对象编辑器的共享连接。因此,如果您打开了一个表并更改了一条记录 - 这与您在工作表上的 SELECT 查询位于同一连接上。