?
Solved

ORA-28113: policy predicate has error

Posted on 2011-04-20
4
Medium Priority
?
3,490 Views
Last Modified: 2012-05-11

CREATE OR REPLACE PACKAGE jgottumu.scott_dept_context AS
  PROCEDURE set_dept;
END;
/

CREATE OR REPLACE PACKAGE BODY jgottumu.scott_dept_context AS
  PROCEDURE set_dept IS
  BEGIN
    DBMS_SESSION.SET_CONTEXT(
             'which_depts',
             'dept_no',
             20);
  END set_dept;
END;
/

CREATE CONTEXT which_depts USING scott_dept_context;
       
CREATE OR REPLACE PACKAGE dept_pkg AS
  FUNCTION secure(
    p_owner VARCHAR2,
    p_object VARCHAR2)
    RETURN VARCHAR2;
END;        

CREATE OR REPLACE PACKAGE BODY dept_pkg AS
  FUNCTION secure(
    p_owner VARCHAR2,
    p_object VARCHAR2)
  RETURN VARCHAR2 IS
    v_where VARCHAR2 (2000);
  BEGIN
    v_where := 'dept_no = SYS_CONTEXT(''which_depts'', ''dept_no'')';
    RETURN v_where;
  END;
END;


BEGIN

  DBMS_RLS.ADD_POLICY (
    object_schema => 'jgottumu',
    object_name => 'emp',
    policy_name => 'dept_pl',
    policy_function =>'dept_pkg.secure',
    statement_types => 'select');

END;
/

SELECT * FROM EMP;

I am getting error ORA-28113: policy predicate has error when i am trying to run SELECT * FROM EMP;


0
Comment
Question by:sumanth_ora
  • 2
4 Comments
 
LVL 11

Expert Comment

by:yuching
ID: 35438949
in function dept_pkg.secure, try to put a space before dept_no

  v_where := ' dept_no = SYS_CONTEXT(''which_depts'', ''dept_no'')';
0
 
LVL 11

Expert Comment

by:yuching
ID: 35438978
sorry kindly ignore my comments above, when u login in the db, try select SYS_CONTEXT(''which_depts'', ''dept_no'') from dual, is any error returned?
0
 
LVL 4

Expert Comment

by:devind
ID: 35439533
replace exiting v_where with following

 v_where := 'SYS_CONTEXT('||q'['which_depts']'||','||q'['dept_no']'||') = '||q'[dept_no]';

refer: http://forums.oracle.com/forums/thread.jspa?threadID=1117535&tstart=0
0
 
LVL 78

Accepted Solution

by:
slightwv (䄆 Netminder) earned 2000 total points
ID: 35440024
Not sure about your schema but my EMP table's column is DEPTNO not DEPT_NO.

Try making this small change:
    v_where := 'deptno = SYS_CONTEXT(''which_depts'', ''dept_no'')';


I tested your code using 10.2.0.3.

Below is the complete example.
CREATE OR REPLACE PACKAGE scott_dept_context AS
  PROCEDURE set_dept;
END;
/

CREATE OR REPLACE PACKAGE BODY scott_dept_context AS
  PROCEDURE set_dept IS
  BEGIN
    DBMS_SESSION.SET_CONTEXT(
             'which_depts', 
             'dept_no', 
             20);
  END set_dept;
END;
/

drop CONTEXT which_depts;
CREATE CONTEXT which_depts USING scott_dept_context;
       
CREATE OR REPLACE PACKAGE dept_pkg AS
  FUNCTION secure(
    p_owner VARCHAR2, 
    p_object VARCHAR2)
    RETURN VARCHAR2;
END;        
/

CREATE OR REPLACE PACKAGE BODY dept_pkg AS
  FUNCTION secure(
    p_owner VARCHAR2, 
    p_object VARCHAR2)
  RETURN VARCHAR2 IS
    v_where VARCHAR2 (2000);
  BEGIN
    v_where := 'deptno = SYS_CONTEXT(''which_depts'', ''dept_no'')';
	

    RETURN v_where;
  END;
END;
/


BEGIN
  DBMS_RLS.DROP_POLICY (
    object_schema => 'SCOTT',
    object_name => 'emp',
    policy_name => 'dept_pl'
    );

  DBMS_RLS.ADD_POLICY (
    object_schema => 'SCOTT',
    object_name => 'emp',
    policy_name => 'dept_pl',
    policy_function =>'dept_pkg.secure',
    statement_types => 'select');

END;
/

--no rows becuase context isn't set
SELECT * FROM EMP;

exec scott_dept_context.set_dept;
SELECT * FROM EMP;

Open in new window

0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Via a live example, show how to take different types of Oracle backups using RMAN.
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question