title: utl_raw.cast_to_varchar2 behavior with different character sets
body: <p>I'm using a pdf package for oracle pl/sql called <code>pl_fpdf</code> to create pdfs on the fly (this is what I have to use at the moment).  It works on one database, but doesn't work on the other.  I believe I've narrowed down the issue to a difference in character set and the behavior of <code>utl_raw.cast_to_varchar2</code> when trying to convert image binary to ascii (base64).  </p>
  
  <p>The working character set is <code>WE8MSWIN1252</code>, and the other is <code>AL32UTF8</code> (seems to be much more common these days)</p>
  
  <p>My question is, how do I make <code>utl_raw.cast_to_varchar2</code> behave the same with <code>AL32UTF8</code> as it does with <code>WE8MSWIN1252</code> so that the resulting base64 image data is correct?</p>
  
  <p>Here's the code where I think the issue is.  If I'm completely wrong here, then please let me know.  </p>
  
  <pre><code>procedure p_putstream(pData in out NOCOPY blob) is
      offset integer := 1;
      lv_content_length number := dbms_lob.getlength(pdata);
      buf_size integer := 2000;
      buf raw(2000);
  begin
      p_out('stream');
      -- read the blob and put it in small pieces in a varchar
      while offset &lt; lv_content_length loop
        dbms_lob.read(pData,buf_size,offset,buf);
        p_out(utl_raw.cast_to_varchar2(buf), false);
        offset := offset + buf_size;
      end loop;
      -- put a CRLF at te end of the blob
      p_out(chr(10), false);
      p_out('endstream');
  exception
    when others then
     error('p_putstream : '||sqlerrm);
  end p_putstream;
  </code></pre>