我是Oracle和SQL的新手,我試圖創建一個觸發器,其中req_ship_date(子訂單表)不能位於order_date(customer_order表)之前。我創建觸發器:Oracle SQL觸發器
create or replace trigger req_ship_date_error
before insert on suborder
for each row
declare
placed_date date;
req_date date;
begin
select order_date into placed_date
from customer_order;
select req_ship_date into req_date
from suborder
where suborder_no = :new.suborder_no;
if placed_date > req_date then
raise_application_error(-20002, ('Order ' || :new.suborder_no || ' required shipping date cannot be before order date'));
end if;
end;
但即使是嘗試插入一個很好的發言,我發現了以下錯誤
insert into suborder
values (8, 2, '10-jul-2012', '12-jul-2012', 'CVS', 2);
ERROR
Error starting at line 1 in command:
insert into suborder
values (8, 2, '10-jul-2012', '12-jul-2012', 'CVS', 2)
Error report:
SQL Error: ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "COMPANY.REQ_SHIP_DATE_ERROR", line 5
ORA-04088: error during execution of trigger 'COMPANY.REQ_SHIP_DATE_ERROR'
01422. 00000 - "exact fetch returns more than requested number of rows"
*Cause: The number specified in exact fetch is less than the rows returned.
*Action: Rewrite the query or change number of rows requested
任何想法是什麼原因造成這之後?由於
明白了,非常感謝你的幫助! – JProg 2012-07-19 16:41:27