An Application Context example
Creating a Context
Context is a set of session-based attributes that can be only set by the package specified in CREATE CONTEXT statement.
CREATE CONTEXT app1_ctx USING app1_ctx_package;
In this example, only procedures and functions of app1_ctx_package package are allowed to set or reset the attributes of the app1_ctx context.
Setting Attributes of Context
Only the package specified in CREATE CONTEXT statement can change attributes of the context using DBMS_SESSION.SET_CONTEXT procedure:
CREATE OR REPLACE PACKAGE app1_ctx_package IS
PROCEDURE set_empno (empno NUMBER);
END;
/
CREATE OR REPLACE PACKAGE BODY app1_ctx_package IS
PROCEDURE set_empno (empno NUMBER) IS
BEGIN
DBMS_SESSION.SET_CONTEXT('app1_ctx', 'empno', empno);
END;
END;
/
Note. You have to create the package (or just its specification) before you create the context.
An application can initialize context by calling the package procedure i.e
CALL app1_ctx_package.set_empno(11);
Restricting Data Access using Context
Assume, you have the following data:
CREATE TABLE orders (price NUMBER(10,2), empno NUMBER(5));
INSERT INTO orders VALUES (295.00, 10);
INSERT INTO orders VALUES (99.00, 11);
INSERT INTO orders VALUES (125.00, 11);
Then you can restrict access to this table, so an employee can see only own data using SYS_CONTEXT function:
SELECT * FROM orders WHERE empno = SYS_CONTEXT('app1_ctx', 'empno');
Result:
price | empno |
99 | 11 |
125 | 11 |
This example shows how application can restrict access to data by adding WHERE condition with SYS_CONTEXT function.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7734298/viewspace-709479/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 在 Swift 中使用 Watch Connectivity — Application ContextSwiftAPPContext
- why i can't success deploy struts1.1 example application to jboss3.2.5APPS3
- Android 應用啟動那些事兒,Application? Context?AndroidAPPContext
- 四大元件以及Application和Context的全面理解元件APPContext
- Android中Application和Activity的Context物件的區別AndroidAPPContext物件
- Spark exampleSpark
- oracle exampleOracle
- An example of polybase for OracleOracle
- angular 2 by exampleAngular
- Oracle By Example (OBE)Oracle
- simd example code
- An example about git hookGitHook
- react router animation exampleReact
- An Example of How Oracle WorksOracle
- [Typescript] Query builder exampleTypeScriptUI
- A example that using JQuery clonejQuery
- a simple example for spring AOPSpring
- 【RabbitMQ】direct type exchange example in golangMQGolang
- 【RabbitMQ】topic type exchange example in golangMQGolang
- 【RabbitMQ】fanout type exchange example in golangMQGolang
- openni example NiViewer opengl blockViewBloC
- Common threads: Awk by examplethread
- Amazing Algorithms with NoSQL: A MongoDB ExampleSQLMongoDB
- JDBC Connection Pool Example (轉)JDBC
- Bitmap Index Example (223)Index
- Example: How to Packetize a TCP Stream (轉)TCP
- ContextContext
- go 上下文:context.ContextGoContext
- For example, when you want to get the ball to the ground
- DB2 PL/SQL Example: RunstatsDB2SQL
- Spring 3 MVC hello world exampleSpringMVC
- 《Lua-in-ConTeXt》02:ConTeXt 計算機Context計算機
- Catch Application Exceptions in a Windows Forms ApplicationAPPExceptionWindowsORM
- 理解ContextContext
- Go ContextGoContext
- context包Context
- 聊聊ContextContext
- vpd contextContext