title: Predicate Error with Oracle VPD/RLS
body: <p>I need some help with Oracle's RLS feature. I have never used it before but did some research online about it, however i'm running into a problem.</p>
  
  <p>Here are the steps that I have taken:</p>
  
  <p>1- Create the function:</p>
  
  <pre><code>create or replace function
     table_access_policy
     (obj_schema varchar2, obj_name varchar2) return varchar2
  
  is                
  
  v_project varchar2(2000);
  
  begin              
  
  v_project:= '(select project from users where user_name = (select sys_context(''userenv'',''session_user'') from dual))';
  
  return 'project = ' || v_project;       
  
  end;
  </code></pre>
  
  <p>2- Add the security policy</p>
  
  <pre><code>Begin
  
  DBMS_RLS.ADD_POLICY ('db1', 'data', 'access_policy', 'admin', 'table_access_policy', 'SELECT' );
  
  End;
  </code></pre>
  
  <p>3- Run a simple select query on the object</p>
  
  <pre><code>select * from db1.data
  </code></pre>
  
  <p>When I do step 3 I get the following error:</p>
  
  <p>ORA-28113: policy predicate has error
  28113. 00000 -  "policy predicate has error"
  *Cause:    Policy function generates invalid predicate.
  *Action:   Review the trace file for detailed error information.
  Error at Line: 5 Column: 14</p>
  
  <p>I don't know what could be wrong with the security function. I successfully used it manually on the db1 schema as follows:</p>
  
  <pre><code>select * from data
  where project = (select project from users where user_name = (select sys_context('userenv','session_user') from dual))
  </code></pre>
  
  <p>Any thoughts??</p>