我對SQL仍然很陌生,現在處於學習階段。我有一個家庭作業,我一直在努力了很長一段時間,我無法弄清楚我的錯誤在序列中的位置。我正在使用Oracle SQL。如何在Oracle中使用序列號
INSERT INTO ORDERS
VALUES (SEQ_ORDER_ID.NEXTVAL, '200', 'MOVIE FOR RENT', '30', '322.61', '15.36', 'CP', '10-MAR-13', '15-MAR-13');
INSERT INTO ORDERS
VALUES (SEQ_ORDER_ID.NEXTVAL, '200', 'MOVIE FOR RENT', '30', '419.74', '19.99', 'CP', '12-MAR-13', '17-MAR-13');
INSERT INTO ORDER_ITEMS
VALUES (SEQ_ITEM_ID.NEXTVAL, SEQ_ORDER_ID.CURRVAL, '40', '10', '25', '12.29', '307.25');
INSERT INTO ORDER_ITEMS
VALUES (SEQ_ITEM_ID.NEXTVAL, SEQ_ORDER_ID.CURRVAL, '40', '11', '25', '15.99', '399.75');
ORDER_ID和ITEM_ID我想用NEXTVAL和CURRVAL測序。我得到的錯誤是:
VALUES (SEQ_ITEM_ID.NEXTVAL, SEQ_ORDER_ID.CURRVAL, '40', '10', '25', '12.29', '307.25')
*
ERROR at line 2:
ORA-02289: sequence does not exist
VALUES (SEQ_ITEM_ID.NEXTVAL, SEQ_ORDER_ID.CURRVAL, '40', '11', '25', '15.99', '399.75')
*
ERROR at line 2:
ORA-02289: sequence does not exist
感謝您的幫助。
這裏是一個小的詳細信息...
create table orders(
order_id number(8),
Store_id number(4) not null,
description varchar2(30),
total_items number(3),
total_payment number(8,2),
tax number(6,2),
order_status varchar2(2),
ordering_date date,
order_completed_date date
);
create table order_items(
item_id number(10),
order_id number(8) not null,
distribution_id number(8) not null,
movie_id number(5) not null,
number_of_items number(3),
item_unit_price number(5,2),
item_sub_total number(10,2)
);
alter table orders
add constraint order_pk primary key (order_id);
alter table orders
add constraint store_order_fk foreign key (store_id) references movie_rental_stores(store_id);
alter table order_items
add constraint order_item_pk primary key (item_id);
alter table order_items
add constraint order_item_fk foreign key (order_id) references orders(order_id);
alter table order_items
add constraint movie_item_fk foreign key (movie_id) references movies(movie_id);
alter table order_items
add constraint distributor_order_item_fk foreign key (distribution_id) references distributed_movie_list(distribution_id);
DROP sequence seq_order_id;
CREATE sequence seq_order_id
increment BY 1 START WITH 1 minvalue 1;
DROP sequence seq_order_item_id;
CREATE sequence seq_order_item_id
increment BY 1 START WITH 1 minvalue 1;
@William Peterson,您已經創建了'seq_order_item_id'序列,但是您正嘗試在代碼中使用'seq_item_id'。 – Noel
此問題是關於發佈代碼中的錯字 – APC
@APC,代碼中的拼寫錯誤在哪裏?我做錯了什麼?我還是不太明白。 –