Oracle imp exp 导入导出 执行脚本
一:用命令 imp/exp 的方式进行数据的导入和导出
一:文件后缀名:
二:oracle 导出 exp 命令
1 echo 开始备份数据库
2 if not exist D:\oracle_bak\files md D:\oracle_bak\files
3 if not exist D:\oracle_bak\logs md D:\oracle_bak\logs
4
5 set var=%date:~0,4%%date:~5,2%%date:~8,2%%time:~9,2%
6 exp GDSDCZJ/GDSDCZJ1234@192.168.1.100/pdborcl file=D:\oracle_bak\files\GDSDCZJ_%var%.dmp log=D:\oracle_bak\logs\GDSDCZJ_%var%.log
7 echo 备份数据库结束
8
9 echo 删除30天前的备份记录
10 forfiles /p "D:\oracle_bak" /s /m *.dmp /d -30 /c "cmd /c del @path"
11 forfiles /p "D:\oracle_bak" /s /m *.log /d -30 /c "cmd /c del @path"
12 echo 删除30天前的备份记录结束
13 exit
14
三:oracle 导入 imp 命令
1 echo 开始导入数据库
2 set var=%date:~0,4%%date:~5,2%%date:~8,2%
3 imp GDSDYTH/GDSDYTH@192.168.0.110/pdborcl full=y ignore=y file=D:\oracle_bak\files\gdsd_czj_%var%.dmp log=D:\oracle_bak\logs\gdsd_czj_to_apa_imp_%var%.log
4 echo 导入数据库结束
5 exit
6
四:oracle 删除用户 再创建用户并赋予相对应的操作权限,然后再 导入 imp 命令
1 drop user sync_plus_1_0501 cascade;
2 create user sync_plus_1_0501 identified by sync_plus_1_0501
3 default tablespace sync_plus_1 temporary tablespace temp quota 500m on users;
4 grant all privileges to sync_plus_1_0501 ;
5 grant ALLTAX to SYNC_PLUS_1_0501;
6 grant ALLINONE_JX to sync_plus_1_0501 ;
7 grant ALLOUTSIDE to sync_plus_1_0501 ;
8 grant dba to sync_plus_1_0501;
9 grant RDCX to sync_plus_1_0501;
10 quit;
11
1 echo 开始导入数据库
2 sqlplus sys/oracle@192.168.1.168/pdborcl as sysdba @F:\decoument\DB_soft\createUser.sql
3
4 set var=%date:~0,4%%date:~5,2%%date:~8,2%
5 imp sync_plus_1_0501/sync_plus_1_0501@192.168.1.168/pdborcl full=y ignore=y
6 file=F:\decoument\DB_soft\imp_data\SYNC_PLUS_1_%var%.dmp
7 log=F:\decoument\DB_soft\imp_data\logs\SYNC_PLUS_1_to_apa_imp_%var%.log
8 echo 导入数据库结束
9 exit;
执行 效果:
五:每天自动创建当天日期为后缀名的oracle用户。并给该用户导入数据
1:看执行效果
2:上脚本:
Imp_toDay_Data.bat
1 echo 开始导入数据库
2 set var=%date:~0,4%%date:~5,2%%date:~8,2%
3 sqlplus sys/oracle@192.168.1.168/pdborcl as sysdba @F:\decoument\DB_soft\imp_toDay_Data\createUser.sql
4
5 imp sync_plus_1_%var%/sync_plus_1_%var%@192.168.1.168/pdborcl full=y ignore=y file=F:\decoument\DB_soft\SYNC_PLUS_1_%var%.dmp log=F:\decoument\DB_soft\imp_toDay_Data\logs\SYNC_PLUS_1_to_apa_imp_%var%.log
6 echo 导入数据库结束
7createUser.sql
1 declare
2 v_time varchar(20);
3 v_sql varchar(4000);
4 v_count int :=0;
5 v_count_sql varchar(4000);
6 v_username varchar(300);
7 begin
8 select to_char(sysdate,'yyyyMMdd') into v_time from dual;
9 v_username :='SYNC_PLUS_1_'||v_time;
10 dbms_output.put_line(v_username);
11 SELECT count(USERNAME) into v_count FROM ALL_USERS t where t.username =v_username ;
12 dbms_output.put_line(v_count);
13 if v_count = 0 then
14 v_sql :='create user sync_plus_1_'||v_time ||' identified by sync_plus_1_'||v_time ||' default tablespace sync_plus_1 temporary tablespace temp quota 500m on users';
15 dbms_output.put_line(v_sql);
16 execute immediate v_sql;
17 end if;
18 v_sql:='grant all privileges to sync_plus_1_'||v_time ;
19 dbms_output.put_line(v_sql);
20 execute immediate v_sql;
21 v_sql:='grant ALLTAX to sync_plus_1_'||v_time;
22 dbms_output.put_line(v_sql);
23 execute immediate v_sql;
24 v_sql:='grant ALLINONE_JX to sync_plus_1_'||v_time ;
25 dbms_output.put_line(v_sql);
26 execute immediate v_sql;
27 v_sql:='grant ALLOUTSIDE to sync_plus_1_'||v_time ;
28 dbms_output.put_line(v_sql);
29 execute immediate v_sql;
30 v_sql:='grant dba to sync_plus_1_'||v_time;
31 dbms_output.put_line(v_sql);
32 execute immediate v_sql;
33 v_sql:='grant RDCX to sync_plus_1_'||v_time;
34 dbms_output.put_line(v_sql);
35 execute immediate v_sql;
36 commit;
37 end;
38 /
39
40 quit;
六: 对oracle数据库某个用户 进行删表后再导入数据
Imp_SYNC_PLUS_1.bat
1 echo 开始导入数据库
2 sqlplus /nolog @F:\decoument\DB_soft\imp_data\createUser.sql
3
4 set var=%date:~0,4%%date:~5,2%%date:~8,2%
5 imp SYNC_PLUS_1/SYNC_PLUS_1@192.168.1.168/pdborcl full=y ignore=y file=F:\decoument\DB_soft\SYNC_PLUS_1_%var%.dmp log=F:\decoument\DB_soft\imp_data\logs\SYNC_PLUS_1_to_apa_imp_%var%.log
6 echo 导入数据库结束
7 exit;
createUser.sql
--drop user sync_plus_1 cascade;
--create user sync_plus_1 identified by sync_plus_1 default tablespace sync_plus_1 temporary tablespace temp quota 500m on users;
--grant all privileges to sync_plus_1 ;
--grant ALLTAX to sync_plus_1;
---grant ALLINONE_JX to sync_plus_1 ;
--grant ALLOUTSIDE to sync_plus_1 ;
--grant dba to sync_plus_1;
--grant RDCX to sync_plus_1;
conn SYNC_PLUS_1/SYNC_PLUS_1@192.168.1.168/pdborcl ; ----禁用所有的外键
/*--批量生成规则
select 'alter table ' || table_name || ' disable constraint ' ||
constraint_name || ';'
from user_constraints
where constraint_type = 'R';
*/
SET SERVEROUTPUT ON SIZE 1000000
BEGIN
for c in (select 'ALTER TABLE '||TABLE_NAME||' DISABLE CONSTRAINT '||constraint_name||' ' as v_sql from user_constraints where CONSTRAINT_TYPE='R') loop
DBMS_OUTPUT.PUT_LINE(C.V_SQL);
begin
EXECUTE IMMEDIATE c.v_sql;
exception when others then
dbms_output.put_line(sqlerrm);
end;
end loop;
for c in (select 'ALTER TABLE '||TNAME||' DISABLE ALL TRIGGERS ' AS v_sql from tab where tabtype='TABLE') loop
dbms_output.put_line(c.v_sql);
begin
execute immediate c.v_sql;
exception when others then
dbms_output.put_line(sqlerrm);
end;
end loop;
end;
/
commit; ------禁用所有的主键;
/*
select 'alter table ' || table_name || ' disable constraint ' ||
constraint_name || ';'
from user_constraints
where constraint_type = 'P'; */
SET SERVEROUTPUT ON SIZE 1000000
BEGIN
for c in (select 'ALTER TABLE '||TABLE_NAME||' DISABLE CONSTRAINT '||constraint_name||' ' as v_sql from user_constraints where CONSTRAINT_TYPE='P') loop
DBMS_OUTPUT.PUT_LINE(C.V_SQL);
begin
EXECUTE IMMEDIATE c.v_sql;
exception when others then
dbms_output.put_line(sqlerrm);
end;
end loop;
for c in (select 'ALTER TABLE '||TNAME||' DISABLE ALL TRIGGERS ' AS v_sql from tab where tabtype='TABLE') loop
dbms_output.put_line(c.v_sql);
begin
execute immediate c.v_sql;
exception when others then
dbms_output.put_line(sqlerrm);
end;
end loop;
end;
/
commit; ----删除所有外键:
/*
select 'alter table ' || table_name || ' drop constraint ' ||
constraint_name || ';'
from user_constraints
where constraint_type = 'R';
*/ SET SERVEROUTPUT ON SIZE 1000000
BEGIN
for c in (select 'ALTER TABLE '||TABLE_NAME||' drop CONSTRAINT '||constraint_name||' ' as v_sql from user_constraints where CONSTRAINT_TYPE='R') loop
DBMS_OUTPUT.PUT_LINE(C.V_SQL);
begin
EXECUTE IMMEDIATE c.v_sql;
exception when others then
dbms_output.put_line(sqlerrm);
end;
end loop;
/*for c in (select 'ALTER TABLE '||TNAME||' DISABLE ALL TRIGGERS ' AS v_sql from tab where tabtype='TABLE') loop
dbms_output.put_line(c.v_sql);
begin
execute immediate c.v_sql;
exception when others then
dbms_output.put_line(sqlerrm);
end;
end loop;*/
end;
/
commit; ----删除主键:
/*
select 'alter table ' || table_name || ' drop constraint ' ||
constraint_name || ';'
from user_constraints
where constraint_type = 'P'; */ SET SERVEROUTPUT ON SIZE 1000000
BEGIN
for c in (select 'ALTER TABLE '||TABLE_NAME||' drop CONSTRAINT '||constraint_name||' ' as v_sql from user_constraints where CONSTRAINT_TYPE='P') loop
DBMS_OUTPUT.PUT_LINE(C.V_SQL);
begin
EXECUTE IMMEDIATE c.v_sql;
exception when others then
dbms_output.put_line(sqlerrm);
end;
end loop;
/*for c in (select 'ALTER TABLE '||TNAME||' DISABLE ALL TRIGGERS ' AS v_sql from tab where tabtype='TABLE') loop
dbms_output.put_line(c.v_sql);
begin
execute immediate c.v_sql;
exception when others then
dbms_output.put_line(sqlerrm);
end;
end loop;*/
end;
/
commit; -----删除所有表
--- 批量生成规则 select 'drop table '||table_name||';' from cat where table_type='TABLE' ; SET SERVEROUTPUT ON SIZE 1000000
BEGIN
for c in (select 'drop TABLE '||TABLE_NAME||' ' as v_sql from cat where table_type='TABLE') loop
DBMS_OUTPUT.PUT_LINE(C.V_SQL);
begin
EXECUTE IMMEDIATE c.v_sql;
exception when others then
dbms_output.put_line(sqlerrm);
end;
end loop;
/*for c in (select 'ALTER TABLE '||TNAME||' DISABLE ALL TRIGGERS ' AS v_sql from tab where tabtype='TABLE') loop
dbms_output.put_line(c.v_sql);
begin
execute immediate c.v_sql;
exception when others then
dbms_output.put_line(sqlerrm);
end;
end loop;*/
end;
/
commit; quit;
二:使用 PL/SQL 工具 进行数据的导入 导出
1: 前提:需要安装oracle Xe 的客户端
2: 使用Plsql 工具 进行demp 文件 的数据导入
——————————————————————————————————————————————————————————————————————————————————————————————————————
Oracle imp exp 导入导出 执行脚本的更多相关文章
- oracle imp exp 导入导出
一.exp导出 exp myuser/mypwd@orcl file=D:\sql-bak\myuser.dmp log=D:\sql-bak\myuser.log exp 用户/密码@实例名 fil ...
- oracle快速创建用户、imp/exp导入导出dmp文件
1.首先我们可以用管理员用户以sysdba的身份登录oracle sqlplus username/password as sysdba 2.然后我就可以来创建用户了. create user use ...
- 关于 Oracle 的数据导入导出及 Sql Loader (sqlldr) 的用法
在 Oracle 数据库中,我们通常在不同数据库的表间记录进行复制或迁移时会用以下几种方法: 1. A 表的记录导出为一条条分号隔开的 insert 语句,然后执行插入到 B 表中2. 建立数据库间的 ...
- oracle数据库数据导入导出步骤(入门)
oracle数据库数据导入导出步骤(入门) 说明: 1.数据库数据导入导出方法有多种,可以通过exp/imp命令导入导出,也可以用第三方工具导出,如:PLSQL 2.如果熟悉命令,建议用exp/imp ...
- Oracle 数据泵导入导出总结
Oracle 数据泵(IMPDP/EXPDP)导入导出总结 Oracle数据泵导入导出是日常工作中常用的基本技术之一,它相对传统的逻辑导入导出要高效,这种特性更适合数据库对象数量巨大的情形,因为我日常 ...
- Oracle之 dmp导入/导出、数据库操作等过程中的字符集问题
影响Oracle数据库字符集最重要的参数是NLS_LANG参数. 它的格式如下: NLS_LANG = language_territory.charset 它有三个组成部分(语言.地域和字符集),每 ...
- oracle数据库的导入 导出实例
oracle数据库的导入 导出实例 分类: DataBase2011-09-07 23:25 377人阅读 评论(0) 收藏 举报 数据库oraclefileusercmdservice 我要从另外一 ...
- oracle数据的导入导出(两种方法三种方式)
大概了解数据库中数据的导入导出.在oracle中,导入导出数据的方法有两种,一种是使用cmd命令行的形式导入导出数据,另一种是使用PL/SQL工具导入导出数据. 1,使用cmd命令行导入导出数据 1. ...
- ORACLE数据库在导入导出时序列不一致的问题
ORACLE数据库在导入导出时序列不一致的问题 在使用ORACLE数据库时,当给一个表设置自增字段时,我们经常会使用到序列+触发器来完成.但当你需要对数据库进行导入导出时,序列很容易出问题. 当你 ...
随机推荐
- 【noip 2015】普及组
T1.金币 题目链接 #include<cstdio> #include<algorithm> #include<cstring> using namespace ...
- linux下mysql 配置
su root 加环境变量 在文件末尾加上如下两行代码 PATH=/usr/local/webserver/php/bin:$PATHexport PATH # /etc/profile 保存,重启 ...
- ORA-01882 timezone region not found
解决方案有2个 1.在java运行环境中添加配置,制定时区 -Duser.timezone=GMT 2.修改系统时区 linux 下 1. 查看当前时区 date -R 2. 修改设置时区 方法(1) ...
- Vue中的双向数据绑定简单介绍
1. 文本框绑定v-module <div id="app"> <input type="text" v-model="msg&qu ...
- Python 转路由之uplink
项目描述 1.为客制化的Web API接口建立可重用的对象 2.可以与Requests,asyncio和Twisted 快速开始 Uplink把你的HTTP API接口转化成一个Python的类 fr ...
- Spring如何支持可扩展
Spring是一款优秀的开发框架,包括了非常多的基础组件 那么它是如何做到灵活可扩展呢? 1 .框架初始化 2.Bean初始化 ref https://mp.weixin.qq.com/s/QuSls ...
- django 学习手册 - ORM 报错集(随时更新)
报错问题: 问题一:(1050代码) django.db.utils.InternalError: (1050, "Table 'app01_group' already exists&qu ...
- MySql cmd下的学习笔记 —— 有关视图的操作(algorithm)
建立一张简单的查询视图,不用临时表,只用条件合并 在简单的查询中,建立临时表的开销比较大 这是可以指定algorithm选项为merge 在v2的视图中,并没有建立临时表 但在下列情况下,必须建立临时 ...
- 20165234 《Java程序设计》第八周学习总结
第八周学习总结 教材内容学习 第十二章 Java 多线程机制 进程与线程 进程是程序的一次动态执行过程,对应了从代码加载.执行至执行完毕的一个完整过程. 线程不是进程,是比进程更小的执行单位. 一个进 ...
- nginx基础命令
1.nginx 启动nginx service nginx start 查看nginx状态 service nginx status 关闭nginx service nginx stop 热重启(前提 ...