您的位置:首页 > 数据库 > Oracle

Oracle常用命令

2016-03-30 17:48 417 查看
开启服务后,在控制台输入 sqlplus / as sysdba;即可直接使用sys超级管理员用户进入(可以不用密码)

备注:以下命令只在进入sqlplus工具后方可使用(它们不是dos命令,是属于oracle数据库操作命令)

1、startup命令:启动oracle服务器

startup nomount 只启动实例

startup mount 启动实例并装载数据库

startup open 启动实例装载数据库并打开数据库

例如:

startup open force 终止实例后重新启动

2、shutdown命令:关闭oracle服务器

例如:

shutdown immediate 立即关闭

3、clear screen:清屏

4、conn:切换用户连接 disc: 断开连接 exit :断开连接并退出sqlplus

conn scott/tiger

conn sys/sys as sysdba 注:sys用户必须设置连接模式为sysdba

conn / as sysdba 默认连接(默认使用sys用户)

5、set pagesize :设置数据显示每页的信息行数

set pagesize 20

6、column … format ..:设置执行列显示时占据的列数’

column ename format a20

7、show user:显示当前连接的用户

8、desc:查看表的结构 rename: 修改表的名字

desc emp

rename emp to employee

9、ed或edit:将上一次执行的sql命令显示在记事本中

10、spool:将屏幕的内容保存到指定的文件中

spool d:\1.txt

指定数据操作命令

spool off

11、start或@:运行sql脚本文件

start c:\1.sql 或 @ c:\1.sql

12、show error:显示当一个命令出现的错误信息

13、表空间操作命令

创建表空间

create tablespace mytablespace

datafile ‘d:\mytablespace01.dbf’ size 100M

删除表空间(包含表空间中的内容和文件)

drop tablespace mytablespace including contents and datafiles

14、用户操作命令

创建用户(并设置使用的表空间和临时表空间)

create user scce identified by scce default tablespace users temporay tablespace temp

删除用户

drop user scce cascade

锁定用户

alter user scce account lock

解除锁定

alter user scce account unlock

修改口令

password用于当前用户修改自己的密码

alter user scce identified by 新密码(主要用于管理员修改用户其他用户密码)

用户授权

grant connect to scce 授予连接权限

grant connect to scce with admin option 授予连接权限(并可以将系统权限授予给其他用户)

grant insert table to scce with grant option 授予插入数据权限(并可以将对象权限授予给其他用户)

grant resource to scce 授予使用表空间权限

grant select|delete|update|insert|all on 表名 to scce 授予scce访问表的权限

grant select|delete|update|insert|all on 表名 to scce with grant option 授予scce访问表的权限(权限可以下传)

(注意:授予某张表的某列update权限只包括插入和修改,不包含查询和删除)(并可以将权限授予给其他用户)

撤销权限

revoke connect from scce 撤销连接权限

revoke resource from scce 撤销使用表空间权限

revoke select|delete|update|insert|all on 表名 from scce 撤销scce方法表的权限

查看权限

select * from user_sys_privs;查看当前用户拥有的系统权限

select * from user_表名_privs;查看当前用户拥有的对象权限

select * from user_col_privs;查看当前用户拥有的某一列的权限

15、使用select语句获取系统信息

select table_name from user_tables 获取当前用户模式的数据表名

select * from user_role_privs 查看当前用户的角色

select username,default_tablespace from user_users查看当前用户使用的表空间

16、修改日期格式(oracle默认的日期格式’dd-mm-yy’,例如10-09月-2012表示2012年09月10日)

alter session set nls_date_format=’yyyy-mm-dd’ 注:只在当前连接会话中有效

为表添加一列:alter table 表名 add 字段名 类型
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: