一.创建目录对象并授权
使用expdp和impdp时,其导出文件只能存放在DIRECTORY(目录)对象指定的操作系统目录中,而不能直接指定OS目录。例如:
1. sys用户创建两个目录对象
SQL> conn sys/oracle as sysdba
Connected.
SQL> create directory dirdp1 as '/home/oracle/dump1';
Directory created.
SQL> create directory dirdp2 as '/home/oracle/dump2';
Directory created.
查询所创建的目录:
SQL> select * from dba_directories where directory_name like 'DIR%';
OWNER DIRECTORY_NAME
------------------------------ ------------------------------
DIRECTORY_PATH
--------------------------------------------------------------------------------
SYS DIRDP1
/home/oracle/dump1
SYS DIRDP2
/home/oracle/dump2
2.为使用expdp和impdp的用户授权,如scott用户
SQL> grant read,write on directory dirdp1 to scott;
Grant succeeded.
SQL> grant read,write on directory dirdp2 to scott;
Grant succeeded.
二.创建示例数据
SQL> create tablespace expdptest
2 datafile '/home/oracle/app/oracle/oradata/test/expdptest.dbf' size 5M
3 autoextend on next 3M maxsize unlimited;
Tablespace created.
SQL> alter user scott quota unlimited on expdptest;
User altered.
创建索引
SQL> show user
USER is "SCOTT"
SQL> create index idx_emp_ename on emp(ename)
2 pctfree 30
3 tablespace expdptest;
Index created.
新建表并插入某些数据
SQL> create table test_tab
2 (
3 c1 number(9) primary key,
4 c2 varchar2(20),
5 c3 varchar2(30))
6 tablespace expdptest;
Table created.
SQL> insert into test_tab values (1,'aaa','bbb');
1 row created.
SQL> insert into test_tab values (12,'afaa','bfbb')
1 row created.
创建视图
SQL> conn / as sysdba
Connected.
SQL> grant create view to scott;
Grant succeeded.
SQL> conn scott/tiger
Connected.
SQL> create view v_dept_emp
2 as
3 select a.deptno,a.dname,a.loc,b.empno,b.ename,b.sal
4 from dept a,emp b
5 where a.deptno=b.deptno and a.deptno in (10,20);
View created.
创建存储过程
SQL> create or replace procedure query_emp_sal
2 (v_no in emp.empno%TYPE,
3 v_name out emp.ename%TYPE,
4 v_sal out emp.sal%TYPE)
5 IS
6 emp_sal_error exception;
7 begin
8 select ename,sal into v_name,v_sal from emp
9 where empno=v_no;
10 end query_emp_sal;
11 /
Procedure created
三.使用expdp导出数据
语法:expdp username/passwd parameter1[,parameter2,...]
关键字 说明 (默认)
---------------------------------------------------------------------------
ATTACH 连接到现有作业, 例如 ATTACH [=作业名]。
COMPRESSION 减小有效的转储文件内容的大小
关键字值为: (METADATA_ONLY) 和 NONE。
CONTENT 指定要导出的数据内容, 其中有效关键字为: (ALL), DATA_ONLY 和METADATA_ONLY
DIRECTORY 供转储文件和日志文件使用的目录对象。
DUMPFILE 目标转储文件 (expdat.dmp) 的列表, 例如 DUMPFILE=scott1.dmp, scott2.dmp, dmpdir:scott3.d
ENCRYPTION_PASSWORD 用于创建加密列数据的口令关键字。
ESTIMATE 计算作业估计值, 其中有效关键字为: (BLOCKS) 和 STATISTICS。
ESTIMATE_ONLY 在不执行导出的情况下计算作业估计值,关键字为Y,N
EXCLUDE 排除特定的对象类型, 例如 EXCLUDE=TABLE:EMP。
FILESIZE 以字节为单位指定每个转储文件的大小。
FLASHBACK_SCN 用于将会话快照设置回以前状态的 SCN。
FLASHBACK_TIME 用于获取最接近指定时间的 SCN 的时间。
FULL 导出整个数据库 (N)。
HELP 显示帮助消息 (N)。
INCLUDE 包括特定的对象类型, 例如 INCLUDE=TABLE_DATA。
JOB_NAME 要创建的导出作业的名称。
LOGFILE 日志文件名 (export.log)。
NETWORK_LINK 链接到源系统的远程数据库的名称。
NOLOGFILE 不写入日志文件 (N)。
PARALLEL 更改当前作业的活动 worker 的数目。
PARFILE 指定参数文件。
QUERY 用于导出表的子集的谓词子句。
使用expdp和impdp时,其导出文件只能存放在DIRECTORY(目录)对象指定的操作系统目录中,而不能直接指定OS目录。例如:
1. sys用户创建两个目录对象
SQL> conn sys/oracle as sysdba
Connected.
SQL> create directory dirdp1 as '/home/oracle/dump1';
Directory created.
SQL> create directory dirdp2 as '/home/oracle/dump2';
Directory created.
查询所创建的目录:
SQL> select * from dba_directories where directory_name like 'DIR%';
OWNER DIRECTORY_NAME
------------------------------ ------------------------------
DIRECTORY_PATH
--------------------------------------------------------------------------------
SYS DIRDP1
/home/oracle/dump1
SYS DIRDP2
/home/oracle/dump2
2.为使用expdp和impdp的用户授权,如scott用户
SQL> grant read,write on directory dirdp1 to scott;
Grant succeeded.
SQL> grant read,write on directory dirdp2 to scott;
Grant succeeded.
二.创建示例数据
SQL> create tablespace expdptest
2 datafile '/home/oracle/app/oracle/oradata/test/expdptest.dbf' size 5M
3 autoextend on next 3M maxsize unlimited;
Tablespace created.
SQL> alter user scott quota unlimited on expdptest;
User altered.
创建索引
SQL> show user
USER is "SCOTT"
SQL> create index idx_emp_ename on emp(ename)
2 pctfree 30
3 tablespace expdptest;
Index created.
新建表并插入某些数据
SQL> create table test_tab
2 (
3 c1 number(9) primary key,
4 c2 varchar2(20),
5 c3 varchar2(30))
6 tablespace expdptest;
Table created.
SQL> insert into test_tab values (1,'aaa','bbb');
1 row created.
SQL> insert into test_tab values (12,'afaa','bfbb')
1 row created.
创建视图
SQL> conn / as sysdba
Connected.
SQL> grant create view to scott;
Grant succeeded.
SQL> conn scott/tiger
Connected.
SQL> create view v_dept_emp
2 as
3 select a.deptno,a.dname,a.loc,b.empno,b.ename,b.sal
4 from dept a,emp b
5 where a.deptno=b.deptno and a.deptno in (10,20);
View created.
创建存储过程
SQL> create or replace procedure query_emp_sal
2 (v_no in emp.empno%TYPE,
3 v_name out emp.ename%TYPE,
4 v_sal out emp.sal%TYPE)
5 IS
6 emp_sal_error exception;
7 begin
8 select ename,sal into v_name,v_sal from emp
9 where empno=v_no;
10 end query_emp_sal;
11 /
Procedure created
三.使用expdp导出数据
语法:expdp username/passwd parameter1[,parameter2,...]
关键字 说明 (默认)
---------------------------------------------------------------------------
ATTACH 连接到现有作业, 例如 ATTACH [=作业名]。
COMPRESSION 减小有效的转储文件内容的大小
关键字值为: (METADATA_ONLY) 和 NONE。
CONTENT 指定要导出的数据内容, 其中有效关键字为: (ALL), DATA_ONLY 和METADATA_ONLY
DIRECTORY 供转储文件和日志文件使用的目录对象。
DUMPFILE 目标转储文件 (expdat.dmp) 的列表, 例如 DUMPFILE=scott1.dmp, scott2.dmp, dmpdir:scott3.d
ENCRYPTION_PASSWORD 用于创建加密列数据的口令关键字。
ESTIMATE 计算作业估计值, 其中有效关键字为: (BLOCKS) 和 STATISTICS。
ESTIMATE_ONLY 在不执行导出的情况下计算作业估计值,关键字为Y,N
EXCLUDE 排除特定的对象类型, 例如 EXCLUDE=TABLE:EMP。
FILESIZE 以字节为单位指定每个转储文件的大小。
FLASHBACK_SCN 用于将会话快照设置回以前状态的 SCN。
FLASHBACK_TIME 用于获取最接近指定时间的 SCN 的时间。
FULL 导出整个数据库 (N)。
HELP 显示帮助消息 (N)。
INCLUDE 包括特定的对象类型, 例如 INCLUDE=TABLE_DATA。
JOB_NAME 要创建的导出作业的名称。
LOGFILE 日志文件名 (export.log)。
NETWORK_LINK 链接到源系统的远程数据库的名称。
NOLOGFILE 不写入日志文件 (N)。
PARALLEL 更改当前作业的活动 worker 的数目。
PARFILE 指定参数文件。
QUERY 用于导出表的子集的谓词子句。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/25465866/viewspace-1346508/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/25465866/viewspace-1346508/