日期:2014-05-16  浏览次数:20442 次

oracle_创建create_user_及授权grant_查看登陆的用户
oracle 创建create user 及授权grant 查看登陆的用户:

以下都可以: 
  show   user; 
  select   sys_context('userenv','session_user')   from   dual; 
  select   user   from   dual;   

  查看所有登录的用户必须为DBA 用户: 
  select   username   from   v$session;

sys、system等DBA 用户查看 其他用户(test)中的对象(表):
SQL> select * from test.student;


创建一个普通用户都把该用户用起来的流程:
1、创建用户
SQL>create user test identified by test;
这样就创建了一个用户名密码都为test的用户
但这个时候test还是不能登陆成功的,我们需要赋予相应的权限

2、赋予create session的权限
SQL>grant create session to test;
这样test用户就能成功登陆进去

给所有的权限:grant connect,resource,dba to business;
但是此时用户还是不能创建表 我们需要赋予用户创建表的权限:
SQL>grant create table to test;
但是用户此时还不能创建表 因为需要有使用表空间的权限(相当于 用户有了进房间的钥匙 但是没有进大门的钥匙。。。)

所以也应该赋予相应的权限
SQL>grant unlimited tablespace to test;
这个时候用户就拥有了创建表的权限 由于表是用户test的 相应的他就拥有了对创建的表的增删查改的权限了

3、查看用户拥有什么权限可以通过查询一个系统的视图(数字字典)
SQL>select * from user_sys_privs;
这样就可以知道当前用户的权限

4、撤销权限
SQL> revoke create table from test;

-----------------------------
一些常用视图的区分
dba_tables  dba_all_tables  user_tables  user_all_tables  all_tables  all_all_tables
当前用户所属的所有表(注意大写)
SQL> select tablespace_name,table_name from user_all_tables where table_name='STUDENT';
SQL> select table_name,tablespace_name from user_tables where table_name='STUDENT';
TABLE_NAME                     TABLESPACE_NAME
------------------------------ ------------------------------
STUDENT                        USERS

sys 要查看dba_all_tables,ALL_ALL_TABLES才能查看到 test 用户的表。
SQL> select owner,table_name,tablespace_name from dba_all_tables where owner='TEST';
SQL> select owner,table_name,tablespace_name from all_all_tables where owner='TEST';
SQL> select owner,table_name,tablespace_name from dba_tables  where owner='TEST';
SQL> select owner,table_name,tablespace_name from ALL_tables  where owner='TEST';
OWNER                          TABLE_NAME                     TABLESPACE_NAME
------------------------------ ------------------------------ ------------------------------
TEST                           STUDENT                        USERS

1.DBA_ALL_TABLES describes all object tables and relational tables in the database. Its columns are the same as those in ALL_ALL_TABLES.
2.ALL_ALL_TABLES describes the object tables and relational tables accessible to the current user.
3.USER_ALL_TABLES describes the object tables and relational tables owned by the current user. Its columns (except for OWNER) are the same as those in
ALL_ALL_TABLES.
----------------------------------

情景一:
用户test 用户test1
test1的用户创建了个表mytab 并且插入了一些数据
那么 test用户是否可以访问到test1的mytab怎么访问?
答:不可以,必须先授权
test1必须授权给test :grant select on mytab to test;
那么这个时候test可以通过 select * from test1.mytab;来访问mytab中的数据
如果想把某个表(对象)的所有权限都赋予给test那么可以:
grant al