ORA-00942: 可以从“schema.table”中选择但不是“桌子”?

发布于 2024-12-06 19:34:14 字数 179 浏览 3 评论 0原文

我在执行时遇到了ORA-00942(“表或视图不存在”)

select * from brunch

但是,执行时没有这样的问题

select * from joe.brunch

我可以知道这里的问题是什么吗?

I experienced an ORA-00942 ("table or view does not exist") when executing

select * from brunch

However, no such problem when executing

select * from joe.brunch

May i know what is the issue here?

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

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

发布评论

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

评论(3

最初的梦 2024-12-13 19:34:14

不合格,BRUNCH 引用当前会话中与 JOE.BRUNCH 不同的对象。您有几个选项可以解决这个问题。

  1. 创建公共同义词。这将允许任何拥有 JOE.BRUNCH 表权限的用户通过查询 BRUNCH

    来访问它

    创建公共同义词早午餐
    FOR joe.brunch

  2. 创建一个私有同义词。这将仅允许当前用户通过查询 BRUNCH

    来访问 JOE.BRUNCH

    创建同义词早午餐
    FOR joe.brunch

  3. 将当前会话的当前架构更改为 JOE。这将导致当前会话中的所有不合格引用解析为 JOE 架构,而不是当前用户的架构

    ALTER SESSION SET current_schema = JOE

Unqualified, BRUNCH refers to a different object than JOE.BRUNCH in your current session. You've got a couple of options to fix that.

  1. Create a public synonym. This will allow any user that has privileges on the JOE.BRUNCH table to access it by querying BRUNCH

    CREATE PUBLIC SYNONYM brunch
    FOR joe.brunch

  2. Create a private synonym. This will allow just the current user to access the JOE.BRUNCH table by querying BRUNCH

    CREATE SYNONYM brunch
    FOR joe.brunch

  3. Change the current schema for the current session to JOE. This will cause all unqualified references in the current session to resolve to the JOE schema rather than to the current user's schema

    ALTER SESSION SET current_schema = JOE

悸初 2024-12-13 19:34:14

有几种可能的原因

1) 存在多个称为 brunch 的对象(表、视图、过程等)。 Oracle不知道你指的是哪一个。

2)最可能的原因:该表存在于 joe 模式中,但您正在以另一个尚未被授予对 joe.brunch 对象进行选择的用户身份进行连接

尝试

将 joe.brunch 上的选择授予 your_user

并尝试此操作并查看有多少对象匹配名称早午餐

选择*
来自所有对象
其中 object_type in ('TABLE','VIEW')
和 object_name = '早午餐';

There are several possible causes

1) there is more than one object (table,view, procedure, etc) called brunch. Oracle does not know which one you are referring to.

2) most likely cause: the table exists in the joe schema but you are connecting as another user who has not been granted select on the joe.brunch object

Try

Grant select on joe.brunch to your_user

and try this and see how many objects match the name brunch

select *
from all_objects
where object_type in (‘TABLE’,'VIEW’)
and object_name = ‘brunch‘;

冷了相思 2024-12-13 19:34:14

我发现我引用的表(Flyway 的 schema_version 表)是用双引号创建的......因此无论在哪里引用它都需要双引号。

以下是 Oracle 的说法

带引号的标识符以双引号 (") 开头和结尾。
如果使用带引号的标识符命名架构对象,则必须
每当您引用该对象时,请使用双引号。

在实践中,这些有效:

SELECT * FROM MYSCHEMA."schema_version";
SELECT * FROM "MYSCHEMA"."schema_version";

当这不起作用时(-> ORA-00942:表或视图不存在):

SELECT * FROM MYSCHEMA.schema_version;

I found that the table I was referencing (Flyway's schema_version table), was created with double quotes... and thus needed double quotes wherever it was referenced.

Here's what Oracle says:

A quoted identifier begins and ends with double quotation marks (").
If you name a schema object using a quoted identifier, then you must
use the double quotation marks whenever you refer to that object.

In practice, these worked:

SELECT * FROM MYSCHEMA."schema_version";
SELECT * FROM "MYSCHEMA"."schema_version";

When this didn't (-> ORA-00942: table or view does not exist):

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