• dbms_rls for policy


    --示例1
    --create table
    create table t_policy(t1 varchar2(20),t2 number);

    --创建policy function
    create or replace function fn_getpolicy(
    p_schema in varchar2,
    p_object in varchar2
    )
    return varchar2
    is
    begin
    return 't2=10';
    end;

    --insert data
    insert into t_policy values ('a',10);
    insert into t_policy values ('b',10);
    insert into t_policy values ('c',20);
    commit;

    --加入policy
    begin
    dbms_rls.add_policy(
    object_schema=>'zyj',
    object_name=>'t_policy',
    policy_name=>'t_testpolicy',
    function_schema=>'zyj',
    policy_function=>'fn_getpolicy',
    statement_types=>'select,insert,update,delete',
    update_check=>true,
    enable=>true
    );
    end;
    /

    --test policy(insert and select)
    select * from t_policy;
    insert into t_policy values('d',10);
    insert into t_policy values('d',20);
    commit;

    --查看policy
    select * from user_policies;

    ------------------------------------------------------------------------------------
    --示例2
    create or replace function oe.f_get_where(
    p_owner varchar2,
    p_tablename varchar2
    )
    return varchar2
    as
    v_where varchar2(1000);
    begin
    if user like 'AM%' then
    v_where := 'OE.CUSTOMERS.account_mgr_id=substr(' || '''' || user || '''' || ',3,3)';
    end if;
    return v_where;
    end;
    /

    --
    begin
    DBMS_RLS.ADD_POLICY (
    object_schema=>'OE',
    object_name=>'customers',
    policy_name=>'fgac_policy_1',
    function_schema=>'oe',
    policy_function=>'f_get_where',
    statement_types=>'SELECT',
    enable=>TRUE
    );
    end;
    /

    --
    connect am145/AM145
    select count(*) from oe.customers;

    connect AM147/AM147
    select count(*) from oe.customers;

    connect oe/oe
    select account_mgr_id,count(*) from customers group by account_mgr_id;
    ------------------------------------------------------------------------------------

    --示例3 dbms_rls在透明加密中的应用


    ------------------------------------------------------------------------------------

    --示例4 dbms_rls vpd应用案例

  • 相关阅读:
    创建索引
    列出所有的索引
    查看集群节点api
    集群健康检查api
    mapping 映射
    Elasticsearch 版本控制
    四种常见的 POST 提交数据方式
    HttpPost 传输Json数据并解析
    基本概念
    信用卡年轻消费群体数据分析和洞察报告
  • 原文地址:https://www.cnblogs.com/buffercache/p/10817865.html
Copyright © 2020-2023  润新知