Performing a mass-load of BLOBS
Administration Tips
Mass-loading BLOBS into a table Here's a real issue I had to deal with recently, and thanks to Anurag Varma (avdbi@hotmail.com) who's a regular poster on the comp.databases.oracle.server newsgroup and who proffered these techniques in response to my own pleas for help, I can now share them with you. My table was constructed thus: CREATE TABLE ALBUM
(
PHOTOID NUMBER CONSTRAINT PHOTOID_PK PRIMARY KEY, PHOTO BLOB);
...with a sequence and trigger to generate a unique number for each photo to be loaded: CREATE SEQUENCE PHOTONUM; CREATE OR REPLACE TRIGGER IDPHOTO BEFORE INSERT ON ALBUM FOR EACH ROW BEGIN SELECT PHOTONUM.NEXTVAL INTO
:NEW.PHOTOID
FROM DUAL;
END;
10 So how best to load all 10000+ photos into the album table? First, get a listing of all the files, and store it in a text file which we'll call photos.lst. Easy enough: just type DIR /B /S D:\PHOTOALBUM\*.* > PHOTOS.LST in a DOS window. Second, create a SQL Loader control file, which we'll call loadalbum.ctl, containing the following lines: LOAD DATA INFILE PHOTOS.LST INTO TABLE ALBUM (EXT_FNAME FILLER CHAR(200), PHOTO LOBFILE(EXT_FNAME) TERMINATED BY EOF) Finally, run SQL Loader by typing the following command: SQLLDR USERID=USERNAME/PASSWOIRD@TNSNAMES_ALIAS CONTROL=LOADALBUM.CTL
Copyright Š Howard Rogers 2001
10/18/2001
Page 1 of 2
Performing a mass-load of BLOBS
Administration Tips
You should find the thing now proceeds apace, and at the end of it, you should check the SQL Loader log file for any errors that might have been encountered. That will be located in a file called (in this case) loadalbum.log, located in the directory from which you launched SQL Loader in the first place. The principle lesson to be learned here is that SQL Loader is a fine tool for mass-loading blobs into Oracle -a fact which I'd forgotten, and of which Anurag kindly reminded me.
Copyright Š Howard Rogers 2001
10/18/2001
Page 2 of 2