oracle数据库cmd导出数据和导入数据

版权所有,禁止匿名转载;禁止商业使用。

一:前言

每次我自己来导出oracle数据的数据进行备份的时候都是要看一遍记载的语句,还别说自己敲多了,也熟练了,但是还是不是很放心,所以就记载下来吧。

二:内容

(1)、最简单,最直接的导入方式(这种导入需要用户具有dba权限)

imp user/password file="H:/db_table.dmp" full=y

(2)、导出数据库的方式

A:最简单最直接的方式

exp user/password @192.168.22.22/orcl file=F:/db_table.dmp

B:指定需要导出的表(因为有的表的数据很多,所以可以有选择的导数据)

exp user/password@192.168.22.22/orcl file=F:/db_table.dmp tables=(table1,table2,table3,table4,table5,table6,table7,table8,table9,table10)

对于B的说明,file那里也可以写成这样“file=./db_table.dmp”

c:导出表的结构

exp user/password@192.168.22.22/orcl file=filename.dmp rows=N;

D:导出表的空间:
导出指定表空间

exp user/password@192.168.22.22/orcl transport_tablespace=y tablespaces=(table_space_name) file=filename.dmp

(三):修改表结构

增加一个字段

alter table db_table add  creator varchar(20);
comment on column db_table .creator is '创建人';##增加注解

修改某个字段的类型
##修改某个字段名称

alter table db_table rename column sname to name;


##修改某个字段类型

alter table db_table modify createtime Date;

(四):查询一些表或者数据库的属性

查看表名和object_id

select object_name, object_id from user_objects where object_name = 'db_name';

查询表的结构

select * from user_tab_columns where Table_Name='db_table';

一张表的列名,数据类型,数据长度

select column_name,data_type,data_length,DATA_PRECISION ,DATA_SCALE 
from all_tab_columns where table_name='db_table';

查看表的注解

select * from user_tab_comments;

查看表中列的注解

select * from user_col_comments where table_name='db_table'

查看表的属性,表的所属者

select * from dba_tab_columns where table_name='db_table'

查看表的属性空间

select * from dba_tables where table_name='db_table';

(五):创建最简单索引(创建索引就是创建目录,已经排好序,所以调用所以来查找时就会按照这个排序来找)

create index  index_yz_db_column on db(column);

(六):锁

查询锁
##查询锁

select * from v$session a ,v$locked_object b where a.sid=b.session_id;
select sess.sid,sess.serial#,lo.oracle_username,lo.os_user_name,ao.object_name,lo.locked_modefrom v$locked_object lo,dba_objects ao,v$session sesswhere ao.object_id=lo.object_id and lo.session_id=sess.sid;

解除锁
##解除锁

alter system kill session='430,14747'

(7)创建表空间
#创建表空间

create tablespace PRISON_DATA_SPACE
datafile 'H:\oracle_table_space\table_DATA_SPACE.dbf'
size 50m
autoextend on
next 10m #每次增加100m
extent management local;

(8)给用户赋权限
用户的权限赋值:

-- Create the user 
create user SCOTT
  default tablespace USERS
  temporary tablespace TEMP
  profile DEFAULT
  password expire;
-- Grant/Revoke role privileges 
grant connect to SCOTT;
grant dba to SCOTT;
grant resource to SCOTT;
-- Grant/Revoke system privileges 
grant unlimited tablespace to SCOTT;

(8)拼凑sql

select 'create  or replace  view as select '|| wm_concat(column_name) || 'from 表2' from user_tab_columns  where table_name='表1';
删除数据库中的所有表select 'drop table '|| table_name from user_tables;

0 0