Vous êtes sur la page 1sur 2

ops$tkyte%ORA10GR2> create table t

2 as
3 select empno ssn, ename nm, hiredate, job, deptno
4 from scott.emp
5 where rownum <= 5
6 /
Table created.
ops$tkyte%ORA10GR2>
ops$tkyte%ORA10GR2> create or replace function foo( p_owner in varchar2, p_name
in
varchar2 ) return varchar2
2 as
3 begin
4 if sys_context( 'userenv', 'session_user' ) = 'OPS$TKYTE'
5 then
6 return null;
7 else
8 return '1=0';
9 end if;
10 end;
11 /
Function created.
ops$tkyte%ORA10GR2> select * from t;
SSN NM HIREDATE JOB DEPTNO
---------- ---------- --------- --------- ----------
7369 SMITH 17-DEC-80 CLERK 20
7499 ALLEN 20-FEB-81 SALESMAN 30
7521 WARD 22-FEB-81 SALESMAN 30
7566 JONES 02-APR-81 MANAGER 20
7654 MARTIN 28-SEP-81 SALESMAN 30
ops$tkyte%ORA10GR2> BEGIN
2 DBMS_RLS.ADD_POLICY(object_schema=>user, object_name=>'T',
3 policy_name=>'SEC_SSN',
4 function_schema=>user,
5 policy_function=>'foo',
6 sec_relevant_cols=>'ssn',
7 sec_relevant_cols_opt=>dbms_rls.ALL_ROWS);
8 END;
9 /
PL/SQL procedure successfully completed.
ops$tkyte%ORA10GR2> select * from t;
SSN NM HIREDATE JOB DEPTNO
---------- ---------- --------- --------- ----------
7369 SMITH 17-DEC-80 CLERK 20
7499 ALLEN 20-FEB-81 SALESMAN 30
7521 WARD 22-FEB-81 SALESMAN 30
7566 JONES 02-APR-81 MANAGER 20
7654 MARTIN 28-SEP-81 SALESMAN 30
ops$tkyte%ORA10GR2> grant all on t to public;
Grant succeeded.
ops$tkyte%ORA10GR2> connect scott/tiger
Connected.
scott%ORA10GR2> insert into ops$tkyte.t (ssn, nm, hiredate, job, deptno ) values
( 1234,
'x', sysdate, 'y', 40 );
1 row created.
scott%ORA10GR2> select * from ops$tkyte.t;
SSN NM HIREDATE JOB DEPTNO
---------- ---------- --------- --------- ----------
SMITH 17-DEC-80 CLERK 20
ALLEN 20-FEB-81 SALESMAN 30
WARD 22-FEB-81 SALESMAN 30
JONES 02-APR-81 MANAGER 20
MARTIN 28-SEP-81 SALESMAN 30
x 05-AUG-09 y 40
6 rows selected.
scott%ORA10GR2> connect /
Connected.
ops$tkyte%ORA10GR2> select * from t;
SSN NM HIREDATE JOB DEPTNO
---------- ---------- --------- --------- ----------
7369 SMITH 17-DEC-80 CLERK 20
7499 ALLEN 20-FEB-81 SALESMAN 30
7521 WARD 22-FEB-81 SALESMAN 30
7566 JONES 02-APR-81 MANAGER 20
7654 MARTIN 28-SEP-81 SALESMAN 30
1234 x 05-AUG-09 y 40
6 rows selected.