需要 SQL 初学者帮助

时间:2021-02-20 18:33:36

标签: sql oracle

我是 SQL 新手,我对错误试图表达的内容感到困惑。需要帮助!

脚本在这里:

CREATE TABLE CUSTOMERS 
(
    customer_id varchar(10) PRIMARY KEY,
    fist_name varchar (10),
    last_name varchar (10),
    address varchar (20),
    account_balance varchar (10),
    credit_card varchar(20)
);
    
CREATE INDEX cust_id ON CUSTOMERS(customer_id);

INSERT INTO CUSTOMERS (customer_id, first_name, last_name, address, account_balance, credit_card) 
VALUES ('0001', 'Alie', 'Smith', '123 apple st. apt 456','60.00', '2222-6543-8765-7634');
INSERT INTO CUSTOMERS (customer_id, first_name, last_name, address, account_balance, credit_card) 
VALUES ('0002', 'Alex', 'Green', '765 deer st. apt 6009','40.00', '2209-7653-3234-9764');
INSERT INTO CUSTOMERS (customer_id, first_name, last_name, address, account_balance, credit_card) 
VALUES ('0003', 'Bob', 'Jackson', '309  teerance court apt','20.00', '6753-1243-6533-8942');
INSERT INTO CUSTOMERS (customer_id, first_name, last_name, address, account_balance, credit_card) 
VALUES ('0004', 'Casey', 'Rhodes', '799 fernburn rd.','78.00', '5000-3546-1437-9987');
INSERT INTO CUSTOMERS (customer_id, first_name, last_name, address, account_balance, credit_card) 
VALUES ('0005', 'Daniel', 'Henry', '123 apple st. apt 436','25.00', '5776-5363-6675-0075');

CREATE TABLE RENTAL 
(
    rental_id varchar(10) PRIMARY KEY,
    customer_id varchar (10),
    rental_date date ( ormat yy)
);
    
CREATE INDEX rent_id ON RENTAL(rental_id);


INSERT INTO RENTAL (rental_id, customer_id, rental_date) VALUES
('000001', '0001', '01-02-2021');
INSERT INTO RENTAL (rental_id, customer_id, rental_date) VALUES
('000002', '0002', '01-08-2021');
INSERT INTO RENTAL (rental_id, customer_id, rental_date) VALUES
('000003', '0003', '01-14-2021');
INSERT INTO RENTAL (rental_id, customer_id, rental_date) VALUES
('000004', '0004', '01-25-2021');
INSERT INTO RENTAL (rental_id, customer_id, rental_date) VALUES
('000005', '0005', '01-30-2021');





create table RENTAL_LINE ( rental_line_id varchar(10) primary key,
    inventory_id varchar(10),
    return_date date(),
    fee_id varchar (10));
    
create index rent_line on RENTAL_LINE(rental_line_id);


INSERT INTO RENTAL_LINE (rental_line_id, inventory_id, return_date, fee_id) VALUES
('0011', '000001', '02-01-2021', '00001');
INSERT INTO RENTAL_LINE (rental_line_id, inventory_id, return_date, fee_id) VALUES
('0022', '000002', '02-07-2021', '00002');
INSERT INTO RENTAL_LINE (rental_line_id, inventory_id, return_date, fee_id) VALUES
('0033', '000003', '02-13-2021', '00003');
INSERT INTO RENTAL_LINE (rental_line_id, inventory_id, return_date, fee_id) VALUES
('0044', '000004', '02-24-2021', '00004');
INSERT INTO RENTAL_LINE (rental_line_id, inventory_id, return_date, fee_id) VALUES
('0055', '000005', '03-01-2021', '00005');





create table FEES (fee_id varchar(10) primary key,
    rental_line_id varchar(10),
    rental_fee number(5,2),
    damage_fee number (5,2),
    late_fee number(5,2));


create index fee on FEES(fee_id);

INSERT INTO FEES (fee_id, rental_line_id, rental_fee, damage_fee, late_fee ) VALUES
('0001', '0011', '5.00', '0', '0');
INSERT INTO FEES (fee_id, rental_line_id, rental_fee, damage_fee, late_fee ) VALUES
('0002', '0022', '5.00', '15', '0');
INSERT INTO FEES (fee_id, rental_line_id, rental_fee, damage_fee, late_fee ) VALUES
('0003', '0033', '5.00', '0', '10');
INSERT INTO FEES (fee_id, rental_line_id, rental_fee, damage_fee, late_fee ) VALUES
('0004', '0044', '5.00', '15', '10');
INSERT INTO FEES (fee_id, rental_line_id, rental_fee, damage_fee, late_fee ) VALUES
('0005', '0055', '5.00', '0', '0');





create table DISTRIBUTOR (distributor_id varchar(10) primary key,
distributor_name varchar(20),
address varchar(20),
phone VARCHAR(20));


create index dist_id on DISTRUBTOR(distributor_id);

INSERT INTO DISTRIBUTOR (distributor_id, distributor_name, address, phone ) VALUES
('000111', 'Movie Buster', '647 baller st.', '349-008-6754');
INSERT INTO DISTRIBUTOR (distributor_id, distributor_name, address, phone ) VALUES
('000222', 'Movie House', '736 pollar st.', '454-345-0006');
INSERT INTO DISTRIBUTOR (distributor_id, distributor_name, address, phone ) VALUES
('000333', 'DVD Mansion', '348 wheller st.', '535-367-2379');
INSERT INTO DISTRIBUTOR (distributor_id, distributor_name, address, phone ) VALUES
('000444', 'Movie Wholesale', '998 holland st.', '566-339-9867');
INSERT INTO DISTRIBUTOR (distributor_id, distributor_name, address, phone ) VALUES
('000555', 'DVD House', '76 main st.', '233-098-4646');







create table MOVIE_INVENTORY (inventory_id varchar(10) primary key,
    distributor_id varchar(10),
    purchase_price varchar(10),
    rent_fee number (5,2),
    movie_format varchar(10));



create index movie_inven on MOVIE_INVENTORY(inventory_id);

INSERT INTO MOVIE_INVENTORY (inventory_id, distributor_id, purchase_price, rent_fee,movie_format ) VALUES
('0001', '000111', '1000.00', '5', 'CDs');
INSERT INTO MOVIE_INVENTORY (inventory_id, distributor_id, purchase_price, rent_fee,movie_format ) VALUES
('0002', '000222', '2000.00', '5', 'DVDs');
INSERT INTO MOVIE_INVENTORY (inventory_id, distributor_id, purchase_price, rent_fee,movie_format ) VALUES
('0003', '000333', '1000.00', '5', 'CDs');
INSERT INTO MOVIE_INVENTORY (inventory_id, distributor_id, purchase_price, rent_fee,movie_format ) VALUES
('0004', '000444', '3000.00', '5', 'DVDs');
INSERT INTO MOVIE_INVENTORY (inventory_id, distributor_id, purchase_price, rent_fee,movie_format ) VALUES
('0005', '000555', '2000.00', '5', 'DVDs');

错误:

Error starting at line : 5 in command -
create table CUSTOMERS ( customer_id varchar(10) primary key,
    fist_name varchar (10),
    last_name varchar (10),
    address varchar (20),
    account_balance varchar (10),
    credit_card varchar(20))
Error report -
ORA-00955: name is already used by an existing object
00955. 00000 -  "name is already used by an existing object"
*Cause:    
*Action:

Error starting at line : 12 in command -
create index cust_id on CUSTOMERS(customer_id)
Error report -
ORA-01408: such column list already indexed
01408. 00000 -  "such column list already indexed"
*Cause:    
*Action:

Error starting at line : 15 in command -
INSERT INTO CUSTOMERS (customer_id, first_name, last_name, address, account_balance, credit_card) VALUES
('0001', 'Alie', 'Smith', '123 apple st. apt 456','60.00', '2222-6543-8765-7634')
Error at Command Line : 15 Column : 37
Error report -
SQL Error: ORA-00904: "FIRST_NAME": invalid identifier
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:

Error starting at line : 17 in command -
INSERT INTO CUSTOMERS (customer_id, first_name, last_name, address, account_balance, credit_card) VALUES
('0002', 'Alex', 'Green', '765 deer st. apt 6009','40.00', '2209-7653-3234-9764')
Error at Command Line : 17 Column : 37
Error report -
SQL Error: ORA-00904: "FIRST_NAME": invalid identifier
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:

Error starting at line : 19 in command -
INSERT INTO CUSTOMERS (customer_id, first_name, last_name, address, account_balance, credit_card) VALUES
('0003', 'Bob', 'Jackson', '309  teerance court apt','20.00', '6753-1243-6533-8942')
Error at Command Line : 19 Column : 37
Error report -
SQL Error: ORA-00904: "FIRST_NAME": invalid identifier
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:

Error starting at line : 21 in command -
INSERT INTO CUSTOMERS (customer_id, first_name, last_name, address, account_balance, credit_card) VALUES
('0004', 'Casey', 'Rhodes', '799 fernburn rd.','78.00', '5000-3546-1437-9987')
Error at Command Line : 21 Column : 37
Error report -
SQL Error: ORA-00904: "FIRST_NAME": invalid identifier
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:

Error starting at line : 23 in command -
INSERT INTO CUSTOMERS (customer_id, first_name, last_name, address, account_balance, credit_card) VALUES
('0005', 'Daniel', 'Henry', '123 apple st. apt 436','25.00', '5776-5363-6675-0075')
Error at Command Line : 23 Column : 37
Error report -
SQL Error: ORA-00904: "FIRST_NAME": invalid identifier
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:

Error starting at line : 31 in command -
create table RENTAL (rental_id varchar(10) primary key,
    customer_id varchar (10),
    rental_date date ())
Error report -
ORA-00907: missing right parenthesis
00907. 00000 -  "missing right parenthesis"
*Cause:    
*Action:

Error starting at line : 35 in command -
create index rent_id on RENTAL(rental_id)
Error report -
ORA-00942: table or view does not exist
00942. 00000 -  "table or view does not exist"
*Cause:    
*Action:

Error starting at line : 38 in command -
INSERT INTO RENTAL (rental_id, customer_id, rental_date) VALUES
('000001', '0001', '01-02-2021')
Error at Command Line : 38 Column : 13
Error report -
SQL Error: ORA-00942: table or view does not exist
00942. 00000 -  "table or view does not exist"
*Cause:    
*Action:

Error starting at line : 40 in command -
INSERT INTO RENTAL (rental_id, customer_id, rental_date) VALUES
('000002', '0002', '01-08-2021')
Error at Command Line : 40 Column : 13
Error report -
SQL Error: ORA-00942: table or view does not exist
00942. 00000 -  "table or view does not exist"
*Cause:    
*Action:

Error starting at line : 42 in command -
INSERT INTO RENTAL (rental_id, customer_id, rental_date) VALUES
('000003', '0003', '01-14-2021')
Error at Command Line : 42 Column : 13
Error report -
SQL Error: ORA-00942: table or view does not exist
00942. 00000 -  "table or view does not exist"
*Cause:    
*Action:

Error starting at line : 44 in command -
INSERT INTO RENTAL (rental_id, customer_id, rental_date) VALUES
('000004', '0004', '01-25-2021')
Error at Command Line : 44 Column : 13
Error report -
SQL Error: ORA-00942: table or view does not exist
00942. 00000 -  "table or view does not exist"
*Cause:    
*Action:

Error starting at line : 46 in command -
INSERT INTO RENTAL (rental_id, customer_id, rental_date) VALUES
('000005', '0005', '01-30-2021')
Error at Command Line : 46 Column : 13
Error report -
SQL Error: ORA-00942: table or view does not exist
00942. 00000 -  "table or view does not exist"
*Cause:    
*Action:

Error starting at line : 53 in command -
create table RENTAL_LINE ( rental_line_id varchar(10) primary key,
    inventory_id varchar(10),
    return_date date(),
    fee_id varchar (10))
Error report -
ORA-00907: missing right parenthesis
00907. 00000 -  "missing right parenthesis"
*Cause:    
*Action:

Error starting at line : 58 in command -
create index rent_line on RENTAL_LINE(rental_line_id)
Error report -
ORA-00942: table or view does not exist
00942. 00000 -  "table or view does not exist"
*Cause:    
*Action:

Error starting at line : 61 in command -
INSERT INTO RENTAL_LINE (rental_line_id, inventory_id, return_date, fee_id) VALUES
('0011', '000001', '02-01-2021', '00001')
Error at Command Line : 61 Column : 13
Error report -
SQL Error: ORA-00942: table or view does not exist
00942. 00000 -  "table or view does not exist"
*Cause:    
*Action:

Error starting at line : 63 in command -
INSERT INTO RENTAL_LINE (rental_line_id, inventory_id, return_date, fee_id) VALUES
('0022', '000002', '02-07-2021', '00002')
Error at Command Line : 63 Column : 13
Error report -
SQL Error: ORA-00942: table or view does not exist
00942. 00000 -  "table or view does not exist"
*Cause:    
*Action:

Error starting at line : 65 in command -
INSERT INTO RENTAL_LINE (rental_line_id, inventory_id, return_date, fee_id) VALUES
('0033', '000003', '02-13-2021', '00003')
Error at Command Line : 65 Column : 13
Error report -
SQL Error: ORA-00942: table or view does not exist
00942. 00000 -  "table or view does not exist"
*Cause:    
*Action:

Error starting at line : 67 in command -
INSERT INTO RENTAL_LINE (rental_line_id, inventory_id, return_date, fee_id) VALUES
('0044', '000004', '02-24-2021', '00004')
Error at Command Line : 67 Column : 13
Error report -
SQL Error: ORA-00942: table or view does not exist
00942. 00000 -  "table or view does not exist"
*Cause:    
*Action:

Error starting at line : 69 in command -
INSERT INTO RENTAL_LINE (rental_line_id, inventory_id, return_date, fee_id) VALUES
('0055', '000005', '03-01-2021', '00005')
Error at Command Line : 69 Column : 13
Error report -
SQL Error: ORA-00942: table or view does not exist
00942. 00000 -  "table or view does not exist"
*Cause:    
*Action:

Error starting at line : 76 in command -
create table FEES (fee_id varchar(10) primary key,
    rental_line_id varchar(10),
    rental_fee number(5,2),
    damage_fee number (5,2),
    late_fee number(5,2))
Error report -
ORA-00955: name is already used by an existing object
00955. 00000 -  "name is already used by an existing object"
*Cause:    
*Action:

Error starting at line : 83 in command -
create index fee on FEES(fee_id)
Error report -
ORA-01408: such column list already indexed
01408. 00000 -  "such column list already indexed"
*Cause:    
*Action:

Error starting at line : 85 in command -
INSERT INTO FEES (fee_id, rental_line_id, rental_fee, damage_fee, late_fee ) VALUES
('0001', '0011', '5.00', '0', '0')
Error report -
ORA-00001: unique constraint (DBST_USER.SYS_C007369) violated


Error starting at line : 87 in command -
INSERT INTO FEES (fee_id, rental_line_id, rental_fee, damage_fee, late_fee ) VALUES
('0002', '0022', '5.00', '15', '0')
Error report -
ORA-00001: unique constraint (DBST_USER.SYS_C007369) violated


Error starting at line : 89 in command -
INSERT INTO FEES (fee_id, rental_line_id, rental_fee, damage_fee, late_fee ) VALUES
('0003', '0033', '5.00', '0', '10')
Error report -
ORA-00001: unique constraint (DBST_USER.SYS_C007369) violated


Error starting at line : 91 in command -
INSERT INTO FEES (fee_id, rental_line_id, rental_fee, damage_fee, late_fee ) VALUES
('0004', '0044', '5.00', '15', '10')
Error report -
ORA-00001: unique constraint (DBST_USER.SYS_C007369) violated


Error starting at line : 93 in command -
INSERT INTO FEES (fee_id, rental_line_id, rental_fee, damage_fee, late_fee ) VALUES
('0005', '0055', '5.00', '0', '0')
Error report -
ORA-00001: unique constraint (DBST_USER.SYS_C007369) violated


Error starting at line : 100 in command -
create table DISTRIBUTOR (distributor_id varchar(10) primary key,
distributor_name varchar(20),
address varchar(20),
phone VARCHAR(20))
Error report -
ORA-00955: name is already used by an existing object
00955. 00000 -  "name is already used by an existing object"
*Cause:    
*Action:

Error starting at line : 106 in command -
create index dist_id on DISTRUBTOR(distributor_id)
Error report -
ORA-00942: table or view does not exist
00942. 00000 -  "table or view does not exist"
*Cause:    
*Action:

Error starting at line : 108 in command -
INSERT INTO DISTRIBUTOR (distributor_id, distributor_name, address, phone ) VALUES
('000111', 'Movie Buster', '647 baller st.', '349-008-6754')
Error report -
ORA-00001: unique constraint (DBST_USER.SYS_C007370) violated


Error starting at line : 110 in command -
INSERT INTO DISTRIBUTOR (distributor_id, distributor_name, address, phone ) VALUES
('000222', 'Movie House', '736 pollar st.', '454-345-0006')
Error report -
ORA-00001: unique constraint (DBST_USER.SYS_C007370) violated


Error starting at line : 112 in command -
INSERT INTO DISTRIBUTOR (distributor_id, distributor_name, address, phone ) VALUES
('000333', 'DVD Mansion', '348 wheller st.', '535-367-2379')
Error report -
ORA-00001: unique constraint (DBST_USER.SYS_C007370) violated


Error starting at line : 114 in command -
INSERT INTO DISTRIBUTOR (distributor_id, distributor_name, address, phone ) VALUES
('000444', 'Movie Wholesale', '998 holland st.', '566-339-9867')
Error report -
ORA-00001: unique constraint (DBST_USER.SYS_C007370) violated


Error starting at line : 116 in command -
INSERT INTO DISTRIBUTOR (distributor_id, distributor_name, address, phone ) VALUES
('000555', 'DVD House', '76 main st.', '233-098-4646')
Error report -
ORA-00001: unique constraint (DBST_USER.SYS_C007370) violated


Error starting at line : 125 in command -
create table MOVIE_INVENTORY (inventory_id varchar(10) primary key,
    distributor_id varchar(10),
    purchase_price varchar(10),
    rent_fee number (5,2),
    movie_format varchar(10))
Error report -
ORA-00955: name is already used by an existing object
00955. 00000 -  "name is already used by an existing object"
*Cause:    
*Action:

Error starting at line : 133 in command -
create index movie_inven on MOVIE_INVENTORY(inventory_id)
Error report -
ORA-01408: such column list already indexed
01408. 00000 -  "such column list already indexed"
*Cause:    
*Action:

Error starting at line : 135 in command -
INSERT INTO MOVIE_INVENTORY (inventory_id, distributor_id, purchase_price, rent_fee,movie_format ) VALUES
('0001', '000111', '1000.00', '5', 'CDs')
Error report -
ORA-00001: unique constraint (DBST_USER.SYS_C007371) violated


Error starting at line : 137 in command -
INSERT INTO MOVIE_INVENTORY (inventory_id, distributor_id, purchase_price, rent_fee,movie_format ) VALUES
('0002', '000222', '2000.00', '5', 'DVDs')
Error report -
ORA-00001: unique constraint (DBST_USER.SYS_C007371) violated


Error starting at line : 139 in command -
INSERT INTO MOVIE_INVENTORY (inventory_id, distributor_id, purchase_price, rent_fee,movie_format ) VALUES
('0003', '000333', '1000.00', '5', 'CDs')
Error report -
ORA-00001: unique constraint (DBST_USER.SYS_C007371) violated


Error starting at line : 141 in command -
INSERT INTO MOVIE_INVENTORY (inventory_id, distributor_id, purchase_price, rent_fee,movie_format ) VALUES
('0004', '000444', '3000.00', '5', 'DVDs')
Error report -
ORA-00001: unique constraint (DBST_USER.SYS_C007371) violated


Error starting at line : 143 in command -
INSERT INTO MOVIE_INVENTORY (inventory_id, distributor_id, purchase_price, rent_fee,movie_format ) VALUES
('0005', '000555', '2000.00', '5', 'DVDs')
Error report -
ORA-00001: unique constraint (DBST_USER.SYS_C007371) violated

2 个答案:

答案 0 :(得分:2)

错误或多或少是不言自明的,只有当您阅读它们时。

我将大型执行拆分为单独的部分,逐个表。阅读我在每个评论开头写的评论。

不久:

  • 如果一个对象已经存在,你就不能创建它;先放下(或重命名)
  • 使用varchar2,而不是varchar
  • date 数据类型只是 "date";它不接受格式或大小
  • 创建主键约束时,Oracle 会自动创建索引;不要在该列上创建另一个索引
  • 不要将数字括在单引号中
  • 不要以字符串形式输入日期值;使用 DATE 文字或 TO_DATE 函数或 ALTER SESSION 到所需的日期格式
  • 不要犯愚蠢的错别字;它是first_name,而不是fist_name

SQL> /* customers: first_name, not fist_name
SQL>               varchar2, not varchar2
SQL>               customer_id is primary key, Oracle indexes it automatically
SQL>               address is too short; enlarge it
SQL> */
SQL> create table CUSTOMERS ( customer_id varchar2(10) primary key,
  2      first_name varchar2 (10),
  3      last_name varchar2 (10),
  4      address varchar2 (30),
  5      account_balance varchar2 (10),
  6      credit_card varchar2(20));

Table created.

SQL> --create index cust_id on CUSTOMERS(customer_id);
SQL> INSERT INTO CUSTOMERS (customer_id, first_name, last_name, address, account_balance, credit_card) VALUES
  2  ('0001', 'Alie', 'Smith', '123 apple st. apt 456','60.00', '2222-6543-8765-7634');

1 row created.

SQL> INSERT INTO CUSTOMERS (customer_id, first_name, last_name, address, account_balance, credit_card) VALUES
  2  ('0002', 'Alex', 'Green', '765 deer st. apt 6009','40.00', '2209-7653-3234-9764');

1 row created.

SQL> INSERT INTO CUSTOMERS (customer_id, first_name, last_name, address, account_balance, credit_card) VALUES
  2  ('0003', 'Bob', 'Jackson', '309  teerance court apt','20.00', '6753-1243-6533-8942');

1 row created.

SQL> INSERT INTO CUSTOMERS (customer_id, first_name, last_name, address, account_balance, credit_card) VALUES
  2  ('0004', 'Casey', 'Rhodes', '799 fernburn rd.','78.00', '5000-3546-1437-9987');

1 row created.

SQL> INSERT INTO CUSTOMERS (customer_id, first_name, last_name, address, account_balance, credit_card) VALUES
  2  ('0005', 'Daniel', 'Henry', '123 apple st. apt 436','25.00', '5776-5363-6675-0075');

1 row created.

SQL> /* rental: what is "ormat yy"? Format? YY as two digits for year? No such thing in Oracle
SQL>    rental_id is a primary key, don't index it separately
SQL>    wrong date format for RENTAL_DATE. Use TO_DATE with appropriate format or DATE literal, or ALTER SESSION
SQL> */
SQL> create table RENTAL (rental_id varchar2(10) primary key,
  2      customer_id varchar2 (10),
  3      rental_date date
  4      );

Table created.

SQL> --create index rent_id on RENTAL(rental_id);
SQL> alter session set nls_date_format = 'mm-dd-yyyy';

Session altered.

SQL> INSERT INTO RENTAL (rental_id, customer_id, rental_date) VALUES
  2  ('000001', '0001', '01-02-2021');

1 row created.

SQL> INSERT INTO RENTAL (rental_id, customer_id, rental_date) VALUES
  2  ('000002', '0002', '01-08-2021');

1 row created.

SQL> INSERT INTO RENTAL (rental_id, customer_id, rental_date) VALUES
  2  ('000003', '0003', '01-14-2021');

1 row created.

SQL> INSERT INTO RENTAL (rental_id, customer_id, rental_date) VALUES
  2  ('000004', '0004', '01-25-2021');

1 row created.

SQL> INSERT INTO RENTAL (rental_id, customer_id, rental_date) VALUES
  2  ('000005', '0005', '01-30-2021');

1 row created.

SQL> /* rental_line:  datetype is just DATE, not DATE()
SQL>    Don't index primary key column separately
SQL> */
SQL> create table RENTAL_LINE ( rental_line_id varchar2(10) primary key,
  2      inventory_id varchar2(10),
  3      return_date date,
  4      fee_id varchar2 (10));

Table created.

SQL> --create index rent_line on RENTAL_LINE(rental_line_id);
SQL> INSERT INTO RENTAL_LINE (rental_line_id, inventory_id, return_date, fee_id) VALUES
  2  ('0011', '000001', '02-01-2021', '00001');

1 row created.

SQL> INSERT INTO RENTAL_LINE (rental_line_id, inventory_id, return_date, fee_id) VALUES
  2  ('0022', '000002', '02-07-2021', '00002');

1 row created.

SQL> INSERT INTO RENTAL_LINE (rental_line_id, inventory_id, return_date, fee_id) VALUES
  2  ('0033', '000003', '02-13-2021', '00003');

1 row created.

SQL> INSERT INTO RENTAL_LINE (rental_line_id, inventory_id, return_date, fee_id) VALUES
  2  ('0044', '000004', '02-24-2021', '00004');

1 row created.

SQL> INSERT INTO RENTAL_LINE (rental_line_id, inventory_id, return_date, fee_id) VALUES
  2  ('0055', '000005', '03-01-2021', '00005');

1 row created.

SQL> /* fees: don't index primary key separately
SQL>    Don't enclose numbers into single quotes
SQL> */
SQL> create table FEES (fee_id varchar2(10) primary key,
  2      rental_line_id varchar2(10),
  3      rental_fee number(5,2),
  4      damage_fee number (5,2),
  5      late_fee number(5,2));

Table created.

SQL> --create index fee on FEES(fee_id);
SQL> INSERT INTO FEES (fee_id, rental_line_id, rental_fee, damage_fee, late_fee ) VALUES
  2  ('0001', '0011', 5, 0, 0);

1 row created.

SQL> INSERT INTO FEES (fee_id, rental_line_id, rental_fee, damage_fee, late_fee ) VALUES
  2  ('0002', '0022', 5, 15, 0);

1 row created.

SQL> INSERT INTO FEES (fee_id, rental_line_id, rental_fee, damage_fee, late_fee ) VALUES
  2  ('0003', '0033', 5, 0, 10);

1 row created.

SQL> INSERT INTO FEES (fee_id, rental_line_id, rental_fee, damage_fee, late_fee ) VALUES
  2  ('0004', '0044', 5, 15, 10);

1 row created.

SQL> INSERT INTO FEES (fee_id, rental_line_id, rental_fee, damage_fee, late_fee ) VALUES
  2  ('0005', '0055', 5, 0, 0);

1 row created.

SQL> /* Distributor: don't index primary key separately
SQL> */
SQL> create table DISTRIBUTOR (distributor_id varchar2(10) primary key,
  2  distributor_name varchar2(20),
  3  address varchar2(20),
  4  phone varchar2(20));

Table created.

SQL> --create index dist_id on DISTRUBTOR(distributor_id);
SQL> INSERT INTO DISTRIBUTOR (distributor_id, distributor_name, address, phone ) VALUES
  2  ('000111', 'Movie Buster', '647 baller st.', '349-008-6754');

1 row created.

SQL> INSERT INTO DISTRIBUTOR (distributor_id, distributor_name, address, phone ) VALUES
  2  ('000222', 'Movie House', '736 pollar st.', '454-345-0006');

1 row created.

SQL> INSERT INTO DISTRIBUTOR (distributor_id, distributor_name, address, phone ) VALUES
  2  ('000333', 'DVD Mansion', '348 wheller st.', '535-367-2379');

1 row created.

SQL> INSERT INTO DISTRIBUTOR (distributor_id, distributor_name, address, phone ) VALUES
  2  ('000444', 'Movie Wholesale', '998 holland st.', '566-339-9867');

1 row created.

SQL> INSERT INTO DISTRIBUTOR (distributor_id, distributor_name, address, phone ) VALUES
  2  ('000555', 'DVD House', '76 main st.', '233-098-4646');

1 row created.

SQL> /* movie_inventory:  don't index primary key column
SQL>    don't enclose numbers into single quotes
SQL> */
SQL> create table MOVIE_INVENTORY (inventory_id varchar2(10) primary key,
  2      distributor_id varchar2(10),
  3      purchase_price varchar2(10),
  4      rent_fee number (5,2),
  5      movie_format varchar2(10));

Table created.

SQL> --create index movie_inven on MOVIE_INVENTORY(inventory_id);
SQL> INSERT INTO MOVIE_INVENTORY (inventory_id, distributor_id, purchase_price, rent_fee,movie_format ) VALUES
  2  ('0001', '000111', '1000.00', 5, 'CDs');

1 row created.

SQL> INSERT INTO MOVIE_INVENTORY (inventory_id, distributor_id, purchase_price, rent_fee,movie_format ) VALUES
  2  ('0002', '000222', '2000.00', 5, 'DVDs');

1 row created.

SQL> INSERT INTO MOVIE_INVENTORY (inventory_id, distributor_id, purchase_price, rent_fee,movie_format ) VALUES
  2  ('0003', '000333', '1000.00', 5, 'CDs');

1 row created.

SQL> INSERT INTO MOVIE_INVENTORY (inventory_id, distributor_id, purchase_price, rent_fee,movie_format ) VALUES
  2  ('0004', '000444', '3000.00', 5, 'DVDs');

1 row created.

SQL> INSERT INTO MOVIE_INVENTORY (inventory_id, distributor_id, purchase_price, rent_fee,movie_format ) VALUES
  2  ('0005', '000555', '2000.00', 5, 'DVDs');

1 row created.

SQL>

答案 1 :(得分:0)

我想您已经多次执行查询。 避免它。采用 如果不存在则创建表[table_name] 代替创建表[table_name]

并单独搜索所有其他错误。