1) 定義:session
a schema is a collection of database objects (used by a user) Schema objects are the logical structures that directly refer to the database's data.oracle
a user is a name defined in the database that can connect to and access objects. 函數
2) 關係:對象
oracle 中 一個用戶 有一個缺省的 schema,其schema 名 就等於 用戶名。資源
如 用戶user1訪問表:權限控制
select * from user1.emp ---------訪問user1 的schema集合中的對象empio
select * from emp -----------------不加集合名,默認訪問本身的schema 集合的emp,即 user1 的 empsed
select * from user2.emp --------訪問 user2的schema集合的對象 empobject
3) 比喻date
user 是oracle 中的用戶,所持有的是系統的權限和資源;
schema 是涵蓋了各類對象的集合,包括 表 、函數、和包等對象的 所在地,不包括權限控制。
比如一個房子,裏面放滿了傢俱,對這些傢俱備支配權的是房子的主人(user),而不是房子(schema)。
你能夠是一個房子的主人(user),擁有本身的房子(schema).
也能夠經過alter session的方式進入別人的房子。若是你沒有特別指定的話,你所作的操做都是針對你當前所在房子中的東西。
至於你是否有權限使用(select)、搬動(update)或者拿走(delete)這些傢俱就看這個房子的主人有沒有給你這樣的權限了,
或者你是整個大廈(DB)的老大(DBA)。alter session set schema能夠用來代替synonyms。
若是你想調用其餘schema的對象(有權限的前提下),但並無建synonym,同時又不想把其餘 schema名字放入代碼中,
就能夠首先使用alter session set schema=<其餘schema名字>。