Oracle SQL Developer "table or view does not exist"

16,333

Solution 1

To access a table without specifying the schema you have 4 options in Oracle Database:

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.

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.

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.

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.

Solution 2

ALTER SESSION ... oracle-docs .. is the equvalnet to use database-name in sql server and 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.

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.

  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 :

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.

Share:
16,333
Admin
Author by

Admin

Updated on June 05, 2022

Comments

  • Admin
    Admin about 2 years

    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:

    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:

    1. 00000 - "table or view does not exist"

    *Cause:
    *Action:

    Error at Line: 163 Column: 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?

    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!