Hi guys I'm new in Oracle Apex and I want to record the data based on the user id in Oracle Apex. The application has two role which is employee and manager. I want to make if the employee login to their account, they can only see and update their own record. Besides that, the manager can see all the employee record. The record data already working but not based on the user id. Anyone know how to do that? Thank you
The table structure for record data
CREATE TABLE "TIMESHEET"
( "ID" NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE NOKEEP NOSCALE NOT NULL ENABLE,
"NO" VARCHAR2(50) NOT NULL ENABLE,
"CUSTOMER" VARCHAR2(50) NOT NULL ENABLE,
"DATE_" VARCHAR2(50) NOT NULL ENABLE,
"TIME" VARCHAR2(50) NOT NULL ENABLE,
"WORKING_HOUR" VARCHAR2(50) NOT NULL ENABLE,
"PIC" VARCHAR2(50) NOT NULL ENABLE,
"TOPIC" VARCHAR2(50) NOT NULL ENABLE,
"REMARK" VARCHAR2(50),
"APP_USER" VARCHAR2(255),
PRIMARY KEY ("ID")
USING INDEX ENABLE
)
/
Data record (not based userid)
Data record (APP_User still empty)
CodePudding user response:
The best way to record the user who created the record is to use a trigger on the table TIMESHEET
. This will populate the column APP_USER you added after @Jeffrey Kemp's comment with the value of the user who did the update on insert.
create or replace trigger timesheet_biu
before insert
on timesheet
for each row
begin
:new.app_user := coalesce(sys_context('APEX$SESSION','APP_USER'),user);
end timesheet_biu;
/