set echo on
show user


DROP SEQUENCE fip_s_fip_perslid_sap_key;

DROP trigger fip_t_fip_prs_sap_B_IU;

DROP table fip_perslid_sap;

CREATE TABLE fip_perslid_sap
(
  ALG_LOCATIE_CODE                VARCHAR2(5),
  ALG_GEBOUW_CODE                 VARCHAR2(10),
  ALG_VERDIEPING_VOLGNR           NUMBER(3,0),
  ALG_RUIMTE_NR                   VARCHAR2(10),
  PRS_WERKPLEK_VOLGNR             NUMBER (3),
  PRS_WERKPLEK_OMSCHRIJVING       VARCHAR2 (30),
  PRS_AFDELING_NAAM               VARCHAR2 (10),
  PRS_PERSLID_NAAM                VARCHAR2 (30),
  TUSSENVOEGSEL                   VARCHAR2 (20),
  PRS_PERSLID_VOORLETTERS         VARCHAR2 (10),
  PRS_PERSLID_VOORNAAM            VARCHAR2 (30),
  PRS_PERSLID_INITIALEN           VARCHAR2 (10),
  PRS_PERSLID_TELEFOONNR          VARCHAR2 (15),
  PRS_SRTPERSLID_OMSCHRIJVING     VARCHAR2 (30),
  PRS_PERSLID_NR                  VARCHAR2 (16),
  PRS_PERSLID_TITEL               VARCHAR2 (15),
  PRS_PERSLID_OSLOGIN             VARCHAR2 (30),
  PRS_PERSLID_WACHTWOORD          VARCHAR2 (30),
  PERSLID_EMAIL                   VARCHAR2 (50),
  KAMERNUMMER                     VARCHAR2 (10),
  UITDIENST                       VARCHAR2 (2),  
  IMPORTROW                       VARCHAR2 (1024),
  FIP_PERSLID_SAP_KEY             NUMBER(10),
  FIP_ERROR                       VARCHAR2 (2048),
  FIP_ERROR2                      VARCHAR2 (2048)   
);

CREATE SEQUENCE fip_s_fip_perslid_sap_key minvalue 1;

CREATE OR REPLACE TRIGGER fip_t_fip_prs_sap_B_IU
BEFORE INSERT OR UPDATE ON fip_perslid_sap
FOR EACH ROW
BEGIN
   IF :new.fip_perslid_sap_key IS NULL THEN 
     SELECT fip_s_fip_perslid_sap_key.nextval 
     INTO :new.fip_perslid_sap_key 
     FROM DUAL; 
   END IF;   
END;
/

COMMIT;
SPOOL OFF