title: PLSQL ORA-22275: invalid LOB locator, when using CLOB/BLOB
body: <p>I havent done PLSQL for a long time and try to run a script to assist in querying a XML blob.</p>
  
  <p>The script is from an old thread, (<a href="https://community.oracle.com/thread/514518" rel="nofollow noreferrer">https://community.oracle.com/thread/514518</a>) aparently worked at that time but it seems to have problems running on 11.2.</p>
  
  <p>My dbs:
  Oracle Database 11g Release 11.2.0.4.0 - 64bit Production
  PL/SQL Release 11.2.0.4.0 - Production
  "CORE   11.2.0.4.0  Production"
  TNS for Linux: Version 11.2.0.4.0 - Production
  NLSRTL Version 11.2.0.4.0 - Production</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION XBLOB_To_CLOB(L_BLOB BLOB) RETURN CLOB IS
  L_CLOB CLOB;
  L_SRC_OFFSET NUMBER;
  L_DEST_OFFSET NUMBER;
  L_BLOB_CSID NUMBER := DBMS_LOB.DEFAULT_CSID;
  V_LANG_CONTEXT NUMBER := DBMS_LOB.DEFAULT_LANG_CTX;
  L_WARNING NUMBER;
  L_AMOUNT NUMBER;
  BEGIN
    IF DBMS_LOB.GETLENGTH(L_BLOB) &gt; 0 THEN
       DBMS_LOB.CREATETEMPORARY(L_CLOB, TRUE);
       L_SRC_OFFSET := 1;
       L_DEST_OFFSET := 1;
       L_AMOUNT := DBMS_LOB.GETLENGTH(L_BLOB);
  DBMS_LOB.CONVERTTOCLOB(L_CLOB,
    L_BLOB,
    L_AMOUNT,
    L_SRC_OFFSET,
    L_DEST_OFFSET,
    1,
    V_LANG_CONTEXT,
    L_WARNING);
  RETURN L_CLOB;
    ELSE
      L_CLOB:= TO_CLOB('');
      RETURN L_CLOB;
  End IF;
    DBMS_LOB.FREETEMPORARY(L_CLOB);
  END;
  </code></pre>
  
  <p>ORA-06502: PL/SQL:  numeric or value error: invalid LOB locator specified: 
  ORA-22275
  ORA-06512: in "SYS.DBMS_LOB", row 978
  ORA-06512: in "TEST.XBLOB_To_CLOB", row 14</p>
  
  <p>Currently, the script is not executed by another script or remot function, i just tried to run it in the SQL Developer.
  I know that there are a lot of questions concerning ORA-22275, but i found nothing that looks like my problem.
  The other scripts on the thread that apparently were running well, returns the same ORA-22275 error.</p>
  
  <p>Any suggestions whats wrong with the code or the dbs ?</p>