Verwendung von Variablen in einer Oracle-trigger

Ich versuche, erstellen einen trigger für update einer Spalte überprüfen-hash. Es muss nicht HR, sondern auch für die sql-puzzle es ist hr, die Tabelle ist:

   DESC SINERS
Name      Null     Type         
--------- -------- ------------ 
LAST_NAME          VARCHAR2(20) 
SIN  NOT NULL NUMBER(9)    
VFY            NUMBER(2)    

das Rätsel ist knifflig, und es erfordert ein bisschen code.

Meisten payroll-Systeme haben eine eingebaute validitätsprüfung für die soziale
Versicherung Zahl. Das folgende Beispiel zeigt, wie Sie manuell
überprüfen Sie die Gültigkeit einer Sozialversicherungsnummer: Social Insurance
Nummer: 123 456 782 Entfernen Sie die Prüfziffer (die Letzte Ziffer): 2-Extrakt
die 2., 4., 6. und 8. Ziffern: 2 4 6 8 Doppelklicken Sie: 4 8 12 16 Hinzufügen
die Ziffern zusammen: 4 + 8 + 1 + 2 + 1 + 6 = 22 Fügen Sie die 1., 3., 5.
und 7 Ziffern: 1 + 3 + 5 + 7 = 16 GESAMT: 38

Ich nur aus dieser Tabelle, um zu simulieren, wie packen Sie eine variable aus der update-oder insert-Anweisung, berechnen eines hash... dann werfen die variable wieder in die gleiche Tabelle.

also ... Benutzer ausgeführt wird dies :

insert into siners (last_name, sin) values (smith, 111222333);

or 

update siners set sin = 222333444 where last_name = 'smith';

Sah ich rund um das web für Beispiele, wie dies zu tun, aber es ist unklar.

Gibt es eine einfache Möglichkeit, dies zu tun? eine Funktion vielleicht?

Erste, generiert ich den oracle sql-code, --- I sub-saitige den Mist aus, aber es funktioniert.

SELECT NVL((NEXT_MULTI - TOTAL_SUM), 0) AS CHECK_VAL
FROM (
SELECT ((
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 1,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 2,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 3,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 4,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 5,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 6,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 7,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 8,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 9,1), 0) 
      ) + (  SUBSTR(SIN, 1, 1) + SUBSTR(SIN, 3, 1) + SUBSTR(SIN, 5, 1) + SUBSTR(SIN, 7, 1)))
     "TOTAL_SUM",  
      CASE WHEN SUBSTR(((
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 1,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 2,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 3,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 4,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 5,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 6,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 7,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 8,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 9,1), 0) 
      ) + (  SUBSTR(SIN, 1, 1) + SUBSTR(SIN, 3, 1) + SUBSTR(SIN, 5, 1) + SUBSTR(SIN, 7, 1))), 2, 1) BETWEEN 1 AND 9 THEN ((10 - (SUBSTR(((
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 1,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 2,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 3,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 4,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 5,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 6,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 7,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 8,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 9,1), 0) 
      ) + (  SUBSTR(SIN, 1, 1) + SUBSTR(SIN, 3, 1) + SUBSTR(SIN, 5, 1) + SUBSTR(SIN, 7, 1))), 2, 1))) + ((
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 1,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 2,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 3,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 4,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 5,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 6,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 7,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 8,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 9,1), 0) 
      ) + (  SUBSTR(SIN, 1, 1) + SUBSTR(SIN, 3, 1) + SUBSTR(SIN, 5, 1) + SUBSTR(SIN, 7, 1)))) END AS NEXT_MULTI
FROM SINERS);

Zweiten habe ich versucht, den code in einen trigger, und das ist, wo ich bin stecken geblieben in dem moment.

Versuchte ich erstellt, um den trigger mit SQL-select -, aber es gab mir eine Fehlermeldung, dass ich nicht laufen konnte ein select auf eine Zeile geändert wird. //Der trigger kompiliert in Ordnung, aber es spuckte die Fehlermeldung, wenn ich lief eine insert-Anweisung für die Tabelle.

CREATE OR REPLACE TRIGGER CHK_VFY
AFTER INSERT OR UPDATE OF SIN ON SINERS
FOR EACH ROW 

DECLARE

LAST_ONE  NUMBER(1); 
TOTAL_SUM  NUMBER(2);  
NEXT_MULTI NUMBER(2);
CHECK_VAL  NUMBER(2);

BEGIN

SELECT T_SUM INTO TOTAL_SUM
FROM (
SELECT ((
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 1,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 2,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 3,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 4,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 5,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 6,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 7,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 8,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 9,1), 0) 
      ) + (  SUBSTR(SIN, 1, 1) + SUBSTR(SIN, 3, 1) + SUBSTR(SIN, 5, 1) + SUBSTR(SIN, 7, 1)))
     "T_SUM" FROM SINERS );

SELECT LAST1 INTO LAST_ONE
FROM (
SELECT  SUBSTR(((
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 1,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 2,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 3,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 4,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 5,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 6,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 7,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 8,1), 0) +
      NVL(SUBSTR( (SUBSTR(SIN, 2, 1)*2) || (SUBSTR(SIN, 4, 1)*2) || (SUBSTR(SIN, 6, 1)*2) || (SUBSTR(SIN, 8, 1)*2), 9,1), 0) 
      ) + (  SUBSTR(SIN, 1, 1) + SUBSTR(SIN, 3, 1) + SUBSTR(SIN, 5, 1) + SUBSTR(SIN, 7, 1))), 2, 1) LAST1 FROM SINERS);

IF LAST_ONE BETWEEN 1 AND 9 THEN 
         NEXT_MULTI := (10 - LAST_ONE) + TOTAL_SUM ;
         CHECK_VAL := (NEXT_MULTI - TOTAL_SUM);
  ELSE 
    CHECK_VAL := 0;
END IF;
UPDATE SINERS SET VFY = CHECK_VAL;

END;

Nach ein wenig Forschung, die auf dieser Website und andere, habe ich versucht, mit Hilfe :neuen.Sünde zu greifen, die variable vor dem update, hatte aber kein Glück. es scheint sich nicht zu aktualisieren. So, ich sank in die dbms_output.put_line( ' Updated Check Value = ' || CHECK_VAL ); zu versuchen und zu überprüfen, ob die Variablen wurden gesammelt. Ich bekomme keine Ausgabe überhaupt....

über die :neue.variable code.... Es kompiliert in Ordnung, aber fordert mich auf, für bind-Variablen. "neuen", Der Standardwert ist null, aber ich habe versucht, das Spiel mit den Variablen, so wie ich das sehe einige reference new as new and old as old im ähnliche Beispiele.

CREATE OR REPLACE TRIGGER CAL_VFY
BEFORE INSERT OR UPDATE OF SIN ON SINERS
FOR EACH ROW 

DECLARE
SINNO NUMBER(9);
LAST_ONE  NUMBER(2); 
TOTAL_SUM  NUMBER(2);  
NEXT_MULTI NUMBER(2);
CHECK_VAL  NUMBER(2);

BEGIN
  SINNO := :NEW.SIN;
  dbms_output.put_line( 'side sin = ' || sinno );
  LAST_ONE := SUBSTR(((
      NVL(SUBSTR( (SUBSTR(SINNO, 2, 1)*2) || (SUBSTR(SINNO, 4, 1)*2) || (SUBSTR(SINNO, 6, 1)*2) || (SUBSTR(SINNO, 8, 1)*2), 1,1), 0) +
      NVL(SUBSTR( (SUBSTR(SINNO, 2, 1)*2) || (SUBSTR(SINNO, 4, 1)*2) || (SUBSTR(SINNO, 6, 1)*2) || (SUBSTR(SINNO, 8, 1)*2), 2,1), 0) +
      NVL(SUBSTR( (SUBSTR(SINNO, 2, 1)*2) || (SUBSTR(SINNO, 4, 1)*2) || (SUBSTR(SINNO, 6, 1)*2) || (SUBSTR(SINNO, 8, 1)*2), 3,1), 0) +
      NVL(SUBSTR( (SUBSTR(SINNO, 2, 1)*2) || (SUBSTR(SINNO, 4, 1)*2) || (SUBSTR(SINNO, 6, 1)*2) || (SUBSTR(SINNO, 8, 1)*2), 4,1), 0) +
      NVL(SUBSTR( (SUBSTR(SINNO, 2, 1)*2) || (SUBSTR(SINNO, 4, 1)*2) || (SUBSTR(SINNO, 6, 1)*2) || (SUBSTR(SINNO, 8, 1)*2), 5,1), 0) +
      NVL(SUBSTR( (SUBSTR(SINNO, 2, 1)*2) || (SUBSTR(SINNO, 4, 1)*2) || (SUBSTR(SINNO, 6, 1)*2) || (SUBSTR(SINNO, 8, 1)*2), 6,1), 0) +
      NVL(SUBSTR( (SUBSTR(SINNO, 2, 1)*2) || (SUBSTR(SINNO, 4, 1)*2) || (SUBSTR(SINNO, 6, 1)*2) || (SUBSTR(SINNO, 8, 1)*2), 7,1), 0) +
      NVL(SUBSTR( (SUBSTR(SINNO, 2, 1)*2) || (SUBSTR(SINNO, 4, 1)*2) || (SUBSTR(SINNO, 6, 1)*2) || (SUBSTR(SINNO, 8, 1)*2), 8,1), 0) +
      NVL(SUBSTR( (SUBSTR(SINNO, 2, 1)*2) || (SUBSTR(SINNO, 4, 1)*2) || (SUBSTR(SINNO, 6, 1)*2) || (SUBSTR(SINNO, 8, 1)*2), 9,1), 0) ) + 
      (  SUBSTR(SINNO, 1, 1) + SUBSTR(SINNO, 3, 1) + SUBSTR(SINNO, 5, 1) + SUBSTR(SINNO, 7, 1))), 2, 1); 

  TOTAL_SUM := ((
      NVL(SUBSTR( (SUBSTR(SINNO, 2, 1)*2) || (SUBSTR(SINNO, 4, 1)*2) || (SUBSTR(SINNO, 6, 1)*2) || (SUBSTR(SINNO, 8, 1)*2), 1,1), 0) +
      NVL(SUBSTR( (SUBSTR(SINNO, 2, 1)*2) || (SUBSTR(SINNO, 4, 1)*2) || (SUBSTR(SINNO, 6, 1)*2) || (SUBSTR(SINNO, 8, 1)*2), 2,1), 0) +
      NVL(SUBSTR( (SUBSTR(SINNO, 2, 1)*2) || (SUBSTR(SINNO, 4, 1)*2) || (SUBSTR(SINNO, 6, 1)*2) || (SUBSTR(SINNO, 8, 1)*2), 3,1), 0) +
      NVL(SUBSTR( (SUBSTR(SINNO, 2, 1)*2) || (SUBSTR(SINNO, 4, 1)*2) || (SUBSTR(SINNO, 6, 1)*2) || (SUBSTR(SINNO, 8, 1)*2), 4,1), 0) +
      NVL(SUBSTR( (SUBSTR(SINNO, 2, 1)*2) || (SUBSTR(SINNO, 4, 1)*2) || (SUBSTR(SINNO, 6, 1)*2) || (SUBSTR(SINNO, 8, 1)*2), 5,1), 0) +
      NVL(SUBSTR( (SUBSTR(SINNO, 2, 1)*2) || (SUBSTR(SINNO, 4, 1)*2) || (SUBSTR(SINNO, 6, 1)*2) || (SUBSTR(SINNO, 8, 1)*2), 6,1), 0) +
      NVL(SUBSTR( (SUBSTR(SINNO, 2, 1)*2) || (SUBSTR(SINNO, 4, 1)*2) || (SUBSTR(SINNO, 6, 1)*2) || (SUBSTR(SINNO, 8, 1)*2), 7,1), 0) +
      NVL(SUBSTR( (SUBSTR(SINNO, 2, 1)*2) || (SUBSTR(SINNO, 4, 1)*2) || (SUBSTR(SINNO, 6, 1)*2) || (SUBSTR(SINNO, 8, 1)*2), 8,1), 0) +
      NVL(SUBSTR( (SUBSTR(SINNO, 2, 1)*2) || (SUBSTR(SINNO, 4, 1)*2) || (SUBSTR(SINNO, 6, 1)*2) || (SUBSTR(SINNO, 8, 1)*2), 9,1), 0) 
      ) + (  SUBSTR(SINNO, 1, 1) + SUBSTR(SINNO, 3, 1) + SUBSTR(SINNO, 5, 1) + SUBSTR(SINNO, 7, 1))); 

  IF LAST_ONE BETWEEN 1 AND 9 THEN 
         NEXT_MULTI := (10 - LAST_ONE) + TOTAL_SUM ;
         CHECK_VAL := (NEXT_MULTI - TOTAL_SUM);
  ELSE 
    CHECK_VAL := 0;
  END IF;

  CASE 
   WHEN INSERTING THEN
           UPDATE SINERS SET VFY = CHECK_VAL WHERE SIN = :NEW.SIN;
           dbms_output.put_line( 'New Check Value = ' || CHECK_VAL );

    WHEN UPDATING THEN
          UPDATE SINERS SET VFY = CHECK_VAL WHERE SIN = :NEW.SIN;
          dbms_output.put_line( ' Updated Check Value = ' || CHECK_VAL );
  END CASE;

END;

Wenn Sie einen Gedanken auf, wie man über dieses, ich bin ganz Ohr....

Vielen Dank für Ihre Hilfe!

  • Wenn die Kategorie ist in Bezug auf die Kunden in einer anderen Tabelle schon, warum Sie duplizieren möchten, dass der link in der Tabelle und haben zu pflegen es in beiden Orten?
  • Lesen Sie zuerst diese - stackoverflow.com/questions/how-to-ask . Wo ist das "division" - Spalte? Bitte zeigen Sie ALLE relevanten tabellenschemas.
  • Tatsächlich, alles was ich will ist ein trigger berechnen Sie die Dritte Spalte, wenn ein Benutzer update-oder insert-die ersten zwei. Ich habe versucht mit der :neuen. zusammen mit dem update, aber es hat nicht funktioniert. Es ohne Fehler kompiliert, aber nicht ausgeführt. Es ist nur ein Beispiel.
InformationsquelleAutor Tom | 2013-05-06
Schreibe einen Kommentar