Oracle中虚拟专用数据控制方法研究
应用程序上下文 VPDCTX 的属性 MAXBAL 可以在会话的前期设定,而函数在运行时可以容易地获得该数值。
请仔细注意该示例。谓词有两部分:小于号之前的部分和之后的部分。之前的部分是“balance”一词,它是文字符。后面的部分从某种程度而言是静态的,因为应用程序上下文变量在改变之前一直是常量。如果应用程序上下文属性不变,则整个谓词是常量,因此不需要重新执行函数。如果策略类型定义为对上下文敏感,则 Oracle 数据库 10g 可以识别此情况以用于优化。如果在会话期间没有发生会话上下文的变化,则不重新执行该函数,从而显著提高了性能。
有时业务操作可以确保谓词更加静态。例如,在上下文敏感的策略类型示例中,我们将用户所见的最大余额定义为一个变量。当 web 应用程序中的 Oracle userid 由许多 web 用户共享,并且应用程序基于这些用户的权限来设置该变量(应用程序上下文)时,这种方法很有用。因此,web 用户 TAO 和 KARTHIK 都是以用户 APPUSER 连接到数据库的,二者可以在其会话中拥有两个不同的应用程序上下文的值。此时 MAXBAL 的值并不依赖于 Oracle userid,而是依赖 TAO 和 KARTHIK 各自的会话。
在静态策略的情况下,谓词更具有可预测性,其说明如下。
LORA 和 MICHELLE 分别是 Acme Bearings 和 Goldtone Bearings 的帐户管理员。当他们连接数据库时,他们使用自己的 id,并且只应该看到属于他们的那些行。在 Lora 方面,谓词变成 where CUST_NAME = 'ACME';而对于 Michelle,则是 where CUST_NAME = 'GOLDTONE'。在这里,谓词依赖于他们的 userid,因此他们所创建的任何会话在应用程序上下文中始终具有相同的值。
10g 可以利用这种情况,在 SGA 中对谓词进行高速缓存,并在会话中重用该谓词,而不必重新执行策略函数。策略函数类似于以下形式:
create or replace vpd_pol_func ( p_schema in varchar2, p_table in varchar2 ) return varchar2 is begin return 'cust_name = sys_context(''vpdctx'', ''cust_name'')'; end;
而策略定义为:
policy_type => dbms_rls.static
这种方法确保策略函数只执行一次。即使应用程序上下文在会话中改变,也从不重新执行该函数,使得此过程的速度非常快。
建议将静态策略用于在几个用户中托管应用程序的情况。在这种情况下,单个数据库拥有几个用户的数据。当每个用户登录时,登录后触发器可以设置用于策略函数的应用程序上下文的值,以便快速生成谓词。
但是,将策略定义为静态也是一把双刃剑。在以上的示例中,我们假设应用程序上下文属性 VPDCTX.CUST_NAME 的值在会话中不改变。如果这种假设不正确,将会怎样呢?如果该值改变,策略函数将不会执行,因此在谓词中将不会使用新值,而返回错误的结果!因此,在将策略定义为静态时要非常小心;您必须绝对确信该值不会改变。如果您不能作这种假设,则最好将策略定义为对上下文敏感。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

An AWR report is a report that displays database performance and activity snapshots. The interpretation steps include: identifying the date and time of the activity snapshot. View an overview of activities and resource consumption. Analyze session activities to find session types, resource consumption, and waiting events. Find potential performance bottlenecks such as slow SQL statements, resource contention, and I/O issues. View waiting events, identify and resolve them for performance. Analyze latch and memory usage patterns to identify memory issues that are causing performance issues.

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

Deleting all data in Oracle requires the following steps: 1. Establish a connection; 2. Disable foreign key constraints; 3. Delete table data; 4. Submit transactions; 5. Enable foreign key constraints (optional). Be sure to back up the database before execution to prevent data loss.

The steps to open an Oracle database are as follows: Open the Oracle database client and connect to the database server: connect username/password@servername Use the SQLPLUS command to open the database: SQLPLUS
