简体   繁体   中英

“table or view does not exist”

I am trying to create some tables but i get every time i try table or view does not exist.

I cant find any solution. Here is my code.

 CREATE
  TABLE "User"
  (
    anon_id      NUMBER (38) NOT NULL PRIMARY KEY,
    querytime    TIMESTAMP ,
    state_symbol VARCHAR2 (5) NOT NULL
  ) ;

CREATE
  TABLE "state"
  (
    symbol            VARCHAR2 (5) NOT NULL PRIMARY KEY,
    name              VARCHAR2 (30 BYTE) ,
    "size"            NUMBER (38) ,
    population        NUMBER (38) ,
    tourists          NUMBER (38) 
  ) ;

CREATE
  TABLE "population_goup"
  (
    name              VARCHAR2 (255) NOT NULL PRIMARY KEY,
    COUNT             NUMBER (38) 
  ) ;

The first 3 tables are createt and now he starts "table or view does not exist" and i dont know why.

CREATE TABLE "location"
  (
    zip         NUMBER (38) NOT NULL PRIMARY KEY,
    city        VARCHAR2 (30 BYTE) NOT NULL,
    state_symbol VARCHAR2 (30 BYTE) NOT NULL ,
    timezone    VARCHAR2 (30 BYTE) NOT NULL ,
    latitude    FLOAT ,
    longitude   FLOAT ,
    population  NUMBER (38) NOT NULL ,
    FOREIGN KEY (state_symbol) references state(symbol)
  ) ;

CREATE
  TABLE landmark
  (
    name              VARCHAR2 (30 BYTE) NOT NULL PRIMARY KEY,
    tourists          NUMBER (38) NOT NULL ,
    location_zip      NUMBER (38) NOT NULL REFERENCES location (zip)
  ) ;


CREATE
  TABLE event
  (
    name              VARCHAR2 (255) NOT NULL ,
    from_date         TIMESTAMP ,
    to_date           TIMESTAMP ,
    location_zip      NUMBER (38) NOT NULL REFERENCES location (zip)
  ) ;


CREATE
  TABLE lives_in
  (
    population_goup_name VARCHAR2 (255) NOT NULL REFERENCES population_group(NAME),
    state_symbol         VARCHAR2 (5) NOT NULL REFERENCES state(SYMBOL),
    PRIMARY KEY(population_goup_name, state_symbol)
  ) ;

  CREATE
  TABLE "searchquery"
  (
    query        VARCHAR2 (4000 CHAR) NOT NULL PRIMARY KEY,
    User_id NUMBER (38) NOT NULL REFERENCES User(anon_id),
    state_symbol VARCHAR2 (5) REFERENCES state(symbol),
    population_name VARCHAR2 (255) REFERENCES population_goup(name),
    landmark_name  VARCHAR2 (30 BYTE) REFERENCES landmark(name),
    event_name  VARCHAR2 (255) REFERENCES event(name),
    location_zip NUMBER (38) REFERENCES landmark(zip)
  ) ;

For searchquery i get "invalid table name" but its not a reserved word so why? I cant find any help from the script of my uni so i thanks to every one that can help me!

state is a keyword, so you double quoted it to use it as a table name. Now you need the quoted name whenever you access that table:

CREATE TABLE "location"
  (
    zip         NUMBER (38) NOT NULL PRIMARY KEY,
    city        VARCHAR2 (30 BYTE) NOT NULL,
    state_symbol VARCHAR2 (30 BYTE) NOT NULL ,
    timezone    VARCHAR2 (30 BYTE) NOT NULL ,
    latitude    FLOAT ,
    longitude   FLOAT ,
    population  NUMBER (38) NOT NULL ,
    FOREIGN KEY (state_symbol) references "state"(symbol)
  ) ;

In order, every object is saved with UPPER CASE name. Unless enclosed within double quotes .

Remove the double quotes to all your table names in the DDL . Also, User, State all are reserved keywords. You cannot use them as table names.

"state" --> state

OR

Refer your tables in the constraints with double quotes, same as in DDL previously..

references state(symbol) --> references "state"(symbol)

searchquery DDL ended with invalid table name because, you refer User table, which is a datadictionary table. So, embed them in double quotes

Example:

CREATE
  TABLE "searchquery"
  (
    query        VARCHAR2 (4000 CHAR) NOT NULL PRIMARY KEY,
    User_id NUMBER (38) NOT NULL REFERENCES "User"(anon_id),
    state_symbol VARCHAR2 (5) REFERENCES "state"(symbol),
    population_name VARCHAR2 (255) REFERENCES "population_goup"(name),
    landmark_name  VARCHAR2 (30 BYTE) REFERENCES "landmark"(name),
    event_name  VARCHAR2 (255) REFERENCES "event"(name),
    location_zip NUMBER (38) REFERENCES "landmark"(zip)
  ) ;

From DOCs.

Nonquoted identifiers are not case sensitive. Oracle interprets them as uppercase. Quoted identifiers are case sensitive.

By enclosing names in double quotation marks, you can give the following names to different objects in the same namespace:

employees
"employees"
"Employees"

Note that Oracle interprets the following names the same, so they cannot be used for different objects in the same namespace:

employees
EMPLOYEES
"EMPLOYEES"

More on the Schema Object Names and Qualifiers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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