[英]Error with SQL create Trigger oracle
I created a trigger in oracle show that: 我在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;
but I get an error : 但我得到一个错误:
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
what wrong in here? 这是怎么了 thanks for help! 感谢帮助!
Try like this, 这样尝试
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;
Edited 已编辑
The above code will raise the error, table is mutating
, as you are trying to select the columns from the same table. 上面的代码将引发错误, table is mutating
,因为您正试图从同一表中选择列。
You can edit you code like this, 您可以像这样编辑代码,
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;
I think because you have no data type for lat 我认为是因为您没有经纬度的数据类型
DECLARE lat, lng sell_point.sellpoint_lat%TYPE;
^
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.