SQL无效的标识符代码

时间:2016-11-06 08:19:42

标签: sql oracle

我正在尝试使用外键制作3个表2。当我尝试将数据插入表中时,我不断收到错误代码,所以我想我会隔离创建表并尝试修复它。代码如下:

-- Spool the execution output to a text file.  This spooled file serves as logs.
spool on
spool hw2.lst
set echo on


-- All the DROP TABLE in the beginning.

DROP TABLE movie CASCADE CONSTRAINTS;
DROP TABLE companies CASCADE CONSTRAINTS;
DROP TABLE producer CASCADE CONSTRAINTS;

-- Creates Table CUSTOMER.

CREATE TABLE CUSTOMER (
cust_ID NUMBER(10),
last_name VARCHAR2(20) NOT NULL,
first_name VARCHAR2(20) NOT NULL,
MI VARCHAR2(1) NOT NULL,
street VARCHAR2(30) NOT NULL,
city VARCHAR2(30) NOT NULL,
state VARCHAR2(30) NOT NULL,
zip_code VARCHAR2(20) NOT NULL,
CONSTRAINT customer_pk PRIMARY KEY(cust_ID));

-- Creates Table SALE_VEHICLE.

CREATE TABLE SALE_VEHICLE (
VIN NUMBER(20),
trade_ID NUMBER(10),
make VARCHAR2(30) NOT NULL,
model VARCHAR2(30) NOT NULL,
type VARCHAR2(30) NOT NULL,
where_frome VARCHAR2(30) NOT NULL,
wholesale_cost NUMBER(8,2)NOT NULL,
CONSTRAINT producer_pk PRIMARY KEY(VIN));


-- Creates Table SALE.

CREATE TABLE SALE (
sale_ID NUMBER(6),
cust_ID NUMBER(10),
salesperson_ID NUMBER(10),
VIN NUMBER(20),
date DATE NOT NULL,
vehicle_status VARCHAR2(20) NOT NULL,
milage VARCHAR2(20) NOT NULL,
gross_sale_price NUMBER(8,2)NOT NULL,
CONSTRAINT sale_pk PRIMARY KEY(sale_ID))
CONSTRAINT customers_fk2 FOREIGN KEY(cust_ID) REFERENCES CUSTOMER(cust_ID))
CONSTRAINT VIN_fk FOREIGN KEY(VIN) REFERENCES SALE_VEHICLE(VIN));

-- spool off command to turn off the spool with it you may not get the all the content spooled.

set echo off
spool off

这是我尝试运行sql文件后回显的内容:

SQL> 
SQL> 
SQL> -- All the DROP TABLE in the beginning.
SQL> 
SQL> DROP TABLE movie CASCADE CONSTRAINTS;
DROP TABLE movie CASCADE CONSTRAINTS
           *
ERROR at line 1:
ORA-00942: table or view does not exist 


SQL> DROP TABLE companies CASCADE CONSTRAINTS;
DROP TABLE companies CASCADE CONSTRAINTS
           *
ERROR at line 1:
ORA-00942: table or view does not exist 


SQL> DROP TABLE producer CASCADE CONSTRAINTS;
DROP TABLE producer CASCADE CONSTRAINTS
           *
ERROR at line 1:
ORA-00942: table or view does not exist 


SQL> 
SQL> -- Creates Table CUSTOMER.
SQL> 
SQL> CREATE TABLE CUSTOMER (
  2  cust_ID NUMBER(10),
  3  last_name VARCHAR2(20) NOT NULL,
  4  first_name VARCHAR2(20) NOT NULL,
  5  MI VARCHAR2(1) NOT NULL,
  6  street VARCHAR2(30) NOT NULL,
  7  city VARCHAR2(30) NOT NULL,
  8  state VARCHAR2(30) NOT NULL,
  9  zip_code VARCHAR2(20) NOT NULL,
 10  CONSTRAINT customer_pk PRIMARY KEY(cust_ID));
CREATE TABLE CUSTOMER (
             *
ERROR at line 1:
ORA-00955: name is already used by an existing object 


SQL> 
SQL> -- Creates Table SALE_VEHICLE.
SQL> 
SQL> CREATE TABLE SALE_VEHICLE (
  2  VIN NUMBER(20),
  3  trade_ID NUMBER(10),
  4  make VARCHAR2(30) NOT NULL,
  5  model VARCHAR2(30) NOT NULL,
  6  type VARCHAR2(30) NOT NULL,
  7  where_frome VARCHAR2(30) NOT NULL,
  8  wholesale_cost NUMBER(8,2)NOT NULL,
  9  CONSTRAINT producer_pk PRIMARY KEY(VIN));
CREATE TABLE SALE_VEHICLE (
             *
ERROR at line 1:
ORA-00955: name is already used by an existing object 


SQL> 
SQL> 
SQL> -- Creates Table SALE.
SQL> 
SQL> CREATE TABLE SALE (
  2  sale_ID NUMBER(6),
  3  cust_ID NUMBER(10),
  4  salesperson_ID NUMBER(10),
  5  VIN NUMBER(20),
  6  date DATE NOT NULL,
  7  vehicle_status VARCHAR2(20) NOT NULL,
  8  milage VARCHAR2(20) NOT NULL,
  9  gross_sale_price NUMBER(8,2)NOT NULL,
 10  CONSTRAINT sale_pk PRIMARY KEY(sale_ID))
 11  CONSTRAINT customers_fk2 FOREIGN KEY(cust_ID) REFERENCES CUSTOMER(cust_ID))
 12  CONSTRAINT VIN_fk FOREIGN KEY(VIN) REFERENCES SALE_VEHICLE(VIN));
date DATE NOT NULL,
*
ERROR at line 6:
ORA-00904: : invalid identifier 


SQL> 
SQL> -- spool off command to turn off the spool with it you may not get the all the content spooled.
SQL> 
SQL> set echo off

任何帮助都会非常感谢。

1 个答案:

答案 0 :(得分:0)

我认为这是答案:

-- Spool the execution output to a text file.  This spooled file serves as logs.
spool on
spool hw2.lst
set echo on


-- All the DROP TABLE in the beginning.

DROP TABLE CUSTOMER CASCADE CONSTRAINTS;
DROP TABLE SALE_VEHICLE CASCADE CONSTRAINTS;
DROP TABLE SALE CASCADE CONSTRAINTS;

-- Creates Table CUSTOMER.

CREATE TABLE CUSTOMER (
cust_ID NUMBER(10),
last_name VARCHAR2(20) NOT NULL,
first_name VARCHAR2(20) NOT NULL,
MI VARCHAR2(1) NOT NULL,
street VARCHAR2(30) NOT NULL,
city VARCHAR2(30) NOT NULL,
state VARCHAR2(30) NOT NULL,
zip_code VARCHAR2(20) NOT NULL,
CONSTRAINT customer_pk PRIMARY KEY(cust_ID));

-- Creates Table SALE_VEHICLE.

CREATE TABLE SALE_VEHICLE (
VIN NUMBER(20),
trade_ID NUMBER(10),
make VARCHAR2(30) NOT NULL,
model VARCHAR2(30) NOT NULL,
type VARCHAR2(30) NOT NULL,
where_frome VARCHAR2(30) NOT NULL,
wholesale_cost NUMBER(8,2)NOT NULL,
CONSTRAINT producer_pk PRIMARY KEY(VIN));


-- Creates Table SALE.

CREATE TABLE SALE (
sale_ID NUMBER(6),
cust_ID NUMBER(10),
salesperson_ID NUMBER(10),
VIN NUMBER(20),
date_received DATE NOT NULL,
vehicle_status VARCHAR2(20) NOT NULL,
milage VARCHAR2(20) NOT NULL,
gross_sale_price NUMBER(8,2)NOT NULL,
CONSTRAINT sale_pk PRIMARY KEY(sale_ID),
CONSTRAINT customers_fk2 FOREIGN KEY(cust_ID) REFERENCES CUSTOMER(cust_ID),
CONSTRAINT VIN_fk FOREIGN KEY(VIN) REFERENCES SALE_VEHICLE(VIN));

-- spool off command to turn off the spool with it you may not get the all the content spooled.

set echo off
spool off