实验室接的项目需要用到oracle数据库,但是我一直使用的是mysql,所以把这段时间总结的oracle数据库的基本操作语句在这里做一个总结。

登录用户
sqlplus system/123456@192.168.1.36/orcl as sysdba

说明:用户名是system,密码是123456,ip是192.168.1.36,orcl是数据库名,as sysdba是以dba的身份登录,如果普通用户可以省略最后的as sysdba。

创建一个新用户
SQL> create user abc identified by 123456;

说明:创建一个用户叫user,密码是123456

授予DBA权限
SQL> grant connect,resource,dba to abc;

说明:给用户abc授以connect,resource,dba的权限。

建立表空间
SQL> create tablespace tbs logging datafile '/home/colab/oracle11g/orcl/data.dbf'
  2  size 50m
  3  autoextend on
  4  next 50m maxsize unlimited;

说明:建立表空间tbs。

创建用户并赋予默认表空间
SQL> create user test identified by 123456
  2  default tablespace tbs;

说明:创建用户test密码123456并给赋予默认的表空间tbs。

创建文件夹
SQL> create directory ty_dump_dir as  '/home/colab/ty_dump_dir';

数据泵导入数据
directory=ty_dump_dir(建立要存入数据的文件夹)
impdp system/colab1234@192.168.1.110/orcl directory=ty_dump_dir dumpfile=exp_full_hebdb_szcg_20160118.dmp full=y table_exists_action=replace;
impdp system/colab1234@192.168.1.110/orcl directory=ty_dump_dir dumpfile=exp_full_hebdb_szcg_20160118.dmp full=y table_exists_action=append;

导入sql文件

在SQL_PLUS里面执行: sql>@C:/test.sql;  

说明:如果数据量比较大,就需要用到数据泵去导入数据。

修改数据库表的名字
SQL> rename name1 to name2 ;  

说明:把name1改为name2。

数据库导出文件
exp system/123456@192.168.1.207/orcl file = f:\output.dmp owner=sde
exp system/123456@192.168.1.207/orcl file=f:\output.dmp tables=SHICHANG_QUYU
exp system/123456@192.168.1.207/orcl file=f:\output.dmp tables=(SHICHANG_QUYU,SHEXIANGTOU)

说明:分别是导出具体用户的所有表;导出具体某一张表和某几张表。

数据库导入文件
imp system/123456@192.168.1.207/orcl file = f:\output.dmp  full=y
imp system/123456@192.168.1.207/orcl file=f:\output.dmp tables=SHICHANG_QUYU
imp system/123456@192.168.1.207/orcl file=f:\output.dmp tables=(SHICHANG_QUYU,SHEXIANGTOU)

查看所有用户:
SQL>select * from all_users;


查看表空间:
SQL>select tablespace_name from dba_tablespaces;


查看用户具有怎样的角***r> SQL>select * from dba_role_privs where grantee='用户名';


查看某个角色包括哪些系统权限:
SQL>select * from dba_sys_privs where grantee='DBA'


查看oracle中所有的角***r> SQL>select * from dba_roles;

展示表:
select table_name from all_tables where owner='SDE';
all_tables显示用户有权限看到的所有的表,包括系统表
dba_tables是管理员可以看到的数据库中所有的表
user_tables是当前用户的所有表,用这个可以缩小查找的范围

删除表
SQL>drop table xxxxxxxxx;

删除表的数据

SQL>delete from 表名;

退出
SQL>exit