2

I've got a table with an image blob field in it, which stores jpg files.

As those jpg files are shown in a web page, I would like to resize them in order to spend less bandwidth when my web page call them.

First, I thought I could resize a jpg file, stored in blob field, when doing a select statement and using command ORDimage.process. But it seems it's not possible.

CREATE OR REPLACE FUNCTION ORGPOLV2.resize_img (i_cod_op INTEGER)
 RETURN blob
 IS
 v_photo blob ;
 BEGIN
 select img_simbolo_op
 into v_photo
 from tbl_op
 where cod_op=i_cod_op for update;
 ordimage.process(v_photo, 'maxScale=32 32');
 update tbl_op set img_simbolo_op = v_photo where cod_op=0;
--
commit;
 select img_simbolo_op
 into v_photo
 from tbl_op
 where cod_op=0;
 RETURN v_photo;
 END resize_img;
/

With this function, I got error:

ORA-14551: cannot perform a DML operation inside a query 
ORA-06512: at "RESIZE_IMG", line 10

My question is: Is it possible to resize a jpg file in a blob field?

Maybe my approach with ordimage.process is wrong and there is another way.

asked Feb 5, 2016 at 22:24
1
  • As long as you are not calling that function from a SELECT statement, I feel that your code should work. Commented May 21, 2018 at 13:33

1 Answer 1

2

Try this:

CREATE OR REPLACE FUNCTION resize_img (i_ID INTEGER)
 RETURN BLOB
IS
 vImageData BLOB;
 vSizedImage BLOB;
BEGIN
 SELECT img_simbolo_op
 INTO vImageData
 FROM tbl_yourtable
 WHERE my_ID = i_ID; 
 DBMS_Lob.createTemporary(vSizedImage, FALSE, DBMS_LOB.CALL);
 ORDSYS.OrdImage.processCopy(vImageData, 'maxScale=75 75', vSizedImage);
 return vSizedImage;
END resize_img;
Colin 't Hart
9,51015 gold badges37 silver badges44 bronze badges
answered May 21, 2018 at 11:26
1
  • Do yo have any example for oracle 19c? Commented Aug 15, 2019 at 6:36

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.