0

我在 oracle 中创建了一个触发器,显示:

/* Formatted on 3-Oct-2013 15:58:45 (QP5 v5.126) */
CREATE OR REPLACE TRIGGER testtrigger
AFTER INSERT OR UPDATE OF sellpoint_name
ON sell_point
FOR EACH ROW
WHEN (new.sellpoint_name = 'Location')
DECLARE lat, lng sell_point.sellpoint_lat%TYPE;
BEGIN
SELECT  sellpoint_lat, sellpoint_long into lat, lng
  FROM  sell_point
 WHERE  sellpoint_name = :new.sellpoint_name;

IF (:new.sellpoint_lat < 20 OR :new.sellpoint_long < 100)
THEN
    raise_application_error (-20225, 'this point is not exists');
END IF;
END;

但我收到一个错误:

1/12    PLS-00103: Encountered the symbol "," when expecting one of the following:
constant exception <an identifier>
<a double-quoted delimited-identifier> table long double ref
char time timestamp interval date binary national character
nchar
1/47    PLS-00103: Encountered the symbol ";" when expecting one of the following:
16:10:50            := ( , not null range default external character

这里有什么问题?感谢帮助!

4

2 回答 2

2

像这样试试

CREATE OR REPLACE TRIGGER testtrigger
AFTER INSERT OR UPDATE OF sellpoint_name ON sell_point
FOR EACH ROW
WHEN (new.sellpoint_name = 'Location')
DECLARE 
     lat sell_point.sellpoint_lat%TYPE; 
     lng sell_point.sellpoint_long%TYPE;
BEGIN
     SELECT sellpoint_lat, sellpoint_long 
       INTO lat, lng
       FROM sell_point
      WHERE sellpoint_name = :new.sellpoint_name;

     IF (:NEW.sellpoint_lat < 20 OR :NEW.sellpoint_long < 100) THEN
          raise_application_error (-20225, 'this point is not exists');
     END IF;
END;

已编辑

table is mutating当您尝试从同一个表中选择列时,上面的代码将引发错误。

你可以像这样编辑你的代码,

CREATE OR REPLACE TRIGGER testtrigger
AFTER INSERT OR UPDATE OF sellpoint_name ON sell_point
FOR EACH ROW
WHEN (new.sellpoint_name = 'Location')
BEGIN
     IF (:NEW.sellpoint_lat < 20 OR :NEW.sellpoint_long < 100) THEN
          raise_application_error (-20225, 'this point is not exists');
     END IF;
END;
于 2013-10-03T09:34:46.440 回答
0

我想是因为你没有 lat 的数据类型

DECLARE lat, lng sell_point.sellpoint_lat%TYPE;
           ^
于 2013-10-03T09:18:06.770 回答