Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert oracle blob to xml type

I have experience using MSSQL 2008 and I recently had to move from MSSQL to Oracle 10g. The people who designed the (Oracle) table, which has a column I need to extract data from, used a BLOB type column for the XML they need to store.

In MSSQL you would have simply stored your XML string in an XML type or used a VARCHAR(MAX). Assume a table myTable with a column called myColumn which is a VARCHAR(MAX) containing <ROOT><a>111</a></ROOT> If you wanted to convert the VARCHAR(MAX) type to an XML type you would simply write something like:

SELECT CONVERT(XML, myColumn) FROM myTable

if you wanted, you could then use XQuery to get data from the converted column, like so:

SELECT CONVERT(XML, myColumn).query('/ROOT/a')

How would you accomplish the same thing in Oracle 10g if myColumn was a BLOB, without having to write a stored procedure but still making it reusable? The text in the BLOB is UFT-8.

I would really appreciate your assistance, as I kind of need this in a hurry.

like image 447
user1279734 Avatar asked May 15 '13 06:05

user1279734


People also ask

What is XML data type in Oracle?

XMLType is a system-defined opaque type for handling XML data. It as predefined member functions on it to extract XML nodes and fragments. You can create columns of XMLType and insert XML documents into it.

Is it possible to convert a BLOB to a CLOB?

We can use two methods to convert a BLOB to a CLOB: dbms_lob. converttoclob. utl_raw.

Does Oracle support XML?

Oracle XML DB provides full support for all of the key XML standards, including but not limited to XML, XML Schema, Namespaces, DOM, XQuery, SQL/XML and XSLT. By providing full support for XML standards, Oracle XML DB supports native XML application development.

What is BLOB data type in Oracle?

A BLOB (binary large object) is a varying-length binary string that can be up to 2,147,483,647 characters long.


1 Answers

select
XMLType( BLOB_COLUMN,
         1 /* this is your character set ID.
                   1 == USASCII */
       ) as XML
from my_table;
like image 89
user2464519 Avatar answered Nov 07 '22 11:11

user2464519