Skip to content

Instantly share code, notes, and snippets.

@nehresma
Created August 23, 2010 02:41
Show Gist options
  • Save nehresma/544656 to your computer and use it in GitHub Desktop.
Save nehresma/544656 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'oci8'
def make_xml
xml = '';
100.times do |i|
xml += "<row><n>Nathan</n><a>123 Main</a><id>#{i+1}</id></row>"
end
"<rowset>#{xml}</rowset>"
end
sql = "
SELECT
*
FROM xmltable(
'/rowset/row'
PASSING xmltype(:xml)
COLUMNS
name VARCHAR2(50) PATH 'n',
address VARCHAR2(50) PATH 'a',
account_id INTEGER PATH 'id'
)
"
conn=OCI8.new('scott', 'tiger', 'testdb')
cursor = conn.parse(sql)
cursor.bind_param(':xml', OCI8::CLOB.new(conn, make_xml()))
cursor.exec()
while r = cursor.fetch()
puts r.inspect
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment