Oracle policy problems

Source: Internet
Author: User

Oracle policy problems
Oracle policies can restrict query, modification, deletion, and addition operations. A test is performed on the query as follows: begin -- Call the proceduresys. dbms_rls.add_policy (object_schema =>: name of the Schema where the data table (or view) is located/user, object_name =>: name of the data table (or view), policy_name =>: policy Name function_schema =>: return the Schema name/user of the Where clause function, policy_function =>: return the function name of the Where clause, statement_types =>: DML type of the Policy to be used, such as 'select, Insert, Update, delete', update_check => only applicable to Statement_Type: 'insert, Update'; Value: 'true' or' False', enable => enable or not. The value is 'true' or 'false', and static_policy => the default value is False. If it is set to TRUE, this policy is enabled by all users, except sys or privileged users. Policy_type =>: The default value is null, which means that the value of static_policy is determined. specifying any policy here will overwrite the value of static_policy. Long_predicate => long_predicate, sec_relevant_cols =>: sensitive field name, sec_relevant_cols_opt =>: Set it to dbms_rls.ALL_ROWS to display all rows. The value of sensitive columns is null); end; create a function:

Create or replace function f_policy (p_owner in varchar2, -- two parameters must have different names: p_object in varchar2) return varchar2 as v_ SQL varchar2 (2000); begin v_ SQL: = lower (sys_context ('userenv', 'current _ SQL ', 4000); if instr (v_ SQL, 'where') = 0 then return 'deptno = 10 '; -- raise_application_error (-20001, 'contains no where condition'); end if; return ''; end;

 

Add a policy under sys ):
begindbms_rls.add_policy(object_schema => 'scott', object_name => 'emp',policy_name => 'sal', function_schema => 'scott',policy_function => 'f_policy', sec_relevant_cols => 'sal');end;

 

This policy and function combination limit the following example: select * from emp; deletion policy:
begin   sys.dbms_rls.drop_policy(object_schema => 'scott',                            object_name => 'emp',                            policy_name => 'sal'); end;

 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.