当前位置:文档之家› oracle表的导入导出-命令

oracle表的导入导出-命令

数据导出:1 将数据库TEST完全导出,用户名system 密码manager 导出到D:daochu.dmp中exp system/manager@TEST file=d:daochu.dmp full=y2 将数据库中system用户与sys用户的表导出exp system/manager@TEST file=d:daochu.dmp owner=(system,sys)3 将数据库中的表inner_notify、notify_staff_relat导出exp aichannel/aichannel@TESTDB2 file= d:datanewsmgnt.dmp tables=(inner_notify,notify_staff_relat)4 将数据库中的表table1中的字段filed1以"00"打头的数据导出exp system/manager@TEST file=d:daochu.dmp tables=(table1) query=" where filed1 like '00%'"上面是常用的导出,对于压缩,既用winzip把dmp文件可以很好的压缩。

也可以在上面命令后面加上 compress=y 来实现。

数据的导入1 将D:daochu.dmp 中的数据导入 TEST数据库中。

imp system/manager@TEST file=d:daochu.dmpimp aichannel/aichannel@HUST full=y file=file= d:datanewsmgnt.dmp ignore=y上面可能有点问题,因为有的表已经存在,然后它就报错,对该表就不进行导入。

在后面加上 ignore=y 就可以了。

2 将d:daochu.dmp中的表table1 导入imp system/manager@TEST file=d:daochu.dmp tables=(table1)基本上上面的导入导出够用了。

不少情况要先是将表彻底删除,然后导入。

注意:操作者要有足够的权限,权限不够它会提示。

数据库时可以连上的。

可以用tnsping TEST 来获得数据库TEST能否连上。

附录一:给用户增加导入数据权限的操作第一,启动sql*puls第二,以system/manager登陆第三,create user 用户名 IDENTIFIED BY 密码(如果已经创建过用户,这步可以省略)第四,GRANT CREATE USER,DROP USER,ALTER USER ,CREATE ANY VIEW ,DROP ANY VIEW,EXP_FULL_DATABASE,IMP_FULL_DATABASE,DBA,CONNECT,RESOURCE,CREATE SESSION TO 用户名字第五, 运行-cmd-进入dmp文件所在的目录,imp userid=system/manager full=y file=*.dmp或者 imp userid=system/manager full=y file=filename.dmp执行示例:F:WorkOracle_Databackup>imp userid=test/test full=y file=inner_notify.dmp屏幕显示Import: Release 8.1.7.0.0 - Production on 星期四 2月 16 16:50:05 2006(c) Copyright 2000 Oracle Corporation. All rights reserved.连接到: Oracle8i Enterprise Edition Release 8.1.7.0.0 - ProductionWith the Partitioning optionJServer Release 8.1.7.0.0 - Production经由常规路径导出由EXPORT:V08.01.07创建的文件已经完成ZHS16GBK字符集和ZHS16GBK NCHAR 字符集中的导入导出服务器使用UTF8 NCHAR 字符集 (可能的ncharset转换). 正在将AICHANNEL的对象导入到 AICHANNEL. . 正在导入表 "INNER_NOTIFY" 4行被导入准备启用约束条件...成功终止导入,但出现警告。

附录二:Oracle 不允许直接改变表的拥有者, 利用Export/Import可以达到这一目的.先建立import9.par,然后,使用时命令如下:imp parfile=/filepath/import9.par例 import9.par 内容如下:FROMUSER=TGPMSTOUSER=TGPMS2 (注:把表的拥有者由FROMUSER改为TOUSER,FROMUSER和TOUSER的用户可以不同)ROWS=YINDEXES=YGRANTS=YCONSTRAINTS=YBUFFER=409600file==/backup/ctgpc_20030623.dmp******************************************************************************** ******************************************************常用命令1.创建表空间create tablespace 表空间名default ‘filename’/path’服务器端路径’ [size integer [k | m]] [autoextend [off | on]];size:制定文件的大小,autoextend:用来启动或禁用数据文件的自动扩展。

2.创建新用户create user 用户名identified by 密码[default tablespace 表空间][temporary tablespace 临时表空间];3.为用户授权grant 权限 to 用户grant 权限 on 表名 to 用户4.修改用户密码alter user 用户名identified by 密码;5.删除用户drop user 用户名 casaed;6.查看当前用户show user7.查看当前时间select sysdate from dual;8.查看当前用户下的所有表select table_name from user_tables;9.查看当前表的结构desc 表名10.修改上一条的内容edit;Oracle 数据库对象1.同义词a.创建同义词私有同义词create [or replace] synonym 同义词名 for 对象名;共有同义词create [or replace] public synonym 同义词名 for 对象名;b.删除同义词drop synonym同义词名;2.序列a.创建序列create sequence 序列名[start with integer][increment by integer][maxvalue integer | nomaxvalue][minvalue integer | nominvalue][cycle | nocycle][cache integer | nocache];b.访问序列select 序列名.nextval from dual;select 序列名.currval from dual;c.根改序列alter sequence 序列名[increment by integer][maxvalue integer | nomaxvalue][minvalue integer | nominvalue][cycle | nocycle][cache integer | nocache];d.删除序列drop sequence序列名;Oracle 数据表管理(一)1.创建表create table 表名(字段名1 类型,字段名2 类型…);2.修改表命令更改现有列alter table 表名 modify (column definition….);向表中添加新列alter table 表名 add (column definition….);删除表中现有的列alter table 表名 drop column 列名;3.删除表中的记录而不删除表结构truncate table 表名;4.删除与表的所有内容drop table 表名 cascade;5.数据操作语言(DML)SELECTSelect * | {[distinct] 字段名 | 表达式[列别名],…}From 表明[where 条件][order by 字段名];distinct:限制只返回不同的列CTASCreate table 新表名 as select 字段名 from 旧表名;//拷贝旧表的结构和记录,不拷贝约束INSERTInsert into 表名 [(字段名)] values (值);IISInsert into 表名1(字段名1) select 字段名2 from 表名2; //表结构已存在,从另一个表中复制记录UPDATEUpdate 表名Set 字段名=新值[where 条件];DELETEDelete 表名[where 条件];6.事务控制语言COMMITCommit;//提交SAVEPOINTSavepoint 保存点;ROLLBACKRollback or Rollback work;7.数据控制语言GRANTgrant 权限 on 表名 to 用户;REVOKERevoke 权限 on 表名 from 用户;8.集合操作符UNION :合并查询结果,并删除重复的行Select 字段名1 from 表名1UnionSelect 字段名2 from 表名2;UNION ALL:合并查询结果,并包括重复的行Select 字段名1 from 表名1Union allSelect 字段名2 from 表名2;INTERSECT:返回两个查询都有的行Select 字段名1 from 表名1IntersectSelect 字段名2 from 表名2;MINUS:返回第一个查询有而第二个查询中没有的行Select 字段名1 from 表名1MinusSelect 字段名2 from 表名2;Oracle 数据表管理(二)9.锁和表分区A.锁行级锁select …for update[of 字段] [wait n | nowait];wait n :等待的秒数表级锁lock 表名 in 锁定模式 mode [nowait]表级锁的模式:行共享 (row share,rs)行排他 (row exclusive,rx)共享 (share,s)共享行排他 (share row exclusive,srx)排他 (exclusive,x)B.表分区范围分区partition by range (column_name)(partition 分区名1 value less then(分区的边界值) [tablespace 表空间1], partition 分区名2 value less then(分区的边界值) [tablespace 表空间2] );散列分区partition by hash (column_name)partitions 散列分区的数目 [store in (分区使用的表空间)];orpartition by hash (column_name)(partition 分区名1 [tablespace 表空间1],partition 分区名1 [tablespace 表空间1]);复合分区partition by range (column_name1)subpartition by hash (column_name2)subpartitions 散列分区的数目 [store in (分区使用的表空间)];(partition 分区名1 value less then(分区的边界值),partition 分区名2 value less then(分区的边界值),partition 分区名N value less then(maxvalue));列表分区partition by list (column_name)(partition分区名1 values (分区键值的列表1),partition分区名2 values (分区键值的列表2),partition分区名N values (default));default:允许存储前面的分区不能存储的记录10.分区维护操作添加分区alter table 表名 add partition 分区名 values less then(分区的边界值);删除分区alter table 表名 drop partition 分区名;截断分区alter table 表名 truncate partition 分区名;合并分区alter table 表名 merge partitions 分区名1, 分区名2 into 分区名;拆分分区alter table 表名 split partition 分区名at (value) into (partition分区名1,partition 分区名2);分区重命名alter table 表名 rename partition 旧分区名 to 新分区名 ;11.视图a.创建视图create [or replace] [force | noforce] view 视图名[列别名]as select 字段名 from 表名[with check option [constraint 约束名]][with read only];with check option:指定只能插入或更新视图可以访问的行,with read only:确保不能在此视图上执行任何修改操作。

相关主题