PL/Sql查询执行错误
PL/Sql query execution error
这是我的查询。自动将销售代理存储在名为“ExcellentSale”的单独 table 中的触发器
姓名、车型和厂家名称,每次约定价格
SalesTransaction 超过汽车要价的 20%。 (注意:你需要创建
实施此触发器之前的“ExcellentSale”table。要创建主键,请使用
从 1 开始并递增 1 的序列)。它显示这样的错误
ERROR at line 23: PL/SQL: ORA-00942: table or view does not exist
1. create or replace trigger filltable
2. after insert on salestransaction
3. for each row
4. declare
触发器的代码是:
create or replace trigger filltable
after insert on salestransaction
for each row
declare
aname varchar2(25);
modname varchar2(25);
manfname varchar2(25);
askpr number;
agrpr number;
begin
select sa.name,m.name,mf.name
into aname,modname,manfname
from manufacturer mf,model m, car c, salestransaction st, salesagent sa
where mf.manufacturerid = m.manufacturerid and
m.modelno = c.modelno and
c.vin = st.vin and
st.agentid = sa.agentid;
select askingprice,agreedprice
into askpr,agrpr
from car c,salestransaction st
where c.VIN = St.vin;
if(agrpr > askpr*1.2) then
insert into excellentsales values(agent_seq.nextval,aname,modname,manfname);
end if;
end filltable;
/
create table excellentsales
(agentid varchar2(5) not null,
agentname varchar2(25),
carmodel varchar2(25),
mfname varchar2(25),
primary key(agentid))
CREATE SEQUENCE agent_seq START WITH 1 INCREMENT BY 1;
您不需要在 SALESTRANSACTION 的行触发器中查询 SALESTRANSACTION - 您应该改为在调用触发器的 SALESTRANSACTION 行上使用 :NEW 值。我建议将您的触发器重写为:
create table excellentsales
(EXCELLENTSALES_ID NUMBER
CONSTRAINT PK_EXCELLENTSALES
PRIMARY KEY
USING INDEX,
agentid varchar2(5) not null,
agentname varchar2(25),
carmodel varchar2(25),
mfname varchar2(25))
CREATE SEQUENCE EXCELLENTSALES_SEQ
START WITH 1
INCREMENT BY 1;
create or replace trigger filltable
after insert on salestransaction
for each row
declare
aname varchar2(25);
modname varchar2(25);
manfname varchar2(25);
askpr number;
agrpr number;
begin
SELECT m.NAME, mf.NAME, c.ASKINGPRICE
INTO modname, manfname, askpr
FROM CAR c
INNER JOIN MODEL m
ON m.MODELNO = c.MODELNO
INNER JOIN MANUFACTURER mf
ON mf.MANUFACTURERID = m.MANUFACTURERID
WHERE c.VIN = :NEW.VIN;
SELECT sa.NAME
INTO aname
FROM SALESAGENT sa
WHERE sa.AGENTID = :NEW.AGENTID;
agrpr := :NEW.AGREEDPRICE;
if agrpr > askpr * 1.2 then
insert into excellentsales (EXCELLENTSALES_ID, AGENTID, AGENTNAME, CARMODEL, MFNAME)
values(EXCELLENTSALES_SEQ.nextval, :NEW.AGENTID, aname, modname, manfname);
end if;
end filltable;
我还重新设计了您的 EXCELLENTSALES table 以包含一个不是 AGENTID 的主键。由于最初设计的 EXCELLENTSALES 没有记录实际的 AGENTID(显然应该来自 SALESTRANSACTION),在现实世界中可能需要它,例如,用于支付佣金。
这是我的查询。自动将销售代理存储在名为“ExcellentSale”的单独 table 中的触发器 姓名、车型和厂家名称,每次约定价格 SalesTransaction 超过汽车要价的 20%。 (注意:你需要创建 实施此触发器之前的“ExcellentSale”table。要创建主键,请使用 从 1 开始并递增 1 的序列)。它显示这样的错误
ERROR at line 23: PL/SQL: ORA-00942: table or view does not exist
1. create or replace trigger filltable
2. after insert on salestransaction
3. for each row
4. declare
触发器的代码是:
create or replace trigger filltable
after insert on salestransaction
for each row
declare
aname varchar2(25);
modname varchar2(25);
manfname varchar2(25);
askpr number;
agrpr number;
begin
select sa.name,m.name,mf.name
into aname,modname,manfname
from manufacturer mf,model m, car c, salestransaction st, salesagent sa
where mf.manufacturerid = m.manufacturerid and
m.modelno = c.modelno and
c.vin = st.vin and
st.agentid = sa.agentid;
select askingprice,agreedprice
into askpr,agrpr
from car c,salestransaction st
where c.VIN = St.vin;
if(agrpr > askpr*1.2) then
insert into excellentsales values(agent_seq.nextval,aname,modname,manfname);
end if;
end filltable;
/
create table excellentsales
(agentid varchar2(5) not null,
agentname varchar2(25),
carmodel varchar2(25),
mfname varchar2(25),
primary key(agentid))
CREATE SEQUENCE agent_seq START WITH 1 INCREMENT BY 1;
您不需要在 SALESTRANSACTION 的行触发器中查询 SALESTRANSACTION - 您应该改为在调用触发器的 SALESTRANSACTION 行上使用 :NEW 值。我建议将您的触发器重写为:
create table excellentsales
(EXCELLENTSALES_ID NUMBER
CONSTRAINT PK_EXCELLENTSALES
PRIMARY KEY
USING INDEX,
agentid varchar2(5) not null,
agentname varchar2(25),
carmodel varchar2(25),
mfname varchar2(25))
CREATE SEQUENCE EXCELLENTSALES_SEQ
START WITH 1
INCREMENT BY 1;
create or replace trigger filltable
after insert on salestransaction
for each row
declare
aname varchar2(25);
modname varchar2(25);
manfname varchar2(25);
askpr number;
agrpr number;
begin
SELECT m.NAME, mf.NAME, c.ASKINGPRICE
INTO modname, manfname, askpr
FROM CAR c
INNER JOIN MODEL m
ON m.MODELNO = c.MODELNO
INNER JOIN MANUFACTURER mf
ON mf.MANUFACTURERID = m.MANUFACTURERID
WHERE c.VIN = :NEW.VIN;
SELECT sa.NAME
INTO aname
FROM SALESAGENT sa
WHERE sa.AGENTID = :NEW.AGENTID;
agrpr := :NEW.AGREEDPRICE;
if agrpr > askpr * 1.2 then
insert into excellentsales (EXCELLENTSALES_ID, AGENTID, AGENTNAME, CARMODEL, MFNAME)
values(EXCELLENTSALES_SEQ.nextval, :NEW.AGENTID, aname, modname, manfname);
end if;
end filltable;
我还重新设计了您的 EXCELLENTSALES table 以包含一个不是 AGENTID 的主键。由于最初设计的 EXCELLENTSALES 没有记录实际的 AGENTID(显然应该来自 SALESTRANSACTION),在现实世界中可能需要它,例如,用于支付佣金。