
CREATE TRIGGER E_I_EMP_SALAIRE_NNI
ON S_RH.V_EMP_SALARIE_NNI
INSTEAD OF INSERT
FOR EACH STATEMENT
BEGIN ATOMIC
   INSERT INTO S_RH.T_EMPLOYE_EMP
   SELECT EMP_ID, EMP_NOM, EMP_PRENOM, EMP_DATE_NAISSANCE, 
          SUBSTRING(NNI, 1, 1), 
          SUBSTRING(NNI, 2, 4),
          SUBSTRING(NNI, 6, 5),
          SUBSTRING(NNI, 10, 3),,
          EMP_DATE_ENTREE, EMP_SALAIRE, EMP_FONCTION, 
          EMP_SERVICE, EMP_MEDECIN_TRAITANT
   FROM   new;
END;


INSERT INTO S_RH.V_EMP_SALARIE_NNI VALUES
(3, 'SCHMIDT', 'Albert', '1982-11-21', '1821154220030', 
 '2010-03-11', 1450, 'Manoeuvre', 'Logistique'),
(4, 'MOULIN', 'Marc', '1969-11-18', '1691125321007', 
 '2018-05-20', 3200, 'Vendeur', 'Commercial');


/*

--> pour SQL Server

CREATE TRIGGER E_I_EMP_SALAIRE_NNI
ON S_RH.V_EMP_SALARIE_NNI
INSTEAD OF INSERT
AS
INSERT INTO S_RH.T_EMPLOYE_EMP
SELECT EMP_ID, EMP_NOM, EMP_PRENOM, EMP_DATE_NAISSANCE, 
       SUBSTRING(NNI, 1, 1), 
       SUBSTRING(NNI, 2, 4),
       SUBSTRING(NNI, 6, 5),
       SUBSTRING(NNI, 10, 3),
       EMP_DATE_ENTREE, EMP_SALAIRE, EMP_FONCTION, 
       EMP_SERVICE, NULL
FROM   inserted;

*/

