Welcome Guest ( Log In | Register )


 
 
 
 

Oracle performance tuning book

 

 
Oracle performance tuning 

software
 
Oracle 

performance Tuning 10g reference poster
 
Oracle training in Linux 

commands
 
Oracle training 

Excel
 
Easy Oracle Jumpstart
 
Oracle training & performance tuning books
 
Burleson Consulting Remote DB Administration
 
 
 
Reply to this topicStart new topic
> Upload an image using BLOB
LittleGirl_Andre...
post Mar 1 2006, 08:23 PM
Post #1


Newbie
*

Group: Members
Posts: 2
Joined: 1-March 06
Member No.: 3,773



Hi,

I am attempting to Insert an image "C:/hi.jpg" into
oracle10g with BLOB using SQLPlus.

I hv created a table IMAGES...

CREATE TABLE IMAGES (
ID NUMBER(4) PRIMARY KEY,
IMAGE BLOB
);

Is that a correct way to start?

How would you upload the image onto the table?

Thanks in advance.
Andrea:>
Go to the top of the page
 
+Quote Post
maxdbo
post Mar 1 2006, 11:24 PM
Post #2


Advanced Member
***

Group: Members
Posts: 99
Joined: 21-July 05
Member No.: 2,556



hi
yes you r going the right way but I would also add a column mime type along with the 2 columns listed. further you can either write a plsql procedure / package to do the job as suggested by tom in this link below. The Insert Link option doesnt seem to work nowadays just copy paste the link below.

http://asktom.oracle.com/Please/ask/f?p=49...#10676351446970

hope this helps
thanks
MAX
Go to the top of the page
 
+Quote Post
LittleGirl_Andre...
post Mar 2 2006, 04:09 AM
Post #3


Newbie
*

Group: Members
Posts: 2
Joined: 1-March 06
Member No.: 3,773



Ok, I hv tried copy and paste the following code into Oracle10g using SQLPlus...
It returned "Package Body created with compilation errors"

and entering "exec image.load('toolbar.gif;);" into SQLPlus
will return "IMAGE.LOAD must be declared".

Does anyone know wot's wrong with the following code
or any other way for uploading an image to Oracle?

Desperate for help, Thank You!

Andrea
----------------------------------------------------------

CREATE TABLE IMAGES
(
IMAGE_NAME VARCHAR2(30) primary key,
MIME_TYPE VARCHAR2(30),
CONTENT BLOB
)

CREATE OR REPLACE PACKAGE BODY IMAGE AS

PROCEDURE load(filename VARCHAR2) AS
f_lob BFILE;
b_lob BLOB;
image_name VARCHAR2(30);
mime_type VARCHAR2(30);
dot_pos NUMBER;
BEGIN
dot_pos := INSTR(filename,'.');
image_name := filename; --SUBSTR(filename,1,dot_pos-1);
mime_type := 'image/'||SUBSTR( filename,dot_pos+1,length(filename) );

INSERT INTO images values(image_name,mime_type,empty_blob() )
RETURN content INTO b_lob;
f_lob := BFILENAME('SOURCE_DIR',filename);
dbms_lob.fileopen(f_lob,dbms_lob.file_readonly);
dbms_lob.loadfromfile(b_lob,f_lob,dbms_lob.getlength(f_lob) );
dbms_lob.fileclose(f_lob);
COMMIT;
END;
END;
/
Go to the top of the page
 
+Quote Post
ahmedb72
post Mar 3 2006, 11:53 PM
Post #4


Advanced Member
***

Group: Members
Posts: 327
Joined: 9-October 04
From: UAE
Member No.: 792



when you get the error "Package Body created with compilation errors", type the following in SQL Plus and let us know about the returning message you get:
CODE
SQL> Show errors
Go to the top of the page
 
+Quote Post
Siddharta
post May 4 2006, 03:21 AM
Post #5


Newbie
*

Group: Members
Posts: 1
Joined: 4-May 06
Member No.: 4,135



--You need first to declare your package :

CREATE OR REPLACE PACKAGE IMAGE AS
PROCEDURE LOAD(filename VARCHAR2);
PROCEDURE get(name varchar2);
end;
/

--then you specify your package
CREATE OR REPLACE PACKAGE BODY IMAGE AS

PROCEDURE load(filename VARCHAR2) AS
f_lob BFILE;
b_lob BLOB;
image_name VARCHAR2(30);
mime_type VARCHAR2(30);
dot_pos NUMBER;
BEGIN
dot_pos := INSTR(filename,'.');
image_name := filename; --SUBSTR(filename,1,dot_pos-1);
mime_type := 'image/'||SUBSTR( filename,dot_pos+1,length(filename) );

INSERT INTO images values(image_name,mime_type,empty_blob() )
RETURN content INTO b_lob;
f_lob := BFILENAME('SOURCE_DIR',filename);
dbms_lob.fileopen(f_lob,dbms_lob.file_readonly);
dbms_lob.loadfromfile(b_lob,f_lob,dbms_lob.getlength(f_lob) );
dbms_lob.fileclose(f_lob);
COMMIT;
END;
/*=====*/
PROCEDURE get(name varchar2) AS
vblob BLOB;
mime_type VARCHAR2(30);
BEGIN
select content,mime_type
into vblob,mime_type
from images
where image_name=name;
owa_util.mime_header(mime_type, false);
owa_util.http_header_close;
wpg_docload.download_file(vblob);
exception when others then
htp.p(sqlcode || sqlerrm);
END;
/*=====*/
END;
/

But this code doesn't seem to fit your need because you said that you would like to store the c:\mydir\myfile.jpg from you computer (client side) into blob field in database (server side), and with this package , you need to create on server side (data base) a source directory (SQL> create directory source_dir as '/mydir'; --if you have an image file in /mydir/toolbar.gif) in which you will store all yours file you need to load in blob field with this kind of statement :
SQL> exec image.load('toolbar.gif');

So with this exemple you can not load 'client-side' file in 'server-side' blob field, and AS ME you would like to load from client side , if someone would have a suggestion, he/she would answer to a problem which concern 2 persons now wink.gif
Go to the top of the page
 
+Quote Post
burleson
post May 5 2006, 07:22 AM
Post #6


Advanced Member
***

Group: Members
Posts: 7,063
Joined: 26-January 04
Member No.: 13



Hi,

Other options include Perl:

http://www.dba-oracle.com/t_dbi_perl_lob_large_objects.htm

and you can load LOB's with Java OCI:

http://www.dba-oracle.com/t_java_graphics_blob_retrieval.htm


--------------------
Hope this helps. . .

Donald K. Burleson
Oracle Press author
Author of Oracle Tuning: The Definitive Reference
Go to the top of the page
 
+Quote Post
ranatahirfarooq
post Jul 15 2008, 08:47 AM
Post #7


Newbie
*

Group: Members
Posts: 1
Joined: 19-October 04
Member No.: 847



QUOTE (Siddharta @ May 4 2006, 08:21 AM) *
--You need first to declare your package :

CREATE OR REPLACE PACKAGE IMAGE AS
PROCEDURE LOAD(filename VARCHAR2);
PROCEDURE get(name varchar2);
end;
/

--then you specify your package
CREATE OR REPLACE PACKAGE BODY IMAGE AS

PROCEDURE load(filename VARCHAR2) AS
f_lob BFILE;
b_lob BLOB;
image_name VARCHAR2(30);
mime_type VARCHAR2(30);
dot_pos NUMBER;
BEGIN
dot_pos := INSTR(filename,'.');
image_name := filename; --SUBSTR(filename,1,dot_pos-1);
mime_type := 'image/'||SUBSTR( filename,dot_pos+1,length(filename) );

INSERT INTO images values(image_name,mime_type,empty_blob() )
RETURN content INTO b_lob;
f_lob := BFILENAME('SOURCE_DIR',filename);
dbms_lob.fileopen(f_lob,dbms_lob.file_readonly);
dbms_lob.loadfromfile(b_lob,f_lob,dbms_lob.getlength(f_lob) );
dbms_lob.fileclose(f_lob);
COMMIT;
END;
/*=====*/
PROCEDURE get(name varchar2) AS
vblob BLOB;
mime_type VARCHAR2(30);
BEGIN
select content,mime_type
into vblob,mime_type
from images
where image_name=name;
owa_util.mime_header(mime_type, false);
owa_util.http_header_close;
wpg_docload.download_file(vblob);
exception when others then
htp.p(sqlcode || sqlerrm);
END;
/*=====*/
END;
/

But this code doesn't seem to fit your need because you said that you would like to store the c:\mydir\myfile.jpg from you computer (client side) into blob field in database (server side), and with this package , you need to create on server side (data base) a source directory (SQL> create directory source_dir as '/mydir'; --if you have an image file in /mydir/toolbar.gif) in which you will store all yours file you need to load in blob field with this kind of statement :
SQL> exec image.load('toolbar.gif');

So with this exemple you can not load 'client-side' file in 'server-side' blob field, and AS ME you would like to load from client side , if someone would have a suggestion, he/she would answer to a problem which concern 2 persons now wink.gif



So with this exemple you can not load 'client-side' file in 'server-side' blob field, and AS ME you would like to load from client side , if someone would have a suggestion, he/she would answer to a problem which concern 3 persons now wink.gif
Go to the top of the page
 
+Quote Post
HAL9000
post Jul 15 2008, 11:22 AM
Post #8


Advanced Member
***

Group: Members
Posts: 699
Joined: 25-September 07
Member No.: 12,336



"AS ME you would like to load from client side"

First, be clear, Oracle DOES NOT do this, and you must write it yourself, in Java, webmethods, or whatever client side app software that you are using.

The Oracle SQL*Net "client" is disconnected from the Oracle server, and the server can only communicate to the client as you define it.

If you want to store a BLOB image on the server, you must write code to either "push" or "pull" it:

PUSH - Use an FTP program to transfer the BLOB to a known directory on the server. After FTP is complete, invoke PL/SQL to load it.

PULL - Have the server open a secure connection to the client disk as a shared device. Once the client-side disk is mounted, PL/SQL can reach it.
Go to the top of the page
 
+Quote Post
burleson
post Jul 15 2008, 05:06 PM
Post #9


Advanced Member
***

Group: Members
Posts: 7,063
Joined: 26-January 04
Member No.: 13



Greetings,

You don't need to open external connections to store a BLOB into a table from a PC client, you just need to use Java to "stream" the image into a pre-selected row.

Here is how we do it:

http://www.dba-oracle.com/t_insert_image_blob_client_pc.htm


--------------------
Hope this helps. . .

Donald K. Burleson
Oracle Press author
Author of Oracle Tuning: The Definitive Reference
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 8th February 2010 - 06:32 PM