0

我还是 SQL 的新手,我正处于学习阶段。我有一个家庭作业,我已经做了很长一段时间了,但我无法弄清楚我的错误来自序列中的哪个位置。我正在使用 Oracle SQL。

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;
4

2 回答 2

3

ORA-02289 是正确的。序列不存在。更仔细地查看您的代码。您的 DDL 脚本会创建一个具有此名称的序列...

DROP sequence seq_order_item_id;
CREATE sequence seq_order_item_id 

...但是您的代码引用了这个名称:

VALUES (SEQ_ITEM_ID.NEXTVAL

只需更改您的 INSERT 语句,以便它们引用正确的名称,代码就会运行。

于 2013-07-07T02:45:49.920 回答
0

是否在表排序的相同模式中创建序列 SEQ_ITEM_ID?

已通过 SEQ_ITEM_ID 创建了公共同义词?

于 2013-07-06T22:06:27.920 回答