alter session set current_schema 指令

 

SQL> conn scott/tiger
Connected to Oracle9i Enterprise Edition Release 9.2.0.1.0
Connected as scott

SQL>  create table test(name char(10));

Table created

SQL> create table system.test(name char(10));

Table created

SQL>  insert into test values('scott');

1 row inserted

SQL>  insert into system.test values('system');

1 row inserted

SQL>
SQL> commit;

Commit complete

SQL> conn system/manager
Connected to Oracle9i Enterprise Edition Release 9.2.0.1.0
Connected as system

SQL> select * from test;

NAME
----------------------------------------
system

SQL> alter session set current_schema = scott;

Session altered

SQL>  select * from test;

NAME
----------------------------------------
scott

user即oracle中的用户,和所有系统的中用户概念类似,用户所持有的是系统的权限及资源;而schema所涵盖的是各种对象,它包含了表、函数、包等等对象的“所在地”,并不包括对他们的权限控制。好比一个房子,里面放满了家具,对这些家具有支配权的是房子的主人(user),而不是房子(schema)。你可以也是一个房子的主人(user),拥有自己的房子(schema)。可以通过alter session的方式进入别人的房子。这个时候,你可以看到别人房子里的家具(desc)。如果你没有特别指定的话,你所做的操作都是针对你当前所在房子中的东西。至于你是否有权限使用(select)、搬动(update)或者拿走(delete)这些家具就看这个房子的主人有没有给你这样的权限了,或者你是真个大厦(DB)的老大(DBA)。
alter session set schema可以用来代替synonyms。如果你想调用其他schema的对象(有权限的前提下),又没建synonym,有不想把其他schema名字放如代码中,就可以先alter session set schema=<其他schema名字>。

posted @ 2013-10-12 10:49  flydico  阅读(2462)  评论(0编辑  收藏  举报