Virtual on Virtual – VPD on virtual column
February 26, 2009 Leave a Comment
Quick test to prove that Virtual Private Database ( VPD ) works on virtual column.
Here is demo.First create test table and load it ( so lazy that I found this on google too )
/** Create table and insert some rows **/
DROP TABLE employees;
CREATE TABLE employees (
id NUMBER,
first_name VARCHAR2(10),
last_name VARCHAR2(10),
bonus NUMBER(9,2),
extra1 NUMBER(3),
extra2 NUMBER(3),
bonus1 AS (ROUND(bonus*(1+extra1/100),2)),
bonus2 NUMBER GENERATED ALWAYS AS (ROUND(bonus*(1+extra2/100),2)) VIRTUAL,
CONSTRAINT employees_pk PRIMARY KEY (id)
);
INSERT INTO employees (id, first_name, last_name, bonus, extra1, extra2)
VALUES (1, ‘MARKO’, ‘JANKO’, 100, 5, 10);
INSERT INTO employees (id, first_name, last_name, bonus, extra1, extra2)
VALUES (2, ‘JOE’, ‘JANKO’, 200, 10, 20);
COMMIT;
/** VPD role **/
drop role view_virtual;
create role view_virtual not identified;
Here is my function that will enable users witt VIEW_VIRTUAL role to view data on column BONUS2.
/** Create function **/
CREATE OR REPLACE FUNCTION secure_virtual (oowner IN VARCHAR2, ojname IN VARCHAR2)
RETURN VARCHAR2 AS
BEGIN
IF dbms_session.is_role_enabled(‘VIEW_VIRTUAL’) then
return ”;
ELSE
return ’1=0′; — don’t show column
END IF;
END secure_virtual;
/
and finally create policy Read more of this post
Recent Comments