Ver Mensaje Individual
  #2 (permalink)  
Antiguo 28/09/2007, 00:50
Ferruti
 
Fecha de Ingreso: septiembre-2007
Mensajes: 11
Antigüedad: 17 años, 2 meses
Puntos: 0
Re: Problemas con el Trigger

Sinceramente no controlo mucho el tema este de Oracle, así que tampoco es que tenga mucha experiencia en estos temas, por lo que os pongo lo que he hecho y el error que me da:

TRIGGER CAMPO_AFTER
BEFORE INSERT OR UPDATE ON TABLA
FOR EACH ROW
DECLARE
VAR VARCHAR2(254);
A VARCHAR2(60);
B VARCHAR2(60);
C VARCHAR2(60);
D VARCHAR2(60);

PIVOTE NUMBER (20,10);
CONTADOR INTEGER (2);
I INTEGER (4);
J INTEGER (4);
A1 NUMBER (20,10);
B1 NUMBER (20,10);
C1 NUMBER (20,10);
D1 NUMBER (20,10);


BEGIN
I:=0;
CONTADOR:=0;
PIVOTE:=0;

SELECT CAMPO
INTO VAR
FROM TABLA
J:=LEN(VAR);

WHILE VAR(I)<>";" OR I<J LOOP
A(I):=VAR(I);
I:=I+1;
CONTADOR:=1;
END LOOP;
IF VAR(I)=";" THEN
I:=I+1;
END IF;

WHILE I<J OR VAR(I)<>";" LOOP
B(I):=VAR(I);
I++;
CONTADOR:=2;
END LOOP;

IF VAR(I)=";" THEN
I:=I+1;
END IF;

WHILE I<J OR VAR(I)<>";" LOOP
C(I):=VAR(I);
I++;
CONTADOR:=3;
END LOOP;

IF VAR(I)=";" THEN
I:=I+1;
END IF;

WHILE I<J OR VAR(I)<>";" LOOP
D(I):=VAR(I);
I++;
CONTADOR:=4;
END LOOP;

IF VAR(I)="|" THEN
I:=I+1;
END IF;

WHILE I<J OR VAR(I)<>"|" LOOP
E(I):=VAR(I);
I++;
CONTADOR:=5;
END LOOP;

IF VAR(I)=";" THEN
I:=I+1;
END IF;

SELECT CASE (CONTADOR)

WHEN CONTADOR=1 THEN CAMPO:=VAR

WHEN CONTADOR=2 THEN
(A1:= CAST (A AS NUMBER);
B1:= CAST (B AS NUMBER);
IF B1>A1 THEN
PIVOTE:=B1;
B1:=A1;
A1:=PIVOTE;
END IF
A:= CAST (A1 AS VARCHAR2);
B:= CAST(B1 AS VARCHAR2);
VAR:=CONCAT(A,";",B);
CAMPO:=VAR;)


WHEN CONTADOR=3 THEN (
A1:= CAST (A AS NUMBER);
B1:=CAST(B AS NUMBER);
C1:=CAST(C AS NUMBER);
IF B1>A1 THEN
PIVOTE:=B1;
B1:=A1;
A1:=PIVOTE;
END IF;

IF C1>A1 THEN
PIVOTE:=C1;
C1:=A1;
A1:=PIVOTE;
END IF;

IF C1>B1 THEN
PIVOTE:=B1;
B1:=C1;
C1:=PIVOTE;
END IF;
A:=CAST(A1 AS VARCHAR2);
B:=CAST(B1 AS VARCHAR2);
C:=CAST(C1 AS VARCHAR2);
CAMPO:=CONCAT(A,";",B;";",C);)

WHEN CONTADOR=4 THEN (
A1:=CAST(A AS NUMBER);
B1:=CAST(B AS NUMBER);
C1:=CAST(C AS NUMBER);
D1:=CAST(D AS NUMBER);
IF B1>A1 THEN
PIVOTE:=B1;
B1:=A1;
A1:=PIVOTE;
END IF;

IF C1>A1 THEN
PIVOTE:=C1;
C1:=A1;
A1:=PIVOTE;
END IF;

IF D1>A1 THEN
PIVOTE:=D1;
D1:=A1;
A1:=PIVOTE;
END IF;

IF C1>B1 THEN
PIVOTE:=C1;
C1:=B1;
B1:=PIVOTE;
END IF;

IF D1>B1 THEN
PIVOTE:=D1;
D1:=B1;
B1:=PIVOTE;
END IF;

IF D1>C1 THEN
PIVOTE:=D1;
D1:=C1;
C1:=PIVOTE;
END IF;
A:=CAST(A1 AS VARCHAR2);
B:=CAST(B1 AS VARCHAR2);
C:=CAST(C1 AS VARCHAR2);
D:=CAST(D1 AS VARCHAR2);
CAMPO:=CONCAT(A,";",B;";",C,";",D);)

WHEN DEFAULT THEN :NEW (CAMPO:=VAR);
END;




Un saludo