---
title: "Oracle中常用的命令语句"
author: "notejs"
date: "2014-03-31T19:54:59Z"
tags: []
categories: ["数据库"]
slug: "oracle"
draft: false
lastmod: "2014-03-30T15:06:24Z"
id: 2038510
url: "https://notejs.iteye.com/blog/2038510"
---

# [原文链接](http://mojijs.com/2014/03/131014/index.html) [Oracle中常用的命令语句](http://mojijs.com/2014/03/131014/index.html)

# [](http://mojijs.com/)

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&gt; selecttablespace\_name "表空间" , bytes/1024/1024 "总容量MB" fromdba\_data\_files;  
结果如下：

11.查看表空间的使用情况，剩余情况  
SQL&gt; 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&gt; alter system kill session '136,18257';