您的位置:首页 > 数据库

alter session set current_schema='XXX'语句用法

2009-11-13 11:08 525 查看
CURRENT_SCHEMA
Syntax:

CURRENT_SCHEMA = schema

The CURRENT_SCHEMA parameter changes the current schema of the session to the specified schema. Subsequent unqualified references to schema objects during the session will resolve to objects in the specified schema. The setting persists for the duration of the session or until you issue another ALTER SESSION SET CURRENT_SCHEMA statement.

This setting offers a convenient way to perform operations on objects in a schema other than that of the current user without having to qualify the objects with the schema name. This setting changes the current schema, but it does not change the session user or the current user, nor does it give you any additional system or object privileges for the session.

 

随便做了个小实验,贴出来看看。

 

SQL> create user tt1 identified by tt1;

User created.

SQL> grant connect,resource to tt1;

Grant succeeded.

SQL> conn tt1/tt1
Connected.
SQL> create table dept(id number);

Table created.

SQL> insert into dept values(1);

1 row created.

SQL> commit;

Commit complete.

SQL> select * from dept;

ID
----------
1

SQL> alter session set current_schema=scott;

Session altered.

SQL> select * from dept;
select * from dept
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> conn scott/tiger
Connected.
SQL> grant select on dept to tt1;

Grant succeeded.

SQL> conn tt1/tt1
Connected.
SQL> select * from dept;

ID
----------
1

SQL> alter session set current_schema=scott;

Session altered.

SQL> select * from dept;

DEPTNO DNAME          LOC
---------- -------------- -------------
10 ACCOUNTING     NEW YORK
20 RESEARCH       DALLAS
30 SALES          CHICAGO
40 OPERATIONS     BOSTON

SQL>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息