使用Oracle创建触发器时出现问题

使用Oracle创建触发器时出现问题,oracle,plsql,database-trigger,Oracle,Plsql,Database Trigger,我的问题是: 一个触发器,自动存储在销售代理的一个名为“ExcellentSale”的单独表中 名称、车型和制造商名称,每次的约定价格为 销售成交额超过汽车要价的20%。(注意:您需要创建 “ExcellentSale”表。若要创建主键,请使用 从1开始并递增1)的序列 我在用这些桌子 Manufacturer(manufacturerID, name, region) Model(modelNo, name, type, previousModel, manufacturerID) Car

我的问题是:

一个触发器,自动存储在销售代理的一个名为“ExcellentSale”的单独表中 名称、车型和制造商名称,每次的约定价格为 销售成交额超过汽车要价的20%。(注意:您需要创建 “ExcellentSale”表。若要创建主键,请使用 从1开始并递增1)的序列

我在用这些桌子

Manufacturer(manufacturerID, name, region)

Model(modelNo, name, type, previousModel, manufacturerID)

Car(VIN, dateAcquired, yearBuilt, purchasedPrice, askingPrice,
currentMileage, modelNo)

SalesAgent(agentID, name, DOB)

SalesTransaction(VIN, custID, agentID, dateOfSale, agreedPrice)
这是我的尝试

create sequence ggenerateKey
start with 1
increment by 1;
CREATE TABLE ExcellentSale(
recordNo NUMBER,
agentName VARCHAR2(20) NOT NULL,
modelName VARCHAR2(20) NOT NULL,
manufacturerName VARCHAR2(20) NOT NULL,
PRIMARY KEY(recordNo));
create or replace trigger AutoStore
before insert on SalesTransaction
for each row
declare
agentName varchar2(50);
modelName varchar2(50);
manufacturerName varchar2(50);
askingprice number;
agreedprice number;
begin
select sa.name, mo.name, mu.name, c.askingprice, st.agreedprice
into agentName, modelName, manufacturerName, askingprice, agreedprice
from manufacturer MU, Model MO, Car C, SalesAgent SA, SalesTransaction ST
where mu.manufacturerid = mo.manufacturerid
and st.vin = c.vin
AND c.vin = :new.vin
AND sa.agentID = :new.agentID;
IF :new.agreedPrice > (1.2 * askingPrice) THEN 
INSERT INTO ExcellentSale
VALUES
(ggenerateKey.nextval, agentName, modelName, manufacturerName);
END IF; 
end AutoStore;
/
触发器会编译,当我尝试测试它时,我会使用这些将插入SalesTransaction的值,然后触发触发器,但会显示为错误

insert into SalesTransaction
values
('2B7JB33R9CK683376', '1', '1', to_date('01-02-2013','dd-mm-yyyy'), 586000 );
显示的错误如下所示

insert into SalesTransaction
            *
ERROR at line 1:
ORA-01403: no data found 
ORA-06512: at "JTLA.AUTOSTORE", line 8 
ORA-04088: error during execution of trigger 'JTLA.AUTOSTORE' 

此错误意味着带有“into”子句的select语句不生成行。
为避免此错误,我通常在每列上使用聚合函数MAX(),它保证1行结果集,在“无匹配行”的情况下生成空值,并且不会引发异常首先,您的触发器是SalesTransaction表上的before insert触发器,但您正试图在触发器主体的select语句中加入SalesTransaction表。你肯定知道价格和vin吗?它们是:new.agreedprice和:new.vin。接下来,SalesAgent真的与select中的其他表相关吗?我认为您可能需要将该表提取到它自己的select语句中。最后,如果你没有从你的选择中得到一个行,你最好考虑一下应该发生什么。它应该出错吗?您应该使用默认值吗?还有别的吗?