3 Replies Latest reply: Jul 16, 2014 8:27 AM by ABD - DBA RSS

    Oracle APEX Get Username

    c64f54d6-a963-4f87-b63a-0b020ac44cf6

      I have created a basic CRUD application that users may input values into.

      There is a column called "USER_ADD_ID" that I have for users to type in their username to keep track of who is enter what. But instead of having users type that in all the time, I want to use the username they logged in with at the top right to automatically insert into the database, or pre-fill in the form.

      Are there any pointers for this?

        • 1. Re: Oracle APEX Get Username
          jwellsnh

          Hi long unreadable username; please update your profile with something a bit more personal.


          Many stamp their tables via triggers.  For example:

          CREATE OR REPLACE TRIGGER bins1_aim_asset_tbl
             BEFORE INSERT
             ON aim_asset_tbl
             FOR EACH ROW
          BEGIN
             --  *************************************************************************
             --  Description: Insert creation_dt, creation_id,
             --              lst_updt_dt and lst_updt_id
             --
             --  Maintenance:
             --
             --  Date        Actor           Action
             --  ----        -----           ------
             --  10-Feb-2011 J. Wells         Create.
             --  *************************************************************************
          
             :new.creation_id := nvl(v('app_user'), user);
             :new.creation_dt := sysdate;
             :new.lst_updt_dt := :new.creation_dt;
             :new.lst_updt_id := :new.creation_id;
          
             SELECT aim_asset_seq.nextval INTO :new.aim_asset_seq from DUAL;
          END;
          
          
          
          


          CREATE OR REPLACE TRIGGER bchg1_aim_asset_tbl
             BEFORE UPDATE
             ON aim_asset_tbl
             FOR EACH ROW
          BEGIN
             --  *************************************************************************
             --  Description: Update lst_updt_dt and lst_updt_id.
             --
             --  Maintenance:
             --
             --  Date        Actor           Action
             --  ----        -----           ------
             --  10-Feb-2011 J. Wells         Create.
          
             SELECT nvl(v('app_user'), user),
                    sysdate
               INTO :new.lst_updt_id,
                    :new.lst_updt_dt
               FROM dual;
          END;
          
          
          

           

          Jeff

          • 2. Re: Oracle APEX Get Username
            DTSIguy

            Look up APP_USER in the available HELP...you'll find 3 different ways to grab the user name.

             

            Typically, if I have a field on the page I'll set the source to v('APP_USER') and leave it at that.

            • 3. Re: Oracle APEX Get Username
              ABD - DBA

              you can also source it as &APP_USER.  and in PL/SQL as :APP_USER