【发布时间】:2015-10-22 19:02:10
【问题描述】:
我正在为学校开发一个数据库,除了触发器之外一切正常。 例如:
create or replace TRIGGER T_CATEGORY
before insert on GAMECATEGORY
for each row
BEGIN
select G_Category_ID_SEQ.nextval into new.Category_ID from dual;
END;
它忽略了 SQL 语句并且它没有创建触发器? 有谁能帮助我吗? :D
:编辑
CREATE TABLE LIVESTREAM
(
Stream_ID number(13),
LivestreamURL varchar2(50),
primary key(Stream_ID, LivestreamURL),
Channel_ID number(13) not null,
Category_ID number(13) not null,
Title varchar2(50) not null,
Organisation_Name varchar2(50),
Viewers number(13) not null,
LivestreamStatus varchar2(10) check (UPPER(LivestreamStatus) IN ('ONLINE','OFFLINE')),
Followers number(13) not null,
"Views" number(13) not null
);
ALTER TABLE LIVESTREAM ADD constraint FK_LIVESTREAM_Category_ID foreign key(Category_ID) REFERENCES GAMECATEGORY(Category_ID)on delete cascade;
ALTER TABLE LIVESTREAM ADD constraint FK_LIVESTREAM_Channel_ID foreign key(Channel_ID) REFERENCES USERCHANNEL(Channel_ID)on delete cascade;
CREATE SEQUENCE LIVESTREAM_Stream_ID_SEQ
start with 1
increment by 1;
CREATE OR REPLACE TRIGGER T_LIVESTREAM
before insert on LIVESTREAM
for each row
BEGIN
select LIVESTREAM_Stream_ID_SEQ.nextval into :new.Stream_ID from dual;
END;
/
当我将数据插入表中时,它给了我这个错误:
INSERT INTO LIVESTREAM(LivestreamURL, Channel_ID, Category_ID, Title, Organisation_Name, Viewers, LivestreamStatus, Followers, "Views")
VALUES('http://www.twitch.tv/nightblue3, 2, 1,Next Stream: Friday @ 4 AM PST / 7 AM EST / NOON GMT, The Round Table, , OFFLINE, 1052215, 115257581')
Error at Command Line : 253 Column : 1
Error report -
SQL Error: ORA-00947: not enough values
00947. 00000 - "not enough values"
*Cause:
*Action:
【问题讨论】:
-
GAMECATEGORY是什么实体? -
这是它使用的表:
CREATE TABLE GAMECATEGORY ( Category_ID number(13) primary key, CategoryName varchar2(50) not null, ViewerCount number(13) not null ); -
您可以将序列分配简化为
:new.Stream_ID := LIVESTREAM_Stream_ID_SEQ.nextval