何时限定 Oracle 中对象的模式名称

发布于 2024-11-29 18:21:31 字数 236 浏览 0 评论 0原文

是什么决定了 Oracle 对象(表、视图等)是否需要使用模式名称(例如 schema.table_name 或 schema.view_name 等)进行限定?有时,我能够访问远程对象(通过数据库链接),而无需限定架构,但其他时候,我收到一条错误,指出“表或视图不存在”,为了纠正这个问题,我必须限定模式名称。

我知道始终限定模式名称是最佳实践,但我只是好奇为什么我能够在没有限定模式的情况下访问某些远程对象,而其他对象则只能使用限定模式。

What determines whether an Oracle object (table, view, etc.) is required to be qualified with a schema name (for example, schema.table_name, or schema.view_name, etc.)? At times I am able to access a remote objects (via a DB link) without having to qualify the schema, but other times, I receive an error stating that the "table or view doesn't exist", and to correct this, I must qualify the schema name.

I am aware that it is a best practice to always qualify a schema name, but I am just curious why I am able to access certain remote objects without a qualified schema, and others only with a qualified schema.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

谁的年少不轻狂 2024-12-06 18:21:32

来自 Oracle 文档:
http://download.oracle.com/docs/cd /B14117_01/server.101/b10759/sql_elements009.htm

下面的示例说明了 Oracle 如何解析对 SQL 语句中对象的引用。考虑以下语句,该语句将一行数据添加到由部门名称标识的表中:

INSERT INTO departments 
VALUES 
(
 280, 
 'ENTERTAINMENT_CLERK', 
 206, 
 1700);

根据该语句的上下文,Oracle 确定部门可以是:

  • 您自己的模式中的表
  • 您自己的模式中的视图
  • 一个私有同义词表或视图
  • 公共同义词

在考虑模式之外的命名空间之前,Oracle 总是尝试解析您自己的模式中的命名空间内的对象引用。在此示例中,Oracle 尝试按如下方式解析名称部门:

  1. 首先,Oracle 尝试在您自己的包含表、视图和私有同义词的架构中的命名空间中定位对象。如果该对象是私有同义词,则 Oracle 会查找该同义词所代表的对象。该对象可以位于您自己的架构、另一个架构或另一个数据库中。该对象也可以是另一个同义词,在这种情况下,Oracle 会查找该同义词所代表的对象。

  2. 如果该对象位于命名空间中,则 Oracle 会尝试对该对象执行该语句。在此示例中,Oracle 尝试将数据行添加到部门。如果对象的类型不适合语句,Oracle 将返回错误。在此示例中,部门必须是表、视图或解析为表或视图的私有同义词。如果 Departments 是一个序列,则 Oracle 返回错误。

  3. 如果该对象不在迄今为止搜索的任何命名空间中,则 Oracle 会搜索包含公共同义词的命名空间。如果该对象位于该命名空间中,则 Oracle 会尝试对其执行语句。如果对象的类型不适合语句,Oracle 将返回错误。在此示例中,如果 Departments 是序列的公共同义词,则 Oracle 返回错误。

它的意思是,Oracle 在向外扩展搜索之前将在本地检查您调用的对象。
某些远程对象很可能有公共(或您自己的私有)同义词,允许您直接引用它们,而那些没有同义词的对象则必须完全限定。

From the Oracle documentation:
http://download.oracle.com/docs/cd/B14117_01/server.101/b10759/sql_elements009.htm

The following example illustrates how Oracle resolves references to objects within SQL statements. Consider this statement that adds a row of data to a table identified by the name departments:

INSERT INTO departments 
VALUES 
(
 280, 
 'ENTERTAINMENT_CLERK', 
 206, 
 1700);

Based on the context of the statement, Oracle determines that departments can be:

  • A table in your own schema
  • A view in your own schema
  • A private synonym for a table or view
  • A public synonym

Oracle always attempts to resolve an object reference within the namespaces in your own schema before considering namespaces outside your schema. In this example, Oracle attempts to resolve the name departments as follows:

  1. First, Oracle attempts to locate the object in the namespace in your own schema containing tables, views, and private synonyms. If the object is a private synonym, then Oracle locates the object for which the synonym stands. This object could be in your own schema, another schema, or on another database. The object could also be another synonym, in which case Oracle locates the object for which this synonym stands.

  2. If the object is in the namespace, then Oracle attempts to perform the statement on the object. In this example, Oracle attempts to add the row of data to departments. If the object is not of the correct type for the statement, then Oracle returns an error. In this example, departments must be a table, view, or a private synonym resolving to a table or view. If departments is a sequence, then Oracle returns an error.

  3. If the object is not in any namespace searched in thus far, then Oracle searches the namespace containing public synonyms. If the object is in that namespace, then Oracle attempts to perform the statement on it. If the object is not of the correct type for the statement, then Oracle returns an error. In this example, if departments is a public synonym for a sequence, then Oracle returns an error.

What it's saying is that Oracle will check locally for objects you call before expanding its search outwards.
It may well be that there are public (or your own private) synonyms on some of your remote objects allowing you to reference them directly whereas those without the synonyms you'll have to fully qualify.

紅太極 2024-12-06 18:21:32

这取决于您登录时使用的用户名。或者创建/配置数据库链接时使用的用户名。

请注意,对于每个模式,都有一个用户。如果您以用户“XYZ”身份登录,则无需限定“XYZ”架构中的对象。

It depends on what username have you used when you logged in. Or what username was used when the database link was created/configured.

See, for each schema, there is a user. If you logged in as a user "XYZ", then you do not need to qualify object within the "XYZ" schema.

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