我的问题是:
一个触发器,它自动将销售代理名称、汽车型号和制造商名称存储在一个名为“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'