Oracle中常用的命令语句

原文链接 Oracle中常用的命令语句

 

Oracle中常用的命令语句

1.创建用户
create user 用户名 identified by 密码 
注意:用户名和密码最好是英文
如:create user sms identified by sms;

2.创建表空间
create tablespace 表空间名 datafile '存放路径' size 大小
如:create tablespace ts_sms datafile 'F:\quanxianguanliruanjian\oracle\tablespace\sms.dbf' size 100m;

3.把表空间赋值给刚创建的用户
alter user 用户 default tablespace 表空间
如:alter user sms default tablespace ts_sms;

4.给用户赋权
grant create session,create view,create table,unlimited tablespace to 用户
如:grant create session,create view,create table,unlimited tablespace to sms;
或者直接把DBA的权限全部赋值给用户,这样用户就有了创建序列等权限
grant dba to user; 如:grant dba to sms;

5.切换到新建的用户登录
conn 用户/密码
如:conn sms/sms;
其中1——5是新建用户,到导入sql之间的过程。

6.删除用户
drop user 用户名
如:drop user sms;

7.修改用户的密码
alter user 用户名 identified by 新密码
如:alter user test identified by test;

8.查看所有的用户
select * from dba_users; 或者 select * from all_users; 或者 select * from user_users;
其中select * from user_users;只能看当前的用户

9.查看当前用户或DBA角色的权限
select * from user_sys_privs;select * from dba_sys_privs;

10.查看表空间的容量
SQL> selecttablespace_name "表空间" , bytes/1024/1024 "总容量MB" fromdba_data_files;
结果如下:

11.查看表空间的使用情况,剩余情况
SQL> selecta.tablespace_name as 表空间, a.bytes/1024/1024 as 总容量MB ,(a.bytes-b.bytes)/1024/1024 "使用容量MB",b.bytes/1024/1024 "剩余容量MB",round(((a.bytes-b.bytes)/a.bytes)*100,2) "使用百分比" from (select tablespace_name,sum(bytes) bytes fromdba_data_files group by tablespace_name) a,(select tablespace_name,sum(bytes)bytes,max(bytes) largest from dba_free_space group by tablespace_name) b where a.tablespace_name=b.tablespace_nameorder by ((a.bytes-b.bytes)/a.bytes) desc;


12. 查看被锁定的进程:
select 'alter system kill session '''||sid||','||serial#||''';' from v$session where sid in (select sid from v$lock where block = 1);
结果如下:若有则出现锁定的进程如下面,没有则提示会“未选定的行”
'ALTERSYSTEMKILLSESSION'''||SID||','||SERIAL#||''';'
--------------------------------------------------------------------------------
alter system kill session '136,18257';
杀死锁定的进程:
SQL> alter system kill session '136,18257';

猜你喜欢

转载自notejs.iteye.com/blog/2038510