Skip to Main Content

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Stanislav.

Asked: April 04, 2017 - 9:37 am UTC

Last updated: April 18, 2017 - 3:07 am UTC

Version: Oracle database server 12C

Viewed 1000+ times

You Asked

Hello Tom,

we migrate from informix to oracle and we have this problem :
we have to unload tables with millions records, each record has blob,
blobs are unloaded in some blob files with size near 2 GB.

170 thousand blobs are in one blob file.

We found only one way to load contents to oracle database,
each table record has path to file with one blob .

it's mean millions files in file system.

Is there other way to load records from unload file, but blobs merged into
few blob files ?

Thank you for your answer.

You write :
With regards to: "Is there other way to load records from unload file, but blobs merged into few blob files ?" "170 thousand blobs are in one blob file." I dont know what you mean by - lots of blobs merged into 1 file?

I know explain it similar to informix only.
We have big table in informix, 300 mil. records, each record has blob.
I make unload, unload file has field "ADR,LENGTH,FILE" where ADR is number of bytes from begining of blob file, LENGTH is number of bytes whitch blob has and
FILE is blob file name.
Blob file name consist number of blobs up to 2GB bytes of blob file.
When blob file exeeds 2GB, informix make new blob file and so on.

My question is, how I can load this unload to oracle database.

We found one way only in oracle, unload file has records with field "blob file name" but it's mean avery blob is in separate file.

Please give mi some link to knowledge about migration tools from informix to oracle, whitch takes focus to migrate big tables with blobs.

Very thank You.

and Connor said...

OK, if you have this information:

ADR,LENGTH,FILE

then you should be able to cycle through that and load the blobs into the database without too much fuss, eg:

Here's my sample merged blob file, and a loader to load it. I'm hardcoding the file names and lengths, but this could be in a table or any convenient source

C:\temp>dir sang*
 Volume in drive C is OS
 Volume Serial Number is 9CB0-0212

 Directory of C:\temp

27/11/2016  06:18 PM           214,715 sangam1.jpg
27/11/2016  06:18 PM           133,674 sangam2.jpg
27/11/2016  06:19 PM           257,522 sangam3.jpg
15/01/2017  10:24 AM           475,650 sangam4.jpg
               4 File(s)      1,081,561 bytes
               0 Dir(s)  205,366,693,888 bytes free

C:\temp>cat sangam* > blob.file

C:\temp>dir blob.file
 Volume in drive C is OS
 Volume Serial Number is 9CB0-0212

 Directory of C:\temp

18/04/2017  11:02 AM         1,081,561 blob.file
               1 File(s)      1,081,561 bytes
               0 Dir(s)  205,356,343,296 bytes free
               
SQL> create table blobfiles ( name varchar2(20), b blob );

Table created.

SQL>
SQL> set serverout on
SQL> declare
  2    type file_details is record
  3      ( len number,
  4        name varchar2(30)
  5      );
  6    type file_list is table of file_details index by pls_integer;
  7
  8    f file_list;
  9
 10    source_blob bfile := bfilename('TEMP','blob.file');
 11    each_blob blob;
 12
 13    l_offset_Dest int;
 14    l_offset_src int := 1;
 15  begin
 16    f(1).len := 214715;
 17    f(1).name := 'sangam1.jpg';
 18
 19    f(2).len := 133674;
 20    f(2).name := 'sangam1.jpg';
 21
 22    f(3).len := 257522;
 23    f(3).name := 'sangam1.jpg';
 24
 25    f(4).len := 475650;
 26    f(4).name := 'sangam1.jpg';
 27
 28    -- fake entry for starting point
 29    f(0).len := 0;
 30
 31    dbms_lob.fileopen(source_blob);
 32
 33    for i in 1 .. 4 loop
 34      insert into blobfiles
 35      values ( f(i).name, empty_blob())
 36      returning b into each_blob;
 37
 38      
 39      l_offset_Dest := 1;
 40
 41      dbms_output.put_line(i);
 42      dbms_output.put_line(l_offset_src);
 43      dbms_output.put_line(f(i).len);
 44
 45      dbms_lob.loadblobfromfile
 46        (each_blob,
 47         source_blob,
 48         f(i).len,
 49         l_offset_Dest,
 50         l_offset_src);
 51
 52    end loop;
 53  end;
 54  /
1
1
214715
2
214716
133674
3
348390
257522
4
605912
475650

PL/SQL procedure successfully completed.

SQL>
SQL> select * from blobfiles;

NAME
--------------------
B
-------------------------------------------------------------------------------------------
sangam1.jpg
FFD8FFE000104A46494600010101004800480000FFDB00430001010101010101010101010101010101010101010
0102020101020101010202020202020202020102

sangam1.jpg
FFD8FFE000104A46494600010101004800480000FFDB00430001010101010101010101010101010101010101010
0102020101020101010202020202020202020102

sangam1.jpg
FFD8FFE000104A46494600010101004800480000FFDB00430001010101010101010101010101010101010101010
0102020101020101010202020202020202020102

sangam1.jpg
FFD8FFE000104A46494600010101004800480000FFDB00430001010101010101010101010101010101010101010
0102020101020101010202020202020202020102


4 rows selected.

SQL> select name, dbms_lob.getlength(b) from blobfiles;

NAME                 DBMS_LOB.GETLENGTH(B)
-------------------- ---------------------
sangam1.jpg                         214715
sangam1.jpg                         133674
sangam1.jpg                         257522
sangam1.jpg                         475650

4 rows selected.               




Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Stanislav Hricko, April 18, 2017 - 1:08 pm UTC


More to Explore

CLOB/BLOB/etc

Complete documentation on Securefiles and Large Objects here