Unix Technical Forum

Help with PL/SQL and XmlType

This is a discussion on Help with PL/SQL and XmlType within the Oracle Miscellaneous forums, part of the Oracle Database category; --> Why does this? declare var XMLType; var2 XMLType; buf varchar2(2000); type refcur is ref cursor; rc refcur; begin var ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database > Oracle Miscellaneous

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 06:54 AM
stork
 
Posts: n/a
Default Help with PL/SQL and XmlType


Why does this?

declare
var XMLType;
var2 XMLType;
buf varchar2(2000);
type refcur is ref cursor;
rc refcur;
begin
var := xmltype('<PERSON> <NAME ike="uno"> ramesh </NAME> <NAME
ike="duo"> foo </NAME> </PERSON>');
var2 := var.extract( '/PERSON/NAME[@ike="uno"]' );

dbms_output.put_line( 'hello' );
OPEN rc FOR
SELECT extract(value(xooty), '//NAME/text()').getStringVal() AS
empno
FROM table(xmlsequence(extract(var, '/PERSON'))) xooty;
LOOP
fetch rc into buf;
dbms_output.put_line( buf );
exit when rc%notfound;
END LOOP;
end;

return this:

ramesh foo
ramesh foo

I wasn't expecting ramesh and foo to be combined on each row???

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 06:54 AM
Lewis C
 
Posts: n/a
Default Re: Help with PL/SQL and XmlType

On 2 Jun 2005 12:45:28 -0700, "stork" <tbandrow@mightyware.com> wrote:

>
>Why does this?
>
>declare
> var XMLType;
> var2 XMLType;
> buf varchar2(2000);
> type refcur is ref cursor;
> rc refcur;
>begin
> var := xmltype('<PERSON> <NAME ike="uno"> ramesh </NAME> <NAME
>ike="duo"> foo </NAME> </PERSON>');
> var2 := var.extract( '/PERSON/NAME[@ike="uno"]' );
>
> dbms_output.put_line( 'hello' );
> OPEN rc FOR
> SELECT extract(value(xooty), '//NAME/text()').getStringVal() AS
>empno
> FROM table(xmlsequence(extract(var, '/PERSON'))) xooty;
> LOOP
> fetch rc into buf;
> dbms_output.put_line( buf );
> exit when rc%notfound;
> END LOOP;
>end;
>
>return this:
>
>ramesh foo
>ramesh foo
>
>I wasn't expecting ramesh and foo to be combined on each row???


What were you expecting? Ramesh on one row and foo on another?

First of all that's not what you're asking for. You need to move some
code:

LOOP
fetch rc into buf;
dbms_output.put_line( buf );
exit when rc%notfound;
END LOOP;

Should be

LOOP
fetch rc into buf;
exit when rc%notfound;
dbms_output.put_line( buf );
END LOOP;

Now you're actually seeing the correct amount of data.

What exactly do you want to see as output?

In the line: extract(value(xooty), '//NAME/text()').getStringVal() AS
empno

You aren't specifying a specific NAME. Type,
extract(value(xooty), '//NAME[1]/text()').getStringVal() AS empno

You'll get ramesh on a line by itself. Is that along the lines of
what you were looking for?

Hope that helps,

Lewis


-----------------------------------------------------------
Lewis R Cunningham

Author, ItToolBox Blog: An Expert's Guide to Oracle
http://blogs.ittoolbox.com/oracle/guide/

Topic Editor, Suite101.com: Oracle Database
http://www.suite101.com/welcome.cfm/oracle

Sign up for courses here:
http://www.suite101.com/suiteu/default.cfm/416752
-----------------------------------------------------------
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 06:54 AM
stork
 
Posts: n/a
Default Re: Help with PL/SQL and XmlType



TJB replied to what Lewis C wrote:

<snip>

Thank you very much. What I'm ultimately trying to do is map an XPATH
query to some sort of a vector so that I can subsequently insert or
update into a normal table. I would like ideally to map an XPath query
to a table and then insert into in a bulk way (or use merge), but even
if I have to loop through a sequence of query results and do insert, it
would be a heck of a lot better than passing a bunch of arrays to proc
to mimic "recordness".

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-08-2008, 06:54 AM
Lewis C
 
Posts: n/a
Default Re: Help with PL/SQL and XmlType

On 3 Jun 2005 00:23:35 -0700, "stork" <tbandrow@mightyware.com> wrote:

>
>
>TJB replied to what Lewis C wrote:
>
><snip>
>
>Thank you very much. What I'm ultimately trying to do is map an XPATH
>query to some sort of a vector so that I can subsequently insert or
>update into a normal table. I would like ideally to map an XPath query
>to a table and then insert into in a bulk way (or use merge), but even
>if I have to loop through a sequence of query results and do insert, it
>would be a heck of a lot better than passing a bunch of arrays to proc
>to mimic "recordness".


You may be doing more work than you need to. I would need specific
details to make a specific recomendation but check out DBMS_XMLSave,
DBMS_XMLStore or possibly DBMS_XMLDOM. Some good stuff there.

Thanks,

Lewis


-----------------------------------------------------------
Lewis R Cunningham

Author, ItToolBox Blog: An Expert's Guide to Oracle
http://blogs.ittoolbox.com/oracle/guide/

Topic Editor, Suite101.com: Oracle Database
http://www.suite101.com/welcome.cfm/oracle

Sign up for courses here:
http://www.suite101.com/suiteu/default.cfm/416752
-----------------------------------------------------------
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:27 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com