How to format output of query for coulmn type XMLTYPE [message #614262] |
Tue, 20 May 2014 03:27 |
|
ledo60
Messages: 63 Registered: May 2014
|
Member |
|
|
Hi,
How to format output of query for coulmn type XMLTYPE
Am trying this
select dbms_lob.substr (coulmn name,2000,1) from table name;
but got the below error.
ERROR at line 1:
ORA-06553: PLS-306: wrong number or types of arguments in call to 'SUBSTR'
Any advice please .
|
|
|
|
Re: How to format output of query for coulmn type XMLTYPE [message #614277 is a reply to message #614262] |
Tue, 20 May 2014 04:39 |
|
Michel Cadot
Messages: 68731 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
If your data is of XMLTYPEon it, it is meaningless to use SUBSTR on it (like to use SUBSTR on a number). You use XML functions to access part of the XML data.
However, if you really to do such thing, you can do it getting the string associated to the XML data:
SQL> select dbms_lob.substr(xmltype('<michel></michel>'),6,2) from dual;
select dbms_lob.substr(xmltype('<michel></michel>'),6,2) from dual
*
ERROR at line 1:
ORA-06553: PLS-306: wrong number or types of arguments in call to 'SUBSTR'
SQL> select dbms_lob.substr(xmltype('<michel></michel>').getclobval(),6,2) from dual;
DBMS_LOB.SUBSTR(XMLTYPE('<MICHEL></MICHEL>').GETCLOBVAL(),6,2)
--------------------------------------------------------------------------------------
michel
You can also directly used SUBSTR which will implicitly convert your XMLTYPE into a CLOB:
SQL> select substr(xmltype('<michel></michel>'),2,6) from dual;
SUBSTR
------
michel
(But it is better to know what you're doing. )
|
|
|
|
|
|
Re: How to format output of query for coulmn type XMLTYPE [message #614283 is a reply to message #614280] |
Tue, 20 May 2014 04:55 |
|
Michel Cadot
Messages: 68731 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
If the purpose is to have a readable format to display, you can use something like:
SQL> with
2 data as (
3 select xmltype('<parameters>
4 <parameter name="result"><value>success</value></parameter>
5 <parameter name="showBirthday"><value>false</value></parameter>
6 <parameter name="_wrCommand"><value>clearCacheBefore</value></parameter>
7 </parameters>') val
8 from dual
9 )
10 select value(x).extract('/parameters') res
11 from data, table(xmlsequence(extract(val, '/parameters'))) x
12 /
RES
--------------------------------------------------------------------------------
<parameters><parameter name="result"><value>success</value></parameter><paramete
r name="showBirthday"><value>false</value></parameter><parameter name="_wrComman
d"><value>clearCacheBefore</value></parameter></parameters>
SQL> with
2 data as (
3 select xmltype('<parameters>
4 <parameter name="result"><value>success</value></parameter>
5 <parameter name="showBirthday"><value>false</value></parameter>
6 <parameter name="_wrCommand"><value>clearCacheBefore</value></parameter>
7 </parameters>') val
8 from dual
9 )
10 select xmlserialize(document extract(value(x),'/parameters') indent size = 2) res
11 from data, table(xmlsequence(extract(val, '/parameters'))) x
12 /
RES
--------------------------------------------------------------------------------
<parameters>
<parameter name="result">
<value>success</value>
</parameter>
<parameter name="showBirthday">
<value>false</value>
</parameter>
<parameter name="_wrCommand">
<value>clearCacheBefore</value>
</parameter>
</parameters>
[Updated on: Tue, 20 May 2014 04:59] Report message to a moderator
|
|
|
Re: How to format output of query for coulmn type XMLTYPE [message #614284 is a reply to message #614283] |
Tue, 20 May 2014 05:03 |
|
Michel Cadot
Messages: 68731 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Or simpler:
SQL> with
2 data as (
3 select xmltype('<parameters><parameter name="result"><value>success</value>
4 </parameter><parameter name="showBirthday"><value>false</value>
5 </parameter><parameter name="_wrCommand"><value>clearCacheBefore</value>
6 </parameter></parameters>') val
7 from dual
8 )
9 select xmlserialize(document val indent size = 2) res
10 from data
11 /
RES
--------------------------------------------------------------------------------
<parameters>
<parameter name="result">
<value>success</value>
</parameter>
<parameter name="showBirthday">
<value>false</value>
</parameter>
<parameter name="_wrCommand">
<value>clearCacheBefore</value>
</parameter>
</parameters>
[Updated on: Tue, 20 May 2014 05:06] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
Re: How to format output of query for coulmn type XMLTYPE [message #614307 is a reply to message #614304] |
Tue, 20 May 2014 08:53 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
ledo60 wrote on Tue, 20 May 2014 18:34what is syntax here?
select xmlserialize(document column_name indent size = 2) res from table_name
as i got this error
ERROR at line 1:
ORA-00907: missing right parenthesis
And it was already told to you,
Lalit Kumar B wrote on Tue, 20 May 2014 17:11
All you need to do is replace "val" with the column name and select it from required table_name.
Column_name and table_name are not the keywords of the syntax. If you still fail to do so, then follow the steps Michel suggested in above comment.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|