SQL触发器编译但我收到错误

时间:2015-12-15 18:22:12

标签: sql oracle triggers sql-insert sqltransaction

我在SQL中创建了一个触发器,它编译好了,但是当我运行插入时,我收到以下错误:

SQL Error: ORA-01403: no data found  
ORA-06512: at "EOCRIBIN.SHIPMENT_CAPACITY", line 5  
ORA-04088: error during execution of trigger 'EOCRIBIN.SHIPMENT_CAPACITY'  
01403. 00000 -  "no data found"  
*Cause:  No data was found from the objects.  
*Action: There was no data from the objects which may be due to end of fetch.

这是触发器:

CREATE OR REPLACE TRIGGER Shipment_capacity
BEFORE INSERT or UPDATE on SHIPMENT_TYPE FOR EACH ROW
DECLARE 
  NOT_ENOUGH_CAPACITY EXCEPTION;
  WEIGHT INTEGER;
BEGIN

  SELECT VolumeCapacity
    INTO WEIGHT
    FROM shipment_type
   WHERE ShipmentType = :NEW.ShipmentType;

  IF WEIGHT > :new.WeightCapacity THEN
    RAISE NOT_ENOUGH_CAPACITY;
  END IF;

  EXCEPTION 
  WHEN NOT_ENOUGH_CAPACITY THEN
    RAISE_APPLICATION_ERROR(-200003,'Volume capacity exceeds weight limit');
END; 

该表包含以下内容:

CREATE TABLE SHIPMENT_TYPE
(
    ShipmentType varchar(25) primary key, 
    VolumeCapacity INT, 
    WeightCapacity INT, 
    Temperature float
);

知道为什么会发生这种错误吗?

1 个答案:

答案 0 :(得分:2)

我认为您的选择查询返回Nothing。您可以使用

捕获异常
WHEN NO_DATA_FOUND THEN
     --whatever you want to do when the error appear
END;