Column masking behaviour is implemented by using the "
sec_relevant_cols_opt => DBMS_RLS.ALL_ROWS
" parameter. This allows you to display all rows but mask the values of the specified columns for the restricted rowsThere are 3 steps for accomplish column masking:
- A function to be used by the policy (function policy) created in next step.
- Use dbms_rls package to create the policy.
- Assign “exempt access policy” to users to be excluded from the policy. These users can see all data with no masking.
CONN sys/password@db10g AS SYSDBA
GRANT EXECUTE ON dbms_rls TO scott; |
CONN scott/tiger@db10g
-- Create the policy function to restrict access to SAL and COMM columns -- if the employee is not part of the department 20. CREATE OR REPLACE FUNCTION pf_job (oowner IN VARCHAR2, ojname IN VARCHAR2) RETURN VARCHAR2 AS con VARCHAR2 (200); BEGIN con := 'deptno = 20'; RETURN (con); END pf_job; / |
-- Add policy
BEGIN DBMS_RLS.ADD_POLICY (object_schema => 'scott', object_name => 'emp', policy_name => 'sp_job', function_schema => 'scott', policy_function => 'pf_job', sec_relevant_cols => 'sal,comm', sec_relevant_cols_opt => DBMS_RLS.ALL_ROWS); END; / |
-- All rows are returned but the SAL and COMM values are only
-- shown for employees in department 20.
-- Remove the policy function from the table.
DBMS_RLS.DROP_POLICY (object_schema => 'scott', object_name => 'emp', policy_name => 'sp_job'); END; / |
No comments:
Post a Comment