简体   繁体   English

Oracle SQL Developer“表或视图不存在”

[英]Oracle SQL Developer “table or view does not exist”

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. 我是sql开发人员的新手,我知道有人问过这个问题,并且回答了无数次,但我没有找到我需要的答案。 I know that's it's very basic but I can't find it anywhere. 我知道这是非常基本的,但是我在任何地方都找不到。 So this is my little code: 这是我的小代码:

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). 非常简单,但是“ city”是我自己创建的用户表(称为parking_places)(位于System下)。 Now if I try to lunch it I get the following error: 现在,如果我尝试吃午餐,则会出现以下错误:

  1. 00000 - "table or view does not exist" 00000-“表或视图不存在”

*Cause: *原因:
*Action: *行动:

Error at Line: 163 Column: 6 错误在行: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? 现在的要点是,我不希望每次使用表时都不要写用户名,在Web上环顾四周,我发现这是一个特权问题(至少据我所知),现在我如何为用户提供parking_places特权它需要做我想要的吗? Or it's not a problem of privileges? 还是不是特权问题?

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作为应答的过程,非常感谢!

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. a)您以表所在的模式登录。 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. 它确实有一个缺点,即您的运行时用户实际上是表的所有者,因此不能限制访问。

b) you grant your user or everybody access to the table and add a synonym in the PUBLIC. b)您授予用户或每个人对该表的访问权限,并在PUBLIC中添加同义词。 pseudo schema. 伪模式。 CREATE PUBLIC SYNONYM yourtable FOR owner.yourtable; . This clutters the public space and requires sys permissions. 这会使公共空间混乱,并且需要sys权限。

c) you grant your user or everybody access to the table and add a synonym or view in the runtime user's schema. c)您授予您的用户或所有人对表的访问权限,并在运行时用户的架构中添加同义词或视图。 This does not clutter the public space but it needs to be added/maintained for each "runtime" user. 这不会使公共空间混乱,但是需要为每个“运行时”用户添加/维护它。

d) You use ALTER SESSION SET CURRENT_SCHEMA=owner; d)您使用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. 您可以将alter session添加为登录触发器,因此无需在应用程序中进行操作。

ALTER SESSION ... oracle-docs .. is the equvalnet to use database-name in sql server and mysql . ALTER SESSION ... oracle-docs ..是在sql服务器和mysql中use database-name的等效项。

Use the ALTER SESSION statement to set or modify any of the conditions or parameters that affect your connection to the database. 使用ALTER SESSION语句来设置或修改任何影响您与数据库连接的条件或参数。 The statement stays in effect until you disconnect from the database. 该语句将一直有效,直到您与数据库断开连接。

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;

PS : 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中的数据库图标并浏览要使用的架构来更改架构。

Grant select privilege, 授予选择权限,

 GRANT SELECT ON TABLE yourtable to public;

You can give privilege to specific user as well. 您还可以为特定用户赋予特权。

see this link for granting privileges 请参阅此链接以授予特权

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. 对于该工作表连接的其余部分,这会将所有对象默认设置为所讨论的模式。

http://imgur.com/RMsWtIH http://imgur.com/RMsWtIH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM