?
Solved

Saving Images in Oracle Database useing SQL not Developer 2000

Posted on 2003-03-27
6
Medium Priority
?
556 Views
Last Modified: 2009-12-16
I want to save and then extract an image in Oracle database.
The structure of table i have created is as follow:

ID number(5) Primary Key
Description  Varchar2(256)
Image Long Raw


How I save an image using SQL INSERT Command and How I fetch data from table using SQL SELECT Command?

I don't want to use from defaul and samrt menu.
Thank you.

0
Comment
Question by:arwaseem
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 5

Expert Comment

by:jpkemp
ID: 8223037
Oracle recommends using LOB (e.g. BLOB) instead of LONG RAW. They have more features and are not limited to 32767 bytes.

SQL doesn't really provide anything for manipulating image data. You get some functionality with PL/SQL (e.g. getting value of LONG RAW / LOB into a PL/SQL variable and vice versa). Usually this is done using Oracle Forms or some other client interface.

Jeff
0
 
LVL 48

Accepted Solution

by:
schwertner earned 100 total points
ID: 8223145
This is a solution:

SQL> create directory MYDIR as 'C:\MYIMAGE';

Directory created.

SQL> create table special(a number, b varchar2(20), c blob);

Table created.

SQL>
SQL> insert into special values(1,'abcd',empty_blob());

1 row created.

SQL>
SQL> commit;

Commit complete.


create or replace procedure load(id number)
is
dest_lob blob;
src_lob bfile:=bfilename('MYDIR','img.bmp');
amt integer:=sys.dbms_lob.getlength(src_lob);
begin
select c into dest_lob from special
where a=id for update;
dbms_lob.fileopen(src_lob);
dbms_lob.loadfromfile(dest_lob,src_lob,amt);
dbms_lob.fileclose(Src_lob);
commit;
end;
/

SQL> @ blob_insert

Procedure created.

SQL> exec load(1);

PL/SQL procedure successfully completed.

SQL> select a from special;

A




The LONG datatypes are accessible via subprograms from the DBMS_LOB package.
The DBMS_LOB package provides subprograms to operate on BLOBs, CLOBs,NCLOBs, BFILEs, and temporary LOBs.

You can use DBMS_LOB to access and manipulation specific parts of a LOB or complete LOBs.

For example, consider a READ operation past the end of the BFILE value, which generates a NO_DATA_FOUND

exception:

DECLARE
fil BFILE;
pos INTEGER;
amt BINARY_INTEGER;
buf RAW(40);
BEGIN
SELECT f_lob INTO fil FROM lob_table WHERE key_value = 21;
dbms_lob.open(fil, dbms_lob.lob_readonly);
amt := 40; pos := 1 + dbms_lob.getlength(fil); buf := '';
dbms_lob.read(fil, amt, pos, buf);
dbms_output.put_line('Read F1 past EOF: '||
utl_raw.cast_to_varchar2(buf));
dbms_lob.close(fil);
exception
WHEN no_data_found
THEN
BEGIN
dbms_output.put_line('End of File reached. Closing file');
dbms_lob.fileclose(fil);
-- or dbms_lob.filecloseall if appropriate
END;
END;
/
Statement processed.
End of File reached. Closing file
0
 

Author Comment

by:arwaseem
ID: 8223740
Thanks to all for answer specially to Mr. Schwertner.
In my Quaestion at the bottom I asked that I don't want to use Developer Forms default&Smartbar. Mease I do it through PL/SQL but in forms. I don't use Form's built in functions. First of all I called function on a Button for selecting  image files through "Get_File_name" in a variable; Then I used function "Read_Image_File" This shows Selected Image into :Image object on my Canvas. Then I wrote my own Insertion On "Add Record Button" I wrote triger "When button Pressed"
Insert into <table_name> values(:ID,:DES,:IMAGE);

Error message appears: ORA-01465 invalid hex number

How I remove this error and Why Developers Forms do not support JEPEG format?

Regards
ARwaseem
0
 
LVL 5

Assisted Solution

by:jpkemp
jpkemp earned 100 total points
ID: 8235715
Hi ARwaseem,

ORA-01465 refers to your inserting a ROWID value. I don't think that's the best way of doing it (it might not even be possible, but don't quote me on that).

You might want to consider not doing the INSERT yourself - base the block on your database table (if you haven't done this already), then when you Read_Image_File the form will set up the insert for you. Then, in your "Add Record" button (if you still want this), do a COMMIT_FORM. The form should take care of inserting the row and commiting the record for you.

Forms does support JPEG format, except for JPEGs that use Progressive Encoding. Convert the JPG files to not use Progressive Encoding, and they should work fine.

Jeff
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question