sql >> Database >  >> RDS >> Oracle

Oracle SQL Controlebeperking tussen 2 tabellen

Je moet een trigger maken.

Probeer dit

CREATE OR REPLACE TRIGGER   my_trg
              BEFORE INSERT OR UPDATE ON Relationships
                 FOR EACH ROW
  declare
     function i_Age(id int) return int is
     li_res int;
     begin
       select p.Age
        into li_res 
        from Persons p 
        where p.ID= id 
         and rownum=1;
        return li_res;
    exception when no_data_found then
    return NULL; --or Throw Exception depend on your logic if some datas not found
     end;

     BEGIN
      IF INSERTING OR UPDATING THEN
          IF :NEW.Relation == 'child' and i_Age(:NEW.Person_ID) < i_Age(:NEW.Relative_ID)  then 
           NULL; --Throw Exception or your logic
          END IF;
      END IF;
   END;


  1. Oracle Shutdown-fout ORA-01033

  2. Selectquery herhalen

  3. Maak een PHP-array uit de MySQL-kolom

  4. SQL join-subquery