這篇文章主要講解了“Oracle VPD的相關(guān)功能有哪些”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“Oracle VPD的相關(guān)功能有哪些”吧!
成都創(chuàng)新互聯(lián)憑借在網(wǎng)站建設(shè)、網(wǎng)站推廣領(lǐng)域領(lǐng)先的技術(shù)能力和多年的行業(yè)經(jīng)驗(yàn),為客戶提供超值的營銷型網(wǎng)站建設(shè)服務(wù),我們始終認(rèn)為:好的營銷型網(wǎng)站就是好的業(yè)務(wù)員。我們已成功為企業(yè)單位、個(gè)人等客戶提供了成都網(wǎng)站制作、成都做網(wǎng)站、外貿(mào)營銷網(wǎng)站建設(shè)服務(wù),以良好的商業(yè)信譽(yù),完善的服務(wù)及深厚的技術(shù)力量處于同行領(lǐng)先地位。
測(cè)試用的數(shù)據(jù)表使用Oracle的示例Schema Scott中的emp和dept:
SCOTT-orcl@DESKTOP-V430TU3>desc emp Name Null? Type ----------------------------------------- -------- ---------------------------- EMPNO NOT NULL NUMBER(4) ENAME VARCHAR2(10) JOB VARCHAR2(9) MGR NUMBER(4) HIREDATE DATE SAL NUMBER(7,2) COMM NUMBER(7,2) DEPTNO NUMBER(2) SCOTT-orcl@DESKTOP-V430TU3>desc dept Name Null? Type ----------------------------------------- -------- ---------------------------- DEPTNO NOT NULL NUMBER(2) DNAME VARCHAR2(14) LOC VARCHAR2(13) SCOTT-orcl@DESKTOP-V430TU3>set pagesize 100 SCOTT-orcl@DESKTOP-V430TU3>SELECT e.deptno, d.dname, ENAME, JOB, SAL, COMM 2 FROM emp e, dept d 3 WHERE d.deptno = e.deptno; DEPTNO DNAME ENAME JOB SAL COMM ---------- -------------- ---------- --------- ---------- ---------- 10 ACCOUNTING KING PRESIDENT 5000 10 ACCOUNTING CLARK MANAGER 2450 10 ACCOUNTING MILLER CLERK 1300 20 RESEARCH FORD ANALYST 3000 20 RESEARCH SMITH CLERK 800 20 RESEARCH JONES MANAGER 2975 30 SALES JAMES CLERK 950 30 SALES TURNER SALESMAN 1500 0 30 SALES MARTIN SALESMAN 1250 1400 30 SALES WARD SALESMAN 1250 500 30 SALES ALLEN SALESMAN 1600 300 30 SALES BLAKE MANAGER 2850 12 rows selected.
過濾允許范圍外的行
假設(shè)我們希望SALES部門只能看到自己部門的數(shù)據(jù),不能看到其他部門的數(shù)據(jù),按照上一節(jié)介紹的內(nèi)容,可以創(chuàng)建相應(yīng)的函數(shù),添加相應(yīng)的訪問策略即可。
創(chuàng)建函數(shù)
SCOTT-orcl@DESKTOP-V430TU3>CREATE OR REPLACE FUNCTION hide_sal_comm ( 2 v_schema IN VARCHAR2, 3 v_objname IN VARCHAR2) 4 5 RETURN VARCHAR2 AS 6 con VARCHAR2 (200); 7 8 BEGIN 9 con := 'deptno=30'; 10 RETURN (con); 11 END hide_sal_comm; 12 / Function created.
添加策略
SCOTT-orcl@DESKTOP-V430TU3>BEGIN 2 DBMS_RLS.DROP_POLICY( 3 object_schema => 'scott', 4 object_name => 'emp', 5 policy_name => 'hide_sal_policy'); 6 END; 7 / BEGIN * ERROR at line 1: ORA-28102: policy does not exist ORA-06512: at "SYS.DBMS_RLS", line 59 ORA-06512: at line 2 SCOTT-orcl@DESKTOP-V430TU3>BEGIN 2 DBMS_RLS.ADD_POLICY( 3 object_schema => 'scott', 4 object_name => 'emp', 5 policy_name => 'hide_sal_policy', 6 policy_function => 'hide_sal_comm'); 7 END; 8 / PL/SQL procedure successfully completed.
查詢驗(yàn)證
SCOTT-orcl@DESKTOP-V430TU3>SELECT e.deptno, d.dname, ENAME, JOB, SAL, COMM 2 FROM emp e, dept d 3 WHERE d.deptno = e.deptno; DEPTNO DNAME ENAME JOB SAL COMM ---------- -------------- ---------- --------- ---------- ---------- 30 SALES ALLEN SALESMAN 1600 300 30 SALES WARD SALESMAN 1250 500 30 SALES MARTIN SALESMAN 1250 1400 30 SALES BLAKE MANAGER 2850 30 SALES TURNER SALESMAN 1500 0 30 SALES JAMES CLERK 950 6 rows selected.
返回的數(shù)據(jù)均為SALES部門中的數(shù)據(jù)。
涉及到敏感列時(shí),過濾允許范圍外的行
假設(shè)這一次我們希望在查詢某些敏感列時(shí)才過濾,而不查詢這些列時(shí)就不過濾。VPD通過在添加策略時(shí)指定sec_relevant_cols實(shí)現(xiàn)。
添加策略
SCOTT-orcl@DESKTOP-V430TU3>BEGIN 2 DBMS_RLS.DROP_POLICY( 3 object_schema => 'scott', 4 object_name => 'emp', 5 policy_name => 'hide_sal_policy'); 6 END; 7 / PL/SQL procedure successfully completed. SCOTT-orcl@DESKTOP-V430TU3> SCOTT-orcl@DESKTOP-V430TU3> SCOTT-orcl@DESKTOP-V430TU3>BEGIN 2 DBMS_RLS.ADD_POLICY( 3 object_schema => 'scott', 4 object_name => 'emp', 5 policy_name => 'hide_sal_policy', 6 policy_function => 'hide_sal_comm', 7 sec_relevant_cols =>' sal,comm'); 8 END; 9 / PL/SQL procedure successfully completed. SCOTT-orcl@DESKTOP-V430TU3>
查詢驗(yàn)證
-- 不涉及敏感列 SCOTT-orcl@DESKTOP-V430TU3>SELECT e.deptno,ENAME, d.dname, JOB 2 FROM emp e, dept d 3 WHERE d.deptno = e.deptno; DEPTNO ENAME DNAME JOB ---------- ---------- -------------- --------- 10 KING ACCOUNTING PRESIDENT 10 CLARK ACCOUNTING MANAGER 10 MILLER ACCOUNTING CLERK 20 FORD RESEARCH ANALYST 20 SMITH RESEARCH CLERK 20 JONES RESEARCH MANAGER 30 JAMES SALES CLERK 30 TURNER SALES SALESMAN 30 MARTIN SALES SALESMAN 30 WARD SALES SALESMAN 30 ALLEN SALES SALESMAN 30 BLAKE SALES MANAGER 12 rows selected. -- 涉及敏感列 1 SELECT e.deptno, d.dname, ENAME, JOB, SAL, COMM 2 FROM emp e, dept d 3* WHERE d.deptno = e.deptno SCOTT-orcl@DESKTOP-V430TU3>/ DEPTNO DNAME ENAME JOB SAL COMM ---------- -------------- ---------- --------- ---------- ---------- 30 SALES ALLEN SALESMAN 1600 300 30 SALES WARD SALESMAN 1250 500 30 SALES MARTIN SALESMAN 1250 1400 30 SALES BLAKE MANAGER 2850 30 SALES TURNER SALESMAN 1500 0 30 SALES JAMES CLERK 950 6 rows selected.
不涉及敏感列時(shí),返回所有行,而涉及敏感列時(shí),則返回可訪問范圍內(nèi)的行,過濾范圍外的行。
涉及到敏感列數(shù)據(jù)時(shí),脫敏敏感數(shù)據(jù)
最后,假設(shè)我們希望在查詢某些敏感列時(shí)不過濾,但不能顯示數(shù)據(jù),而只能輸出NULL。VPD通過在添加策略時(shí)指定sec_relevant_cols和sec_relevant_cols_opt實(shí)現(xiàn)。
添加策略
SCOTT-orcl@DESKTOP-V430TU3>BEGIN 2 DBMS_RLS.DROP_POLICY( 3 object_schema => 'scott', 4 object_name => 'emp', 5 policy_name => 'hide_sal_policy'); 6 END; 7 / PL/SQL procedure successfully completed. SCOTT-orcl@DESKTOP-V430TU3> SCOTT-orcl@DESKTOP-V430TU3>BEGIN 2 DBMS_RLS.ADD_POLICY( 3 object_schema => 'scott', 4 object_name => 'emp', 5 policy_name => 'hide_sal_policy', 6 policy_function => 'hide_sal_comm', 7 sec_relevant_cols =>' sal,comm', 8 sec_relevant_cols_opt => dbms_rls.ALL_ROWS); 9 END; 10 / PL/SQL procedure successfully completed.
查詢驗(yàn)證
SCOTT-orcl@DESKTOP-V430TU3>SELECT e.deptno,ENAME, d.dname, JOB, SAL, COMM 2 FROM emp e, dept d 3 WHERE d.deptno = e.deptno; DEPTNO ENAME DNAME JOB SAL COMM ---------- ---------- -------------- --------- ---------- ---------- 10 KING ACCOUNTING PRESIDENT 10 CLARK ACCOUNTING MANAGER 10 MILLER ACCOUNTING CLERK 20 FORD RESEARCH ANALYST 20 SMITH RESEARCH CLERK 20 JONES RESEARCH MANAGER 30 JAMES SALES CLERK 950 30 TURNER SALES SALESMAN 1500 0 30 MARTIN SALES SALESMAN 1250 1400 30 WARD SALES SALESMAN 1250 500 30 ALLEN SALES SALESMAN 1600 300 30 BLAKE SALES MANAGER 2850 12 rows selected.
可以看到,允許范圍內(nèi)(SALES部門)的行,SAL和COMM都可以正常顯示數(shù)據(jù),而范圍外的數(shù)據(jù)全部為NULL。
感謝各位的閱讀,以上就是“Oracle VPD的相關(guān)功能有哪些”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)Oracle VPD的相關(guān)功能有哪些這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!