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名字>。