Dear All,
How can I store picture in oracle ? can I use BLOB data type for this?
And How I can use BLOB data type in oracle?
What is long row? What is different with BLOB?
Thanking ALL
Niladri
Yes. You can store Images in BLOB datatype in Oracle.
Using it is a bit tricky. You have to use DBMS_LOB package and know the syntax.
First Create an Oracle directory corresponding to the OS directory where your images are stored.
Code:
create directory root_dir as 'C:/My_Pictures';
After creating the table with a column of BLOB datatype, you can initialize it by storing empty values (different from NULL values).
Then you can load images with a procedure like this:
Code:
CREATE OR REPLACE PROCEDURE loadLOB_proc IS
Dest_loc BLOB;
Src_loc BFILE := BFILENAME('ROOT_DIR', 'ocp_logo.gif');
Amount INTEGER := 4000;--this can be as per size of image
BEGIN
SELECT image INTO Dest_loc FROM imagetest
WHERE ID = 1 FOR UPDATE;
/* Opening the LOB is mandatory: */
DBMS_LOB.OPEN(Src_loc);
/* Opening the LOB is optional: */
DBMS_LOB.OPEN(Dest_loc);
DBMS_LOB.LOADFROMFILE(Dest_loc, Src_loc, Amount);
/* Closing the LOB is mandatory if you have opened it: */
DBMS_LOB.CLOSE(Dest_loc);
DBMS_LOB.CLOSE(Src_loc);
COMMIT;
END;
/
show errors
HII THANKS Raminder UR REPLY
BUT I EXECUITED UR PROCEDURE IT RETURN ERRORS
LIKE*************
CREATE OR REPLACE PROCEDURE loadLOB_proc IS
Dest_loc BLOB;
Src_loc BFILE := BFILENAME('TDTECH', 'picture1.jpg');
Amount INTEGER := 4000;
BEGIN
SELECT COMPANY_MAP INTO Dest_loc FROM TDTECH11
WHERE COMPANY_ID = 'TD1' FOR UPDATE;
DBMS_LOB.OPEN(Src_loc);
DBMS_LOB.OPEN(Dest_loc);
DBMS_LOB.LOADFROMFILE(Dest_loc, Src_loc, Amount);
DBMS_LOB.CLOSE(Dest_loc);
DBMS_LOB.CLOSE(Src_loc);
COMMIT;
END;
** ERRORS
-----------------------------------------------------------------
PLS-00306: wrong number or types of arguments in call to 'OPEN'
PL/SQL: Statement ignored
HII THANKS Raminder UR REPLY
BUT I EXECUITED UR PROCEDURE IT RETURN ERRORS
LIKE*************
CREATE OR REPLACE PROCEDURE loadLOB_proc IS
Dest_loc BLOB;
Src_loc BFILE := BFILENAME('TDTECH', 'picture1.jpg');
Amount INTEGER := 4000;
BEGIN
SELECT COMPANY_MAP INTO Dest_loc FROM TDTECH11
WHERE COMPANY_ID = 'TD1' FOR UPDATE;
DBMS_LOB.OPEN(Src_loc);
DBMS_LOB.OPEN(Dest_loc);
DBMS_LOB.LOADFROMFILE(Dest_loc, Src_loc, Amount);
DBMS_LOB.CLOSE(Dest_loc);
DBMS_LOB.CLOSE(Src_loc);
COMMIT;
END;
** ERRORS
-----------------------------------------------------------------
PLS-00306: wrong number or types of arguments in call to 'OPEN'
PL/SQL: Statement ignored
You are using which requires further configurations:
1) At OS level , create directory to store files , owned by oracle:dba (or whatever ur oracle id and group is)
2) At DBA level: a) open_files= ini init.ora file,
b) create directory ......(see syntax in oracle manual), grant privileges on this directory to users who need to access these bfiles.
Bookmarks