Oracle SQL Developer“表或视图不存在”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33067479/
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
Oracle SQL Developer "table or view does not exist"
提问by Littlelion
I'm pretty new to sql developer, I know that this question was asked and answered tons of times, but I did not found the answer that I need. I know that's it's very basic but I can't find it anywhere. So this is my little code:
我对 sql 开发人员很陌生,我知道这个问题被问过并回答过很多次,但我没有找到我需要的答案。我知道这是非常基本的,但我在任何地方都找不到。所以这是我的小代码:
SELECT *
FROM CITY;
Very simple, but "city" is a table of an user (called parking_places) that I created by myself (it's under System). Now if I try to lunch it I get the following error:
很简单,但是“city”是我自己创建的一个用户表(称为parking_places)(它在System 下)。现在,如果我尝试吃午饭,我会收到以下错误:
- 00000 - "table or view does not exist"
*Cause:
*Action:Error at Line: 163 Column: 6
- 00000 - “表或视图不存在”
*原因:
*行动:行错误:163 列:6
I figured out that if I write:
我发现如果我写:
SELECT *
FROM PARKING_PLACES.CITY ;
I get the expected result. Now the point is that I wish to not write the user name every time that I use a table, looking around in the web I figured out that's a privileges problem (at least so I understood), now how I give the user parking_places the privileges that it needs to do what I want? Or it's not a problem of privileges?
我得到了预期的结果。现在的重点是我不希望每次使用表时都写用户名,在网上环顾四周我发现这是一个权限问题(至少我是这么理解的),现在我如何给用户parking_places权限它需要做我想做的事?还是不是权限问题?
I already tried
我已经试过了
GRANT RESOURCE to parking_places;
The code seems to work, but it seems also that's not what I need.
代码似乎有效,但似乎也不是我需要的。
I woudl prefer a code than a procedure with the GUI as an answere if it's possible, thank you very much!
如果可能的话,我更喜欢代码而不是带有 GUI 的程序作为答案,非常感谢!
回答by eckes
To access a table without specifying the schema you have 4 options in Oracle Database:
要在不指定架构的情况下访问表,您在 Oracle 数据库中有 4 个选项:
a) you login as the schema where the table is located. This is a very common thing since typically you have only one user. It does have the disadvantage that your runtime user is actually the owner of the table and so cannot be restricted in access.
a) 您以表所在的模式登录。这是很常见的事情,因为通常您只有一个用户。它的缺点是您的运行时用户实际上是表的所有者,因此不能限制访问。
b) you grant your user or everybody access to the table and add a synonym in the PUBLIC. pseudo schema. CREATE PUBLIC SYNONYM yourtable FOR owner.yourtable;
. This clutters the public space and requires sys permissions.
b) 您授予您的用户或所有人访问该表的权限,并在 PUBLIC 中添加同义词。伪模式。CREATE PUBLIC SYNONYM yourtable FOR owner.yourtable;
. 这会使公共空间变得混乱并需要 sys 权限。
c) you grant your user or everybody access to the table and add a synonym or view in the runtime user's schema. This does not clutter the public space but it needs to be added/maintained for each "runtime" user.
c) 您授予您的用户或所有人对该表的访问权限,并在运行时用户的架构中添加同义词或视图。这不会使公共空间混乱,但需要为每个“运行时”用户添加/维护它。
d) You use ALTER SESSION SET CURRENT_SCHEMA=owner;
this way all later unqualified table access will use the alternative schema. This is often used when you have a runtime user accessing a schema owned by an installation user. You can add the alter session as a login trigger so you don't need to do it in your application.
d) 您使用ALTER SESSION SET CURRENT_SCHEMA=owner;
这种方式以后所有不合格的表访问都将使用替代模式。当您让运行时用户访问由安装用户拥有的模式时,通常会使用此方法。您可以将更改会话添加为登录触发器,因此您无需在应用程序中执行此操作。
回答by zee
ALTER SESSION ... oracle-docs .. is the equvalnet to use database-name
in sql server and mysql .
ALTER SESSION ... oracle-docs.. 是use database-name
sql server 和 mysql 中的等效网络。
Use the ALTER SESSION statement to set or modify any of the conditions or parameters that affect your connection to the database. The statement stays in effect until you disconnect from the database.
使用 ALTER SESSION 语句来设置或修改影响与数据库的连接的任何条件或参数。该语句将一直有效,直到您与数据库断开连接。
To do this , somewhere in your script add this one line and excute it . Or simply excute from sql developer if that is where you are doing this.
为此,请在脚本的某处添加这一行并执行。或者简单地从 sql developer 执行,如果那是您正在执行的操作。
alter session set current_schema = PARKING_PLACES;
The session will be connected for that user and you wont have to explicitly mention the user name in your subsequent sql statements
:
将为该用户连接会话,您不必在后续内容中明确提及用户名sql statements
:
SELECT * FROM CITY;
P.S : you can also change the schema by right clicking the databases icon in sql developer and browsing the schema you want to work with.
PS:您还可以通过右键单击 sql developer 中的数据库图标并浏览要使用的架构来更改架构。
回答by BradP
Another option exists if you want to select from another schema, you have access to using the workbench:
如果您想从另一个模式中进行选择,则存在另一个选项,您可以使用工作台:
/sqldev:stmt/SET CURRENT SCHEMA='BLAH';
/ sqldev:stmt/SET CURRENT SCHEMA='BLAH';
See imgur below for example.
例如,请参见下面的imgur。
This will for the remainder of that worksheet connection, default all objects to the schema in question.
对于该工作表连接的其余部分,这会将所有对象默认为相关架构。
回答by Kryptonian
Grant select privilege,
授予选择权限,
GRANT SELECT ON TABLE yourtable to public;
You can give privilege to specific user as well.
您也可以为特定用户授予权限。