Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ORA-22275 error: invalid LOB locator specified

I have a procedure that populates a BLOB variable with a PDF document. What I am trying to do is add logic to only display the PDF document within a 60 day period from a static date. See below:

check_staticdate     number(1); 

function DisplayPDF (audit in number) RETURN blob is

person_id     person.person_id%type;
z_lob         blob;
blob_length   NUMBER;


CURSOR getPDF(audit number) IS
   select report
   from report_table
   where report_type = 'PDF'
   and job_no = audit order by rec_no;


begin

/* Check Valid ID */
if not package.ValidID(person_id, check_only=>TRUE) then
   return z_lob;
end if;


/* Here is the case statement.*/
select case
   when exists
      (
       SELECT 'x' from table
       where table_id = person_id
       and trunc(sysdate) < trunc(table_static_date + 60)
      )

    then 1
    else 0
   end into check_staticdate
from dual;


if (check_staticdate = 0) then
   return z_lob;
end if;



open getPDF(audit);
fetch getPDF into z_lob;
close getPDF;
return z_lob;


end DisplayPDF;

The error I am receiving is: ORA-22275: invalid LOB locator specified.

I am new to Oracle SQL, and am unsure why my ValidID check works by returning z_lob but my case statement does not.

Edit: Adding full error stack

Failed to execute target procedure ORA-22275: invalid LOB locator specified

ORA-06512: at "SYS.WPG_DOCLOAD", line 51

ORA-06512: at "User.Package", line 733

ORA-06512: at line 33
like image 910
Phoenix Avatar asked Dec 20 '12 18:12

Phoenix


2 Answers

Initialise your lob with temporary first

DBMS_LOB.CREATETEMPORARY(z_lob,true); --true if you want it to be cached.
like image 120
Suman Avatar answered Nov 09 '22 08:11

Suman


Your function is probably returning (depending on your audit parameter value) a blob with a NULL value to the SYS.WPG_DOCLOAD method which throws the unhandled exception you see.

Perhaps you could modify your return z_lob; to be return nvl(z_lob, empty_blob());

like image 1
Michael O'Neill Avatar answered Nov 09 '22 07:11

Michael O'Neill