oracle触发器:新的上下文变量

时间:2015-05-26 04:50:11

标签: oracle

问题:

触发器,自动存储在名为“ExcellentSale”的单独表中的销售代理 名称,汽车型号和制造商名称,每次商定的价格 SalesTransaction超过汽车要价的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 generateKey
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
SAname varchar2(50);
carModel varchar2(50);
manufacturerName varchar2(50);
askingprice number;
agreedprice number;
begin
select sa.name, mo.name, mu.name, c.askingprice, st.agreedprice
into SAname, CarModel, 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
(generateKey.nextval, agentName, modelName, manufacturerName);
END IF; 
end AutoStore;
/

我得到的错误是

  

PL / SQL:ORA -00984:此处不允许使用列

请帮忙,先谢谢你。

1 个答案:

答案 0 :(得分:1)

在insert语句的VALUES子句中,您可以使用包含所需值的变量而不是列名。

INSERT INTO ExcellentSale
VALUES
(generateKey.nextval, SAname, CarModel, manufacturerName);