Home » Developer & Programmer » JDeveloper, Java & XML » How to format output of query for coulmn type XMLTYPE (11.2.0.3.0)
Re: How to format output of query for coulmn type XMLTYPE [message #614649 is a reply to message #614647] Sun, 25 May 2014 04:47 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Michel Cadot wrote on Wed, 21 May 2014 10:59

So you want we debug a code we don't see. Do you think it is wise?
Once again, copy and paste what you do and get.
For the moment you are just wasting our time.


Re: How to format output of query for coulmn type XMLTYPE [message #614686 is a reply to message #614647] Sun, 25 May 2014 15:43 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
It all depends on your data, which we can't see, so the following is just an example.

-- If there is more than one c2 in any row:
SCOTT@orcl12c> SELECT XMLSERIALIZE (DOCUMENT column_name INDENT SIZE = 2) res FROM table_name
  2  /

RES
--------------------------------------------------------------------------------
<?xml version="1.0"?>
<rowset>
  <row id="10" xml:space="preserve">
     <c1>ACCOUNTING</c1>
     <c2>NEW YORK</c2>
     <c2>BIG APPLE</c2>
   </row>
  <row id="20" xml:space="preserve">
     <c1>RESEARCH</c1>
     <c2>DALLAS</c2>
   </row>
  <row id="30" xml:space="preserve">
     <c1>SALES</c1>
     <c2>CHICAGO</c2>
     <c2>WINDY CITY</c2>
   </row>
  <row id="40" xml:space="preserve">
     <c1>OPERATIONS</c1>
     <c2>BOSTON</c2>
   </row>
</rowset>


1 row selected.


-- Then this will raise an error:
SCOTT@orcl12c> SELECT x.id, x.c1, x.c2
  2  FROM   table_name t,
  3  	    XMLTABLE
  4  	      ('//row'
  5  	       PASSING t.column_name
  6  	       COLUMNS
  7  		 id  NUMBER	   PATH '@id',
  8  		 c1  VARCHAR2(15)  PATH 'c1',
  9  		 c2  VARCHAR2(15)  PATH 'c2') x
 10  /
       XMLTABLE
       *
ERROR at line 3:
ORA-19279: XPTY0004 - XQuery dynamic type mismatch: expected singleton sequence
- got multi-item sequence


-- You can eliminate the error by declaring c2 as XMLTYPE:
SCOTT@orcl12c> COLUMN c2 FORMAT A30
SCOTT@orcl12c> SELECT x.id, x.c1, x.c2
  2  FROM   table_name t,
  3  	    XMLTABLE
  4  	      ('//row'
  5  	       PASSING t.column_name
  6  	       COLUMNS
  7  		 id  NUMBER	   PATH '@id',
  8  		 c1  VARCHAR2(15)  PATH 'c1',
  9  		 c2  XMLTYPE	   PATH 'c2') x
 10  /

        ID C1              C2
---------- --------------- ------------------------------
        10 ACCOUNTING      <c2>NEW YORK</c2>
                           <c2>BIG APPLE</c2>

        20 RESEARCH        <c2>DALLAS</c2>
        30 SALES           <c2>CHICAGO</c2>
                           <c2>WINDY CITY</c2>

        40 OPERATIONS      <c2>BOSTON</c2>

4 rows selected.


-- You can break it down further like so:
SCOTT@orcl12c> SELECT x.id, x.c1, y.c2
  2  FROM   table_name t,
  3  	    XMLTABLE
  4  	      ('//row'
  5  	       PASSING t.column_name
  6  	       COLUMNS
  7  		 id  NUMBER	   PATH '@id',
  8  		 c1  VARCHAR2(15)  PATH 'c1',
  9  		 c2  XMLTYPE	   PATH 'c2') x,
 10  	    XMLTABLE
 11  	      ('//c2'
 12  	       PASSING x.c2
 13  	       COLUMNS
 14  		 c2  VARCHAR2(15)  PATH '.') y
 15  /

        ID C1              C2
---------- --------------- ------------------------------
        10 ACCOUNTING      NEW YORK
        10 ACCOUNTING      BIG APPLE
        20 RESEARCH        DALLAS
        30 SALES           CHICAGO
        30 SALES           WINDY CITY
        40 OPERATIONS      BOSTON

6 rows selected.

Re: How to format output of query for coulmn type XMLTYPE [message #614690 is a reply to message #614262] Mon, 26 May 2014 01:24 Go to previous messageGo to next message
ledo60
Messages: 63
Registered: May 2014
Member
Big thanks ,
No errors for now .
The only issues are:
1-c2 coulmn data is truncated , i tried to increase this parameter COLUMN c2 FORMAT A50 with no success.
2-some data appered like this O?Ii , C?Ca i checked db nls and it's AL32UTF8 and AMERICAN_AMERICA.AR8MSWIN all was n't helpfull .
Was it XML type issue .

Please advice for the above 2 points.
Re: How to format output of query for coulmn type XMLTYPE [message #614715 is a reply to message #614690] Mon, 26 May 2014 07:04 Go to previous messageGo to next message
ledo60
Messages: 63
Registered: May 2014
Member
Any advice please
Re: How to format output of query for coulmn type XMLTYPE [message #614716 is a reply to message #614715] Mon, 26 May 2014 07:08 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

As you refuse to post what I request I refuse to help you.
Now you have to be patient and wait for Barbara.
See in her posts the hours when she is there and no more demand.

Re: How to format output of query for coulmn type XMLTYPE [message #614718 is a reply to message #614716] Mon, 26 May 2014 07:34 Go to previous messageGo to next message
ledo60
Messages: 63
Registered: May 2014
Member
Dear Barbara,
Thank you again for the great help , am waiting for your feedback .
Re: How to format output of query for coulmn type XMLTYPE [message #614752 is a reply to message #614690] Mon, 26 May 2014 13:46 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
ledo60 wrote on Sun, 25 May 2014 23:24

1-c2 coulmn data is truncated , i tried to increase this parameter COLUMN c2 FORMAT A50 with no success.


The "COLUMN c2 FORMAT A50" is just a SQL*Plus command that determines the width of the display column. Any excess data should be wrapped around to the next line, not truncated. It is the last line "c2 VARCHAR2(15) PATH '.') y" of the query that needs to be changed to "c2 VARCHAR2(50) PATH '.') y" or whatever size is sufficient to hold the largest value. For extremely large values, you may also need to SET LONG to a larger value to display all of it.


ledo60 wrote on Sun, 25 May 2014 23:24

2-some data appered like this O?Ii , C?Ca i checked db nls and it's AL32UTF8 and AMERICAN_AMERICA.AR8MSWIN all was n't helpfull .
Was it XML type issue .


Without seeing the data or at least knowing what language it is in and what characters are not being displayed properly, it is difficult to guess what the problem is. It is more likely a display problem than a data storage or conversion problem. You can use ascii and substr on the resulting column values to see what values are actually being returned. Also, you may find that if you spool the results to a file, then edit that file, you see different results than what is displayed in the window that you run it from.
Re: How to format output of query for coulmn type XMLTYPE [message #614874 is a reply to message #614752] Wed, 28 May 2014 01:51 Go to previous messageGo to next message
ledo60
Messages: 63
Registered: May 2014
Member
Thank you ,

1-Problem has been solved .
2-Language is Arabic ex.( O???,I?Ui? OiY,?I?I ?E?i), how to use ascii and substr ? the same output in the spool file.
Waiting your feedback .
Re: How to format output of query for coulmn type XMLTYPE [message #614875 is a reply to message #614874] Wed, 28 May 2014 02:12 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
Here is an example of how to get the ascii values of the first 3 characters in column c2. You can expand this to check however many characters you want. You may want to post this portion of your problem as a separate question about a character set issue with values not being displayed as stored and provide a link to this thread. This is not my area of expertise. It is past midnight here, so I am going to bed now. Hopefully, someone else will help you.

SCOTT@orcl12c> SELECT ASCII (SUBSTR (y.c2, 1, 1)) || ',' ||
  2  	    ASCII (SUBSTR (y.c2, 2, 1)) || ',' ||
  3  	    ASCII (SUBSTR (y.c2, 3, 1))
  4  FROM   table_name t,
  5  	    XMLTABLE
  6  	      ('//row'
  7  	       PASSING t.column_name
  8  	       COLUMNS
  9  		 id  NUMBER	   PATH '@id',
 10  		 c1  VARCHAR2(15)  PATH 'c1',
 11  		 c2  XMLTYPE	   PATH 'c2') x,
 12  	    XMLTABLE
 13  	      ('//c2'
 14  	       PASSING x.c2
 15  	       COLUMNS
 16  		 c2  VARCHAR2(15)  PATH '.') y
 17  /

ASCII(SUBSTR(Y.C2,1,1))||','||ASCII(SUBSTR(Y.C2,2,1))||','||ASCII(SUBSTR(Y.C2,3,
--------------------------------------------------------------------------------
78,69,87
66,73,71
68,65,76
67,72,73
87,73,78
66,79,83

6 rows selected.

Re: How to format output of query for coulmn type XMLTYPE [message #615215 is a reply to message #614875] Sun, 01 June 2014 00:38 Go to previous messageGo to next message
ledo60
Messages: 63
Registered: May 2014
Member
Please find a sample from output
ASCII(SUBSTR(Y.C2,1,1))||','||ASCII(SUBSTR(Y.C2,2,1))||','||ASCII(SUBSTR(Y.C2,3,
--------------------------------------------------------------------------------
50055,50061,50083,78,65,68

What we can gain from this?

Regarding NLS i will open a new case.

Re: How to format output of query for coulmn type XMLTYPE [message #615220 is a reply to message #615215] Sun, 01 June 2014 02:17 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
Unfortunately, I am not familiar with Arabic. However, you should be able to look up the codes in charts like the ones listed below and see if those are the characters that you should be seeing. If so, then it is a display problem and whatever character set is used by whatever interface you are using to display it is not compatible with Arabic. There is an Arabic forum near the bottom of the main forum page with the list of forums. You may find people with more experience with such problems there. I get all confused with multibyte codes and things that read from right to left.

http://www.ascii-code.com/

http://www.unicodetools.com/unicode/codepage-utf8.php?page=51
Re: How to format output of query for coulmn type XMLTYPE [message #615222 is a reply to message #615220] Sun, 01 June 2014 02:26 Go to previous messageGo to next message
ledo60
Messages: 63
Registered: May 2014
Member
Thanks Alot , you mean by ASCII output is the language use UTF8?please clear this confusion to me
Re: How to format output of query for coulmn type XMLTYPE [message #615282 is a reply to message #615222] Sun, 01 June 2014 11:32 Go to previous message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
ledo60 wrote on Sun, 01 June 2014 00:26
Thanks Alot , you mean by ASCII output is the language use UTF8?please clear this confusion to me


You can read about ASCII and Unicode (including UTF) here:

http://en.wikipedia.org/wiki/ASCII

http://en.wikipedia.org/wiki/Unicode

[Updated on: Sun, 01 June 2014 11:32]

Report message to a moderator

Previous Topic: xml data in columns
Next Topic: Grants for loadjava
Goto Forum:
  


Current Time: Wed Apr 24 23:46:10 CDT 2024