Hi,
XMLTYPE can be retrieved as CLOB as following:
require ‘oci8’
def select_as_csv(conn, sqltext)
conn.exec(sqltext) do |row|
row.collect! do |col|
case col
when OCI8::LOB
col.read()
else
col
end
end
puts(row.join(‘,’))
end
end
conn = OCI8.new(‘ruby’, ‘oci8’)
#conn.exec(“CREATE TABLE po_tab OF XMLTYPE”)
#conn.exec(“CREATE TABLE po_xml_tab(poid NUMBER(10), poDoc XMLTYPE)”)
xml1 = ‘JohnSmith’
xml2 = ‘bar’
conn.exec(‘insert into po_tab values(:1)’, xml1)
conn.exec(‘insert into po_tab values(:1)’, xml2)
select_as_csv(conn, ‘select XMLTYPE.getClobVal(value(x)) from po_tab x’)
conn.exec(‘insert into po_xml_tab values(:1, :2)’, 1, xml1);
conn.exec(‘insert into po_xml_tab values(:1, :2)’, 2, xml2);
select_as_csv(conn, ‘select poid, XMLTYPE.getClobVal(podoc) from
po_xml_tab’)
conn.rollback
To insert a XML value, bind as a String.
To select a XML value, use XMLType.getClobVal(CLOBColumn).
I don’t know how to use it with Rails. :-<
I had not successed to use Rails with Oracle until last week, when
“Agile Web Develepment with Rails” Japanese edition was published.
I haven’t played with it but it would be cool to get it back as a REXML
document.
Yes, that would be cool.
Me too.
I suspect it’s because the XMLType datatype was added in Oracle 9i. I’m not
sure if Kubo would be willing to support this or if we need to wait for
ruby-oci9.
User defined types, which are added in Oracle 8, have not been
supported yet. :-p
I have a will to support XML Type. But ruby-oci8 is progressing in a
very slow tempo. It won’t be supported before summer.
–
KUBO Takehiro
email: [email protected]
web: http://www.jiubao.org
GnuPG fingerprint = 5F7B C8EF CA16 57D0 FDE1 9F47 C001 1F93 AC08 2262