Arif
Arif

Reputation: 29

Update statement works in normal mode, but not in procedure

I want to upload image from directory to database blob field. For those reason I write this code. Code alone works well but is not working as a procedure. What is the problem ? I cannot understand. Here is the code:

DECLARE
  dest_loc  BLOB;
  src_loc   BFILE;
BEGIN 
  src_loc:= BFILENAME('ALL_IMG_DIR','SDFGASDF1544.jpg');
  DBMS_LOB.FILEOPEN(src_loc);
  DBMS_LOB.CREATETEMPORARY(dest_loc,true);
  DBMS_LOB.LOADFROMFILE(dest_lob => dest_loc, src_lob  => src_loc,amount=>dbms_lob.getlength(src_loc) );

  UPDATE STUDENT     
    SET  IMAGE=dest_loc     
  WHERE 
    REG_CODE = 'SDFGASDF1544';        
    DBMS_LOB.CLOSE(src_loc);     
end;

But when I write this code as a procedure, like

CREATE OR REPLACE PROCEDURE img_to_blob_student(Vreg_code varchar2)
is
  dest_loc  BLOB;
  src_loc   BFILE;
BEGIN            
  src_loc   := BFILENAME('ALL_IMG_DIR','SDFGASDF1544.jpg');      
  DBMS_LOB.FILEOPEN(src_loc);    
  DBMS_LOB.CREATETEMPORARY(dest_loc,true);    
  DBMS_LOB.LOADFROMFILE(
    dest_lob => dest_loc, 
    src_lob  => src_loc,
    amount=>dbms_lob.getlength(src_loc) 
  );
  UPDATE STUDENT 
  SET  IMAGE=dest_loc     
  WHERE REG_CODE = 'SDFGASDF1544';        
  DBMS_LOB.CLOSE(src_loc);          
end;

And call like

img_to_blob_student('123');

I get

ERROR IS: `ORA-00900: invalid SQL statement in procedure` 

Upvotes: 1

Views: 46

Answers (1)

J. Chomel
J. Chomel

Reputation: 8393

to call the procedure, did you use the execstatement?

exec img_to_blob_student('123');

Upvotes: 1

Related Questions