Question

I am trying to create a view that will display information only about the current user logged in. In the emp table (employee table) I picked two employees Ford and James. I created them as users. Now i want to make sure that if Ford is logged in, that Ford will only see information pertaining to Ford and no one else from the emp table, and the same if James was logged in.

Here is what i have.

create definer=current_user view emp_view as 
  select empno, ename, job, sal, comm 
  from emp 
  where lower(ename) = lower(current_user);

Also not sure if lower(ename) = lower(current_user) will work.

i get an error

ERROR at line 1: ORA-00901: invalid CREATE command

Was it helpful?

Solution

I'm guessing you are used to some other RDBMS; as far as I know you are using non-Oracle syntax. The way I would do this in Oracle is:

CREATE VIEW emp_view AS
  SELECT empno, ename, job, sal, comm
    FROM emp
   WHERE lower(ename) = lower(user)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top