I am trying to make a trigger, it compiles but with 2 errors (same error different location). This is the trigger, I have the table and sequence created
create or replace TRIGGER BIU_APPLICATION
BEFORE INSERT OR UPDATE ON APPLICATION
REFERENCING FOR EACH ROW
BEGIN
IF inserting THEN IF :new.APPLICATION_ID IS NULL THEN
SELECT APPLICATION_ID_SEQ.nextval
INTO :new.APPLICATION_ID
FROM dual;
END IF;
:new.created_by := NVL(apex_application.g_user USER);
:new.created_dt := SYSDATE;
END IF;
IF inserting OR updating THEN
:new.created_by := NVL(apex_application.g_user USER);
:new.created_dt := SYSDATE;
END IF;
END;
The error I get is
PLS-00103: Encountered the symbol "USER" when expecting one of the following: . ( ) , * @ % & = – + < / > at in is mod remainder not rem => <an exponent (**)> <> or != or ~= >= <= <> and or default like like2 like4 likec as between from using || multiset member submultiset The symbol "." was substituted for "USER" to continue.
>Solution :
You forgot about "," in NVL:
NVL(apex_application.g_user, USER);
note: you don’t need select sequence.nextval by SQL. You can do this like:
:new.APPLICATION_ID := APPLICATION_ID_SEQ.nextval