If else issue in stored procedure. I try to run this but get error at every "then" and at the "end"
`

    create or replace procedure CONTACT_REFERENCES(
    datetype IN NUMBER,
    created IN DATE,
    oprtr IN NUMBER)
    
    is
    BEGIN
    
    EXECUTE IMMEDIATE 'CREATE TABLE DUP_REF
    (
    SEQID NUMBER(19),
    SITEID NUMBER(10)
    )';
    
    DELETE FROM PURGE_CONTACT;
    DELETE FROM CONTACT_REF;
    if (oprtr = 0 and datetype = 0)
    then
    INSERT INTO PURGE_CONTACT SELECT SEQID,SITEID,DETAILID,DETAILSITE from CONTACT WHERE CREATED < created;
    
    elseif (oprtr = 1 and datetype = 0)
    then
    INSERT INTO PURGE_CONTACT SELECT SEQID,SITEID,DETAILID,DETAILSITE from CONTACT WHERE EXTRACT(YEAR FROM CREATED) = EXTRACT(YEAR FROM created)
    																				AND EXTRACT(MONTH FROM CREATED) = EXTRACT(MONTH FROM created)
    																				AND EXTRACT(DAY FROM CREATED) = EXTRACT(DAY FROM created);
    
    elseif (oprtr = 2 and datetype = 0)
    then
    INSERT INTO PURGE_CONTACT SELECT SEQID,SITEID,DETAILID,DETAILSITE from CONTACT WHERE CREATED > created;
    
    elseif (oprtr = 0 and datetype = 1)
    then
    INSERT INTO PURGE_CONTACT SELECT SEQID,SITEID,DETAILID,DETAILSITE from CONTACT WHERE LASTMODIFIED < created;
    
    elseif (oprtr = 1 and datetype = 1)
    then
    INSERT INTO PURGE_CONTACT SELECT SEQID,SITEID,DETAILID,DETAILSITE from CONTACT WHERE EXTRACT(YEAR FROM LASTMODIFIED) = EXTRACT(YEAR FROM created)
    																				AND EXTRACT(MONTH FROM LASTMODIFIED) = EXTRACT(MONTH FROM created)
    																				AND EXTRACT(DAY FROM LASTMODIFIED) = EXTRACT(DAY FROM created);
    																				
    elseif (oprtr = 2 and datetype = 1)
    then
    INSERT INTO PURGE_CONTACT SELECT SEQID,SITEID,DETAILID,DETAILSITE from CONTACT WHERE LASTMODIFIED > created;
    end if;
    
    
    INSERT INTO DUP_REF SELECT SEQID,SITEID
    FROM PURGE_CONTACT
    WHERE EXISTS (SELECT *
                  FROM LEAD
                  WHERE LEAD.CONTACTID = PURGE_CONTACT.SEQID
                        AND LEAD.CONTACTSITE = PURGE_CONTACT.SITEID);
    
    INSERT INTO DUP_REF SELECT SEQID,SITEID
    FROM PURGE_CONTACT
    WHERE EXISTS (SELECT *
                  FROM MAPRESULT
                  WHERE MAPRESULT.CONTACTSEQ = PURGE_CONTACT.SEQID
                        AND MAPRESULT.CONTACTSITE = PURGE_CONTACT.SITEID);
    
    INSERT INTO DUP_REF SELECT SEQID,SITEID
    FROM PURGE_CONTACT
    WHERE EXISTS (SELECT *
                  FROM USERS
                  WHERE USERS.CONTACTID = PURGE_CONTACT.SEQID
                        AND USERS.CONTACTSITE = PURGE_CONTACT.SITEID);
    
    INSERT INTO DUP_REF SELECT SEQID,SITEID
    FROM PURGE_CONTACT
    WHERE EXISTS (SELECT *
                  FROM PLAYER
                  WHERE PLAYER.CONTACTID = PURGE_CONTACT.SEQID
                        AND PLAYER.CONTACTSITE = PURGE_CONTACT.SITEID);
    
    INSERT INTO DUP_REF SELECT SEQID,SITEID
    FROM PURGE_CONTACT
    WHERE EXISTS (SELECT *
                  FROM SHOPPINGCART
                  WHERE SHOPPINGCART.CONTACT_SEQID = PURGE_CONTACT.SEQID
                        AND SHOPPINGCART.CONTACT_SITEID = PURGE_CONTACT.SITEID);
    
    INSERT INTO CONTACT_REF SELECT DISTINCT SEQID,SITEID FROM DUP_REF;
    
    EXECUTE IMMEDIATE 'DROP TABLE DUP_REF';
    
    DELETE FROM PURGE_CONTACT
    WHERE EXISTS (SELECT *
    			  FROM CONTACT_REF
    			  WHERE CONTACT_REF.SEQID = PURGE_CONTACT.SEQID
    					AND CONTACT_REF.SITEID = PURGE_CONTACT.SITEID);
    
    COMMIT;
    END CONTACT_REFERENCES;

`
If else issue in stored procedure. I try to run this but get error at every "then" and at the "end"
===

`

    create or replace procedure CONTACT_REFERENCES(
    datetype IN NUMBER,
    created IN DATE,
    oprtr IN NUMBER)
    
    is
    BEGIN
    
    EXECUTE IMMEDIATE 'CREATE TABLE DUP_REF
    (
    SEQID NUMBER(19),
    SITEID NUMBER(10)
    )';
    
    DELETE FROM PURGE_CONTACT;
    DELETE FROM CONTACT_REF;
    if (oprtr = 0 and datetype = 0)
    then
    INSERT INTO PURGE_CONTACT SELECT SEQID,SITEID,DETAILID,DETAILSITE from CONTACT WHERE CREATED < created;
    
    elseif (oprtr = 1 and datetype = 0)
    then
    INSERT INTO PURGE_CONTACT SELECT SEQID,SITEID,DETAILID,DETAILSITE from CONTACT WHERE EXTRACT(YEAR FROM CREATED) = EXTRACT(YEAR FROM created)
    																				AND EXTRACT(MONTH FROM CREATED) = EXTRACT(MONTH FROM created)
    																				AND EXTRACT(DAY FROM CREATED) = EXTRACT(DAY FROM created);
    
    elseif (oprtr = 2 and datetype = 0)
    then
    INSERT INTO PURGE_CONTACT SELECT SEQID,SITEID,DETAILID,DETAILSITE from CONTACT WHERE CREATED > created;
    
    elseif (oprtr = 0 and datetype = 1)
    then
    INSERT INTO PURGE_CONTACT SELECT SEQID,SITEID,DETAILID,DETAILSITE from CONTACT WHERE LASTMODIFIED < created;
    
    elseif (oprtr = 1 and datetype = 1)
    then
    INSERT INTO PURGE_CONTACT SELECT SEQID,SITEID,DETAILID,DETAILSITE from CONTACT WHERE EXTRACT(YEAR FROM LASTMODIFIED) = EXTRACT(YEAR FROM created)
    																				AND EXTRACT(MONTH FROM LASTMODIFIED) = EXTRACT(MONTH FROM created)
    																				AND EXTRACT(DAY FROM LASTMODIFIED) = EXTRACT(DAY FROM created);
    																				
    elseif (oprtr = 2 and datetype = 1)
    then
    INSERT INTO PURGE_CONTACT SELECT SEQID,SITEID,DETAILID,DETAILSITE from CONTACT WHERE LASTMODIFIED > created;
    end if;
    
    
    INSERT INTO DUP_REF SELECT SEQID,SITEID
    FROM PURGE_CONTACT
    WHERE EXISTS (SELECT *
                  FROM LEAD
                  WHERE LEAD.CONTACTID = PURGE_CONTACT.SEQID
                        AND LEAD.CONTACTSITE = PURGE_CONTACT.SITEID);
    
    INSERT INTO DUP_REF SELECT SEQID,SITEID
    FROM PURGE_CONTACT
    WHERE EXISTS (SELECT *
                  FROM MAPRESULT
                  WHERE MAPRESULT.CONTACTSEQ = PURGE_CONTACT.SEQID
                        AND MAPRESULT.CONTACTSITE = PURGE_CONTACT.SITEID);
    
    INSERT INTO DUP_REF SELECT SEQID,SITEID
    FROM PURGE_CONTACT
    WHERE EXISTS (SELECT *
                  FROM USERS
                  WHERE USERS.CONTACTID = PURGE_CONTACT.SEQID
                        AND USERS.CONTACTSITE = PURGE_CONTACT.SITEID);
    
    INSERT INTO DUP_REF SELECT SEQID,SITEID
    FROM PURGE_CONTACT
    WHERE EXISTS (SELECT *
                  FROM PLAYER
                  WHERE PLAYER.CONTACTID = PURGE_CONTACT.SEQID
                        AND PLAYER.CONTACTSITE = PURGE_CONTACT.SITEID);
    
    INSERT INTO DUP_REF SELECT SEQID,SITEID
    FROM PURGE_CONTACT
    WHERE EXISTS (SELECT *
                  FROM SHOPPINGCART
                  WHERE SHOPPINGCART.CONTACT_SEQID = PURGE_CONTACT.SEQID
                        AND SHOPPINGCART.CONTACT_SITEID = PURGE_CONTACT.SITEID);
    
    INSERT INTO CONTACT_REF SELECT DISTINCT SEQID,SITEID FROM DUP_REF;
    
    EXECUTE IMMEDIATE 'DROP TABLE DUP_REF';
    
    DELETE FROM PURGE_CONTACT
    WHERE EXISTS (SELECT *
    			  FROM CONTACT_REF
    			  WHERE CONTACT_REF.SEQID = PURGE_CONTACT.SEQID
    					AND CONTACT_REF.SITEID = PURGE_CONTACT.SITEID);
    
    COMMIT;
    END CONTACT_REFERENCES;

`