1

私の質問は:

SalesTransaction の合意価格が車の提示価格の 20% を超えるたびに、「ExcellentSale」という別のテーブルに販売代理店名、車のモデル、メーカー名を自動的に格納するトリガー。(注: このトリガーを実装する前に、'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' 
4

1 に答える 1

0

このエラーは、「into」句を含む select ステートメントが行を生成しないことを意味します。このエラーを回避するために、通常、各列で集計関数 MAX() を使用します。これにより、1 行の結果セットが保証され、「一致する行がない」場合に null 値が生成され、例外は発生しません。

于 2015-05-26T22:42:18.600 に答える