Usage of the current_schema Parameter

Source: Internet
Author: User

User A contains the table TBL. If user a grants the access permission of TBL to user B (grant selectany table to B), you must reference the table of user a in user B, if you do not use synonyms, select * from. TBL;


A. the TBL format is because the TBL table belongs to the schema of user A. To make a metaphor, the schema (translation Scheme) is like a container that stores a series of database objects, which are described in the official documents:

"A schema is a collection of database objects. A schema is owned by a database userand has the same name as that user. schema objects are the logical structures thatdirectly refer to the database's data. schema objects include structures like tables, views, and indexes. (there is no relationship between a tablespace and a schema. objects in the same schema can be in different tablespaces, and a tablespace can holdobjects from different schemas .)"

Which can be summarized as follows::

1. A schema is owned by a database user and has the same name as that user.

2. the schema object is a logical structure.

3. There is no relationship between the tablespace and schema.

4. Objects in the same schema can exist in different tablespaces. One tablespace can have objects in multiple schemas.


Another analogy is that the schema is like a room with various objects, such as tables and chairs. The owner of the room is the user/owner, by default, he has the permission to add, remove, and delete all objects in the room, but he can only allow another person to enter the room. This is authorization.


It's a little too far away. As mentioned above, user B wants to reference user a's table and does not want to use "User. in addition to synonyms, you can also use current_schema to change the schema used by the current user.

Syntax: Alter session set current_schema = Name;

Although the current mode has been changed, whether the read/write permission exists depends on whether the user is authorized. In other words, this statement cannot decide whether to change shcema, this user has the read and write permissions on the objects in the new schema.


Lab:

1. User A authorizes user B:

Grant select any table to B;

2. ModifyThe shcema of user a's current session is:

Alter session set current_schema =;

3. view the currentSession Schema:

Select sys_context ('userenv', 'current _ scheme') current_schema from dual;

>

Show user

User is "test_priv"

4. view the TBL of.:

Select * From TBL;

Everything is OK.

5. Switch the schema of the current session to SYS.:

Alter session set current_schema = sys;

Select sys_context ('userenv', 'current _ scheme') current_schema from dual;
> Sys

6. View dba_tables:

Select * From dba_tables;

Error at line 1:

ORA-00942: Table or view does not exist

User B is not authorized to access the Sys object.


Summary:

In fact, current_schema is mainly used to apply for some read-only accounts. Grant is usually used to grant users access permissions. However, if there is no synonym for access, "schema (/user) is used ). the table method is used to create synonyms for each new table. However, it is inconvenient to use current_schema.

Oracle provides a variety of general or detailed technical means, with the goal of making it easier for users to use. Therefore, I feel that when there is a problem, I can check whether workround exists, as a good software, you should have considered this issue before you think about it :)

Usage of the current_schema Parameter

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.