0

I'm using PL/SQL developer to créate this trigger, I read somewhere that it could be a CR-LF missinterpretation by Oracle, but it is the first time this occurs. Below the code is the Error log:


    create or replace trigger Terreno_nomenc
  before update of circ_prov,sector_prov,cod_div_prov,nro_div_prov,nro_parc_prov on adminmo.terreno  
  for each row
declare

  circ integer:= 0;
  sector integer:= 0;
  cod_div integer:= 0;
  nro_div integer:= 0;
  nro_par integer:= 0;

  nueva_nomenc varchar2(18)  := ' ';
  vieja_nomenc varchar2(18)  := ' ';
  dominio integer:= 0;

begin
        vieja_nomenc:= :old.nomenc; 
        if (:new.circ_prov <> :old.circ_prov) then {

                                                   circ := :new.circ_prov;
           }
         else {
               circ := :old.circ_prov;
         }
         end if;
         if(:new.sector_prov <> :old.sector_prov) then {
                                                       sector := :new.sector_prov;
         }
         else {
               sector := :old.sector_prov;
         }
         end if;
         if(:new.cod_div_prov <> :old.cod_div_prov) then {
                                                         cod_div := :new.cod_div_prov;
         }
         else{
              cod_div := :old.cod_div_prov;
         }
         end if;
         if(:new.nro_div_prov <> :old.nro_div_prov) then {
                                                          nro_div := :new.nro_div_prov;
         }
         else{
              nro_div := :old.nro_div_prov;
         }
         end if;
         if(:new.nro_parc_prov <> :old.nro_parc_prov) then {
                                                            nro_par := :new.nro_parc_prov;
         }
         else{
              nro_par := :old.nro_parc_prov;
         }
         end if;
         if(circ > 0 and sector > 0 and cod_div > 0 and nro_div > 0) {

                 nueva_nomenc := to_char(circ,'999') || '-' || to_char(sector,'99') || '-' || to_char(cod_div,'99') || '-' || to_char(nro_div,'9999') || '-' || to_char(nro_par, '999');

                 select t.refnro into dominio 
                 from geoimax.comodoro_ejido_dom_ref t
                 where t.reftex = vieja_nomenc;

                 update terreno set nomenc = nueva_nomenc where terreno.subsistema = :new.subsistema and terreno.partida = :new.partida;

                 update geoimax.Comodoro_Ejido_Dom_Ref c set c.reftex = nueva_nomenc where c.refnro = dominio;
         }
         end if;
end Terreno_nomenc;

Error: PLS-00103: Encountered the symbol "{" when expecting one of the following:

      ( begin case declare exit for goto if loop mod null pragma
      raise return select update while with <an identifier>
      <a double-quoted delimited-identifier> <a bind variable> <<
      continue close current delete fetch lock insert open rollback
      savepoint set sql execute commit forall merge pipe purge
   The symbol "begin was inserted before "{" to continue.

Line: 19 Text: if (:new.circ_prov <> :old.circ_prov) then {

Error: PLS-00103: Encountered the symbol "}" when expecting one of the following:

      ( begin case declare end exception exit for goto if loop mod
      null pragma raise return select update while with
      <an identifier> <a double-quoted delimited-identifier>
      <a bind variable> << continue close current delete fetch lock
      insert open rollback savepoint set sql execute commit forall
      merge pipe purge

Line: 21 Text: }

4

2 回答 2

3

您不要在 PL/SQL 中使用大括号。代码中的{}字符都不需要,它们都是语法错误。您需要删除所有这些字符。

一旦你这样做了,你可能仍然会遇到语法错误(因为你没有发布你的表定义,我们无法尝试修复触发器并验证它是否在我们的系统上编译)。但它们至少会是不同的错误。

仔细检查后,您似乎UPDATE在触发器中还有一条语句试图更新定义行级触发器的表中的行。触发器正在尝试更新terreno并在一个表上定义terreno(除非您在不同的模式中有两个同名的表,并且您在名称解析方面非常棘手)。当您尝试运行它时,这将引发变异表错误。您是否真的在尝试修改正在更新的当前行?或者您是否尝试更新表中的其他行?如果是后者,则强烈暗示数据模型不正确,因为这意味着一行中的数据依赖于同一表中其他行中的数据,这违反了基本规范化。

如果您只是尝试修改当前行中的数据,请不要使用UPDATE. 只需修改:new伪记录。

:new.nomenc := nueva_nomenc;
于 2013-09-20T14:18:27.747 回答
2

几个错误:

  1. {} 花括号应该被删除。
  2. 然后错过了其中一个 IF 语句。

CREATE OR replace TRIGGER terreno_nomenc
  BEFORE UPDATE OF circ_prov, sector_prov, cod_div_prov, nro_div_prov,
nro_parc_prov ON adminmo.terreno
  FOR EACH ROW
DECLARE
    circ         INTEGER := 0;
    sector       INTEGER := 0;
    cod_div      INTEGER := 0;
    nro_div      INTEGER := 0;
    nro_par      INTEGER := 0;
    nueva_nomenc VARCHAR2 ( 18 ) := ' ';
    vieja_nomenc VARCHAR2 ( 18 ) := ' ';
    dominio      INTEGER := 0;
BEGIN
    vieja_nomenc := :OLD.nomenc;

    IF ( :NEW.circ_prov <> :OLD.circ_prov ) THEN
      circ := :NEW.circ_prov;
    ELSE
      circ := :OLD.circ_prov;
    END IF;

    IF ( :NEW.sector_prov <> :OLD.sector_prov ) THEN
      sector := :NEW.sector_prov;
    ELSE
      sector := :OLD.sector_prov;
    END IF;

    IF ( :NEW.cod_div_prov <> :OLD.cod_div_prov ) THEN
      cod_div := :NEW.cod_div_prov;
    ELSE
      cod_div := :OLD.cod_div_prov;
    END IF;

    IF ( :NEW.nro_div_prov <> :OLD.nro_div_prov ) THEN
      nro_div := :NEW.nro_div_prov;
    ELSE
      nro_div := :OLD.nro_div_prov;
    END IF;

    IF ( :NEW.nro_parc_prov <> :OLD.nro_parc_prov ) THEN
      nro_par := :NEW.nro_parc_prov;
    ELSE
      nro_par := :OLD.nro_parc_prov;
    END IF;

    IF ( circ > 0
         AND sector > 0
         AND cod_div > 0
         AND nro_div > 0 ) THEN
      nueva_nomenc := To_char (circ, '999')
                      || '-'
                      || To_char (sector, '99')
                      || '-'
                      || To_char (cod_div, '99')
                      || '-'
                      || To_char (nro_div, '9999')
                      || '-'
                      || To_char (nro_par, '999');

      SELECT T.refnro
      INTO   dominio
      FROM   geoimax.comodoro_ejido_dom_ref T
      WHERE  T.reftex = vieja_nomenc;

      UPDATE terreno
      SET    nomenc = nueva_nomenc
      WHERE  terreno.subsistema = :NEW.subsistema
             AND terreno.partida = :NEW.partida;

      UPDATE geoimax.comodoro_ejido_dom_ref C
      SET    C.reftex = nueva_nomenc
      WHERE  C.refnro = dominio;
    END IF;
END terreno_nomenc; 
/
于 2013-09-20T14:22:30.547 回答