title: CLOB value in out/return from plsql (invalid LOB locator specified: ORA-22275)
body: <p>I've got stored plsql procedure, that takes big text from file</p>
  
  <pre><code>create or replace 
  procedure dbst_load_a_file( p_file_name in varchar2, l_clob  out  clob )
      as
          l_bfile   bfile;
          dst_offset  number := 1 ;
          src_offset  number := 1 ;
          lang_ctx    number := DBMS_LOB.DEFAULT_LANG_CTX;
          warning     number;
      begin
          l_bfile := bfilename( 'SCHEMES_OF_PS', p_file_name );
          dbms_lob.fileopen( l_bfile );
          dbms_lob.loadclobfromfile(
            DEST_LOB     =&gt; l_clob
          , SRC_BFILE    =&gt; l_bfile
          , AMOUNT       =&gt; dbms_lob.getlength( l_bfile )
          , DEST_OFFSET  =&gt; dst_offset
          , SRC_OFFSET   =&gt; src_offset
          , BFILE_CSID   =&gt; DBMS_LOB.DEFAULT_CSID
          , LANG_CONTEXT =&gt; lang_ctx
          , WARNING      =&gt; warning);
          dbms_lob.fileclose( l_bfile );
      end;
  </code></pre>
  
  <p>and then I try to use it in this way:</p>
  
  <pre><code>  insert into SCHEME_SOURCE (SOURCE, ID, CODE) 
    values (exec dbst_load_a_file( 'SCHEMES_OF_PS', 'Konotop.svg' ), 15, 'Konotop');
  </code></pre>
  
  <p>or more correct:</p>
  
  <pre><code>declare
    myVal clob := empty_clob();
  
  begin
    DBMS_OUTPUT.PUT_LINE(myVal);
    dbst_load_a_file('Konotop.svg', myVal);
    DBMS_OUTPUT.PUT_LINE(myVal);
  end;
  </code></pre>
  
  <p>In the second case I get an error </p>
  
  <blockquote>
    <p>PL/SQL: numeric or value error: invalid LOB locator specified:
    ORA-22275</p>
  </blockquote>
  
  <p>in the first case, I suspect that syntax does not exist.</p>
  
  <p>How can I out/return CLOB parameter form the procedure/function for use it out of stored plsql</p>
  
  <p>If I've got this code</p>
  
  <pre><code>create or replace
  function dbst_load_a_file2( p_file_name in varchar2 ) return clob
      is
          l_clob  clob;
          l_bfile   bfile;
          dst_offset  number := 1 ;
          src_offset  number := 1 ;
          lang_ctx    number := DBMS_LOB.DEFAULT_LANG_CTX;
          warning     number;
      begin
          l_bfile := bfilename( 'SCHEMES_OF_PS', p_file_name );
          dbms_lob.fileopen( l_bfile );
          dbms_lob.loadclobfromfile( 
            DEST_LOB     =&gt; l_clob
          , SRC_BFILE    =&gt; l_bfile
          , AMOUNT       =&gt; dbms_lob.getlength( l_bfile )
          , DEST_OFFSET  =&gt; dst_offset
          , SRC_OFFSET   =&gt; src_offset
          , BFILE_CSID   =&gt; DBMS_LOB.DEFAULT_CSID
          , LANG_CONTEXT =&gt; lang_ctx
          , WARNING      =&gt; warning);
          dbms_lob.fileclose( l_bfile );
          return l_clob;
      end;
  
    insert into SCHEME_SOURCE (SOURCE, ID, CODE) 
    values (dbst_load_a_file2('Konotop.svg' ), 15, 'Konotop');
  </code></pre>
  
  <p>Then again got error</p>
  
  <blockquote>
    <p>SQL Error: ORA-06502: PL/SQL: numeric or value error: invalid LOB locator specified: ORA-22275
    ORA-06512: at "SYS.DBMS_LOB", line 890
    ORA-06512: at "VAG.DBST_LOAD_A_FILE2", line 12</p>
  </blockquote>
  
  <p>Thanks</p>