Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3058783
  • 博文数量: 206
  • 博客积分: 3409
  • 博客等级: 中校
  • 技术积分: 4066
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-24 10:21
个人简介

● ITPUB名人堂嘉宾 ● ChinaUnix社区博客专家 ● ChinaUnix社区Oracle板块版主 ● 优酷网认证音乐牛人:EricGuitar ● SDOUG 核心成员 ●E-mail:gaoqiangdba@163.com

文章分类

全部博文(206)

文章存档

2021年(11)

2020年(7)

2019年(7)

2016年(5)

2015年(36)

2014年(23)

2013年(15)

2012年(23)

2011年(61)

2010年(18)

分类: Oracle

2012-06-04 16:10:51

测试目的:

  确定在数据库导入、导出过程中数据(尤其是BLOB类型数据)是否能正常访问和使用。

 

测试环境:

源数据库:Oracle 9i on windows 2003 32bit

目的数据库:Oracle 9i on Red Hat Linux 4 32bit

 

测试思路:

将源数据库整库导出,然后分用户导入数据,其中,数据中包括有BLOB类型的数据。导入完成之后查看数据是否能访问,BLOB字段中的图片是否可读。

 

测试步骤:

1.创建基础环境:

确保数据库和系统能正常使用。

Windows数据库中创建测试用户TOM和表空间TOM

 

----------------创建用户表空间-----------------

create tablespace TOM

datafile '/opt/ora10g/oradata/jssbook/jssbook/TOM01.dbf'

size 50 M

extent management local

uniform size 1M;

-----------------创建用户-------------------------

create user TOM

identified  by jackson

default tablespace TOM

account unlock

profile default

 

--------------确定用户创建成功--------------------

select * from dba_users where username = 'TOM'

 

 

-----TOM登陆执行如下命令!------

select  * from user_objects

 

create table test1 as select * from user_objects;

 

create table testblob (id int,photo blob);

 

commit;

 

Linux中创建对应的用户和表空间。但不插入数据。

2.testblob表中插入图片,方法如下:

a,linux oracle 用户建一个文件夹,从windows client传几个图片过去,(文件夹权限读写,owner oracle)

b,规范文件名,小心有重名被替换而丢失

[oracle@test imgs]$ ls

11.gif  12.gif  19.gif  1.gif  31.gif  8.gif

[oracle@test imgs]$ i=100;for img in *.gif;do ((i++)); mv "$img" ${i}.gif;done

[oracle@test imgs]$ ls

101.gif  102.gif  103.gif  104.gif  105.gif  106.gif

c,导入数据库

SQL> conn TOM/password

Connected.

SQL> create table testblob(id int,photo blob);

 

Table created.

 

SQL> create or replace directory imgpath as C:\imgs';

create or replace directory imgpath as 'C:\imgs'

*

ERROR at line 1:

ORA-01031: insufficient privileges

 

SQL> conn system/password

Connected.

SQL> create or replace directory imgpath as 'C:\imgs';

 

Directory created.

SQL> grant read,write on directory imgpath to TOM;

 

Grant succeeded.

 

SQL> conn TOM/password

Connected.

 

SQL> declare

  2  l_blob blob;

  3  l_bfile bfile;

  4  begin

  5  for i in 101..106 loop

  6  insert into testimg(id,photo)

  7  values(1,empty_blob())

  8  returning photo into l_blob;

  9  l_bfile :=bfilename('IMGPATH',i||'.gif');

 10  dbms_lob.fileopen(l_bfile);

 11  dbms_lob.loadfromfile(l_blob,l_bfile,dbms_lob.getlength(l_bfile));

 12  dbms_lob.fileclose(l_bfile);

 13  end loop;

 14  commit;

 15  end;

 16  /

 

PL/SQL procedure successfully completed.

 

SQL> select id,dbms_lob.getlength(photo) blen from testblob;

 

        ID       BLEN

---------- ----------

         1        700

         1       6371

         1        699

         1        552

         1        493

         1        659

 

6 rows selected.

 

 

3.整库导出源数据库:

exp  system/password full=y  file=FULL20120604.dmp  log=FULL20120604_exp.log  buffer=20480000

通过操作系统命令将exp出来的dmp文件拷贝到目的数据库中。

4.按照用户导入数据:

imp  system/password  fromuser=TOM   touser=TOM  file= FULL20120604.dmp  log= FULL20120604_imp.log

5.验证数据完整性和可用性:

select * from test1;

select * from testblob;

可以看到图片和数据都存在。

(由于源数据库和目的数据库的用户和表空间都一样,所以笔者截图意义不大)

                                         

 

                                                   

阅读(4210) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~