ralph_rea
asked on
Load files into BLOB column
Hi,
I've this directory C:\load_file with 2000 files .tif and I've this table:
CREATE TABLE load_blob
(
id NUMBER(15),
tif_file BLOB
)
with 2000 records (id)
ID..................TIF_FI LE
001....................... .......
002....................... ......
234....................... .......
.......................... .......... .
.......................... .......... .
.......................... .......... . 2000 records
Now I'd like to load these 2000 files into TIF_FILE column of the table LOAD_BLOB.
How can I write a query or stored procedure to load these files into LOAD_BLOB table?
Thanks in advance!
Ralph
I've this directory C:\load_file with 2000 files .tif and I've this table:
CREATE TABLE load_blob
(
id NUMBER(15),
tif_file BLOB
)
with 2000 records (id)
ID..................TIF_FI
001.......................
002.......................
234.......................
..........................
..........................
..........................
Now I'd like to load these 2000 files into TIF_FILE column of the table LOAD_BLOB.
How can I write a query or stored procedure to load these files into LOAD_BLOB table?
Thanks in advance!
Ralph
ASKER
mrjoltcola,
in my table LOAD_BLOB I have already ID values.
In your script I must write 2000 times the file name
in my table LOAD_BLOB I have already ID values.
In your script I must write 2000 times the file name
As I said above, do the IDs correlate with the file naming convention? If so, how.
You must have a way to correlate the row to the file. Tell me how and I'll help you with a simple script to generate the 2000 filenames.
You must have a way to correlate the row to the file. Tell me how and I'll help you with a simple script to generate the 2000 filenames.
For ID 001, is the filename 001.tif ?
ASKER
Can I load only .tif file?
LOAD DATA
INFILE *
APPEND INTO TABLE load_blob
FIELDS TERMINATED BY ','
(
tif_filename FILLER, -- skip, but use for reference below
tif_file LOBFILE(tif_filename) TERMINATED BY EOF
)
BEGINDATA
C:\load_file\file001.tif
C:\load_file\file002.tif
C:\load_file\file003.tif
LOAD DATA
INFILE *
APPEND INTO TABLE load_blob
FIELDS TERMINATED BY ','
(
tif_filename FILLER, -- skip, but use for reference below
tif_file LOBFILE(tif_filename) TERMINATED BY EOF
)
BEGINDATA
C:\load_file\file001.tif
C:\load_file\file002.tif
C:\load_file\file003.tif
ASKER
I tried this script:
CREATE DIRECTORY load_file AS 'c:\load_file';
GRANT READ ON DIRECTORY load_file TO COMTS;
DECLARE
bfile_pointer BFILE;
blob_pointer BLOB;
bfile_offset NUMBER :=1;
blob_offset NUMBER :=1;
tot_len INTEGER;
BEGIN
INSERT INTO load_blob VALUES (1,EMPTY_BLOB());
SELECT blob_data INTO blob_pointer FROM load_blobWHERE id = 1 FOR UPDATE;
bfile_pointer :=bfilename('image','00000 001_000000 01.tif');
dbms_lob.fileopen(bfile_po inter,dbms _lob.file_ readonly);
dbms_lob.OPEN(blob_pointer ,dbms_lob. lob_readwr ite);
dbms_lob.LOADBLOBFROMFILE( blob_point er,bfile_p ointer,dbm s_lob.lobm axsize,bfi le_offset, blob_offse t);
tot_len :=DBMS_LOB.GETLENGTH(blob_ pointer);
dbms_lob.close(blob_pointe r);
dbms_lob.fileclose(bfile_p ointer);
DBMS_OUTPUT.PUT_LINE(TO_CH AR(tot_len ));
END;
/
this procedure load correcly the file '00000001_00000001.tif'
Can I use this procedure to load all 2000 files???
CREATE DIRECTORY load_file AS 'c:\load_file';
GRANT READ ON DIRECTORY load_file TO COMTS;
DECLARE
bfile_pointer BFILE;
blob_pointer BLOB;
bfile_offset NUMBER :=1;
blob_offset NUMBER :=1;
tot_len INTEGER;
BEGIN
INSERT INTO load_blob VALUES (1,EMPTY_BLOB());
SELECT blob_data INTO blob_pointer FROM load_blobWHERE id = 1 FOR UPDATE;
bfile_pointer :=bfilename('image','00000
dbms_lob.fileopen(bfile_po
dbms_lob.OPEN(blob_pointer
dbms_lob.LOADBLOBFROMFILE(
tot_len :=DBMS_LOB.GETLENGTH(blob_
dbms_lob.close(blob_pointe
dbms_lob.fileclose(bfile_p
DBMS_OUTPUT.PUT_LINE(TO_CH
END;
/
this procedure load correcly the file '00000001_00000001.tif'
Can I use this procedure to load all 2000 files???
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Something like:
So now your main task is just to generate the list of filenames into a sql loader control file as below.
I would write a script to do so. Do the IDs correlate with the file naming convention, or do you expect to generate the IDs from a sequence?
sqlldr scott/tiger control=tifflob.ctl
Open in new window