Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Oracle8 Trigger Problem] Feld bei Insert auf vorhandenen Wert prüfen

Empfohlene Antworten

Veröffentlicht

Hallo Leute, ich versuche gerade etwas merkwürdiges, aber das muss leider so sein. Ich möchte beim Einfügen eines Datensatzes ein bestimmtes Feld darauf prüfen, ob der Wert, den ich reinschreiben will schon einmal vorhanden ist (ja ich weiß, normalerweise wäre das ein UK/PK, aber ich kann den hier nicht anwenden). Wenn der Wert schon vorhanden ist, sollte der Insert nicht erfolgen und eine Fehlermeldung zurückgegeben werden.

Ich habe das mit folgendem Trigger probiert. Aber außer konfus ist das Teil wohl überhaupt nichts :rolleyes:

Kann mir da jemand etwas unter die Arme greifen?

EDIT: Hm, Rollback scheint in einem Trigger sowieso nicht erlaubt zu sein, was aber das Problem nicht ändert.


CREATE TRIGGER SA999.TRIG_UNIQUE_MATCHCODE

BEFORE INSERT ON SA999.KONTO

FOR EACH ROW

DECLARE

  cMatchcode VARCHAR(20);

BEGIN

  cMatchcode:='';

  SELECT Matchcode INTO cMatchcode FROM Konto WHERE :OLD.Matchcode=:NEW.Matchcode;

  IF NOT cMatchcode = '' THEN

    ROLLBACK;

  END IF;

END;

create or replace trigger tab_trig

  before insert on tab

  for each row

declare

  dummy number;

begin

  select 1 into dummy from tab where id = :new.id;

  raise_application_error(-20000, 'dup_id: '||:new.id);

  exception

    when NO_DATA_FOUND then

      null;

    when OTHERS then

      raise;

end tab_trig;

/

liefert bei bereits vorhandener id den fehler ora-20001 mit fehlertext 'dup_id: <id>' zurück.

-j

Ohhhh, dankeschön vielmals :)

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.