title: Expected UDT got NUMBER in Virtual Private Database Policy
body: <p>I have following problem:
  I want to implement a 'Row Level Security Policy' to a table in my database and added this function:</p>
  
  <pre><code>FUNCTION app_user_is_master_owner(
      schema_in IN VARCHAR2,
      object_in IN VARCHAR
  )
  RETURN VARCHAR2
  IS  return_value VARCHAR2(100);
  BEGIN
  SELECT 'OWNER_FK = ' || 
      (SELECT mo.owner_id 
      FROM MASTER_OWNER mo
      WHERE upper(mo.owner_name) = SYS_CONTEXT('USERENV', 'SESSION_USER')) ||
      ' OR OWNER_FK IS EMPTY' 
      INTO return_value
      FROM DUAL;
  RETURN return_value;
  END app_user_is_master_owner;
  </code></pre>
  
  <p>I called ADD_POLICY from DBMS_RLS to add it to the other policys </p>
  
  <pre><code> BEGIN
   DBMS_RLS.ADD_POLICY(
   object_schema =&gt; 'MY_SCHEMA',
   object_name =&gt; 'MASTER_DATA',
   policy_name =&gt; 'app_user_is_mo_policy',
   function_schema =&gt; 'MY_SCHEMA',
   policy_function =&gt; 'MY_RLS_POLICYS.app_user_is_master_owner',
   statement_types =&gt; 'SELECT, INSERT, UPDATE, DELETE'
   );
   END;
  </code></pre>
  
  <p>When I call the function within sql plus without adding it as RLS Policy the expected 'where' clause is returned</p>
  
  <pre><code>SQL&gt; select my_rls_policys.app_user_is_master_owner('A','A') from dual;
   MY_RLS_POLICYS.APP_USER_IS_MASTER_OWNER('A','A')
   --------------------------------------------------------------------------------
   OWNER_FK = 4000 OR OWNER_FK IS EMPTY
  </code></pre>
  
  <p>but if I call it as a VPD-Policy there is this error message.</p>
  
  <pre><code>SQL&gt; SELECT * FROM MASTER_DATA;
  SELECT * FROM MASTER_DATA
                          *
  ERROR at line 1:
  ORA-00932: inconsistent datatypes: expected UDT got NUMBER
  </code></pre>
  
  <p>I guess it's because the result is a Select and not a VARCHAR, but adding TO_CHAR to neither the "select to_char(...) into return_value" nor "return TO_CHAR(return_value)" seems to solve the problem.</p>
  
  <p>Other policys works just fine.</p>
  
  <p>Thanks for your help.</p>
  
  <p>Matthias</p>