我是 Oracle 和 SQL 的新手,我正在尝试创建一个触发器,其中 req_ship_date(子订单表)不能在 order_date(customer_order 表)之前。我创建了触发器:
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 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
知道是什么原因造成的吗?谢谢