Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Okay, so what is happening is this:</p> <pre><code>SQL&gt; insert into t42 2 (id, version, type, data) 3 values (2, 0, 2, '&lt;?xml version="1.0" encoding="UTF-8"&gt;&lt;Test&gt;&lt;buffer&gt;&lt;A&gt;&lt;/buffer&gt;&lt;/Test&gt;') 4 / values (2, 0, 2, '&lt;?xml version="1.0" encoding="UTF-8"&gt;&lt;Test&gt;&lt;buffer&gt;&lt;A&gt;&lt;/buffer&gt;&lt;/Test&gt;') * ERROR at line 3: ORA-01465: invalid hex number SQL&gt; </code></pre> <p>This is because you are inserting ASCII text in a binary field. Binary fields expect Hexadecimal characters, and things like <code>&lt;</code>. <code>?</code>, <code>=</code> , etc ain't hex. What you need to do is cast it into hex, like this:</p> <pre><code>SQL&gt; insert into t42 2 values (2, 0, 2, utl_raw.cast_to_raw('&lt;?xml version="1.0" encoding="UTF-8"&gt;&lt;Test&gt;&lt;buffer&gt;&lt;A&gt;&lt;/buffer&gt;&lt;/Test&gt;')) 3 / 1 row created. SQL&gt; select * from t42 2 / ID TYPE VERSION ---------- ---------- ---------- DATA -------------------------------------------------------------------------------- 2 0 2 3C3F786D6C2076657273696F6E3D22312E302220656E636F64696E673D225554462D38223E3C5465 73743E3C6275666665723E3C413E3C2F6275666665723E3C2F546573743E SQL&gt; </code></pre> <p>This works easily because I am using Oracle 11g. If you are on a much earlier version of Oracle - definitley 8, possibly 9 - then you might have to use a two-step process. First insert a marker like this:</p> <pre><code>SQL&gt; insert into t42 2 values (1, 0, 1, empty_blob()) 3 / 1 row created. SQL&gt; </code></pre> <p>You can then populate the BLOB column like this:</p> <pre><code>SQL&gt; declare 2 b blob; 3 begin 4 b := utl_raw.cast_to_raw(rpad('FF',32767,'FF')); 5 update t42 6 set data = b 7 where id = 1; 8 end; 9 / PL/SQL procedure successfully completed. SQL&gt; select * from t42 2 / ID TYPE VERSION ---------- ---------- ---------- DATA -------------------------------------------------------------------------------- 1 0 1 46464646464646464646464646464646464646464646464646464646464646464646464646464646 46464646464646464646464646464646464646464646464646464646464646464646464646464646 SQL&gt; </code></pre> <p>Incidentally, if you're storing XML data, why store it as a BLOB rather than either as character data (CLOB) or from 9i onwards the native XMLType type? Well, one reason for not using XMLType is that your text is not well-formed XML, but I presume that is just an oversight ;)</p> <pre><code>SQL&gt; alter table t42 add xdata xmltype; Table altered. SQL&gt; insert into t42 2 (id, version, type, xdata) 3 values (4, 0, 2, xmltype('&lt;?xml version="1.0" encoding="UTF-8"&gt;&lt;Test&gt;&lt;buffer&gt;&lt;A&gt;&lt;/buffer&gt;&lt;/Test&gt;')) 4 / values (4, 0, 2, xmltype('&lt;?xml version="1.0" encoding="UTF-8"&gt;&lt;Test&gt;&lt;buffer&gt;&lt;A&gt;&lt;/buffer&gt;&lt;/Test&gt;')) * ERROR at line 3: ORA-31011: XML parsing failed ORA-19202: Error occurred in XML processing LPX-00254: invalid XML declaration Error at line 1 ORA-06512: at "SYS.XMLTYPE", line 310 ORA-06512: at line 1 SQL&gt; insert into t42 2 (id, version, type, xdata) 3 values (4, 0, 2, xmltype('&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;Test&gt;&lt;buffer&gt;A&lt;/buffer&gt;&lt;/Test&gt;')) 4 / 1 row created. SQL&gt; select * from t42 2 / ID TYPE VERSION ---------- ---------- ---------- DATA -------------------------------------------------------------------------------- XDATA -------------------------------------------------------------------------------- 4 2 0 &lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;Test&gt;&lt;buffer&gt;A&lt;/buffer&gt;&lt;/Test&gt; SQL&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload