Truncation of result XML using Select xmlelement
I am trying the new XMLELEMENT Function of Select, and the resulting XML is truncating. It appears that only very short XML strings return properly. All others truncate.
Example:
Table Token
Token_Id Number;
Token_load_id Varchar2(64);
Table Batch
Batch_Id Number;
select xmlelement("Batch", xmlelement("BatchId" , b.batch_Id),
xmlelement("Card", xmlelement("TokenId" , t.token_Id),
xmlelement("TokenLoadId", substr(t.token_load_Id,1,20)))) as "XMLResult"
from token t, token_batch b
where t.batch_id = b.batch_id
and token_id < 110;
Result:
XMLResult
<Batch>
<BatchId>1</BatchId>
<Card>
<TokenId>100</TokenId>
<TokenLoa
<Batch>
<BatchId>1</BatchId>
<Card>
<TokenId>101</TokenId>
<TokenLoa
So why would the result truncate? I built the above query based on examples in the CD doc set.
If you are using SQL*PLUS to execute your queries and view the results, then you need to modify the settings that govern output of CLOBS (the default type for those fatty XML strings) in SQL*PLUS. I believe the one you need is 'long'.
A LONG, CLOB or NCLOB column's width defaults to
the value of SET LONGCHUNKSIZE or SET LONG, whichever
one is smaller.Try the following:
SQL> Set long 1000
Rich
Similar Messages
-
Strange behaviour of result area after select with XML-function
Hello,
i execute following statement
SELECT XMLElement("arow",
XMLElement("bcol", a.b) ,
XMLElement("ccol", a.c) d
) as res FROM a;
and get afterwards a completly grey result area.
SQL Developer says that it used 0.006 seconds and 5 rows are retrieved.
After clicking in the result i see the column header and the rowcount
on the left side, but the rest is grey.
I am using SQL Developer 1.5.4 on Windows XP Professional Service
Pack 3 and Oracle 10.2.0.4.
I also search in Metalink if this behaviour is a bug, but i didn't find anything.
In this forum i found a solution (getclobval). But i can not use this solution
for several reasons.
How to reproduce:
<--start-->
create table a (b number not null primary key, c varchar2(10 char));
insert into a (b, c) values (1, 'a');
insert into a (b, c) values (2, 'b');
insert into a (b, c) values (3, 'c');
insert into a (b, c) values (4, 'd');
insert into a (b, c) values (5, 'e');
commit;
Execute the statement above.
<--stop-->
If you need further information, let me know.
Thanks for your help in advance.
Yours,
ErichErich,
It looks like you need to provide more details. I can't replicate this on 155 or the latest 2.1 early adopter, on either a remote 10g database or a local 11g database. It sounds like it may be related to your setup, perhaps a slow network connection? The JDK sounds fine, although I'm testing on 1.6_15 for the 1.5.5 installation. Is it only related to the XML queries - do you see this with other queries?
Sue -
hi I am having problem in formatting XML file which I generated with xmlelement() when I execute it gives me putput in a single line
is there any way that I got my output as a XML file HAS......That is expected behavior. PRETTY print(ing) is only needed for humans. XML Parsers don't need the XML to be pretty printed. If you open the XML file in a browser like Windows Explorer or Firefox, the browser will pretty print the output for you.
In all, the "single line" output is done because of PERFORMANCE reasons (lack of unneeded end of line and CTRL line breaks etc)
SELECT xmlelement("Employee Name", dummy) as "XML RESULT"
FROM DUAL;
<Employee Name>X</Employee Name>
SELECT xmlelement("Employee Name", xmlelement("SurName", dummy)
, xmlelement("LastName", dummy)
) as "XML RESULT"
FROM DUAL;
<Employee Name><SurName>X</SurName><LastName>X</LastName></Employee Name>
XMLSERIALIZE can pretty print the output if needed via INDENTation
SELECT XMLSERIALIZE(CONTENT xmlelement("Employee Name", xmlelement("SurName", dummy), xmlelement("LastName", dummy)) as CLOB indent SIZE=1 )
FROM DUAL;
<Employee Name>
<SurName>X</SurName>
<LastName>X</LastName>
</Employee Name> -
Use 1 stylesheet to translate 2 xml documents(raw data)into one result xml
I have one java application which can generate two xml documents (raw data), now i want to have one result xml which contains contents of these two xml documents(raw data) by using one stylesheet. is it possible?
how to match template in the stylesheet?
how to let the stylesheet know that it should read second raw xml?Yes it is possible.
You didn't say whether you want to do this by invoking the transformation from a Java program, or with a stand-alone transformer, and which one.
I've done an application where I had a main XML file and a secondary XML file. I invoked the transformation from Java, and passed a parameter to the stylesteet. It winds up looking like a variable ($parm for example).
Here is the declaration of the param in the stylesheet.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="list" />Next, I use the document function to read the file and produce a result tree (like a DOM object, in a sense).
<xsl:variable name="phonemes"
select="document($list)" />Then, you can use code like the following to look for content in the secondary file:
<xsl:if test="$phonemes/phonemes/allsounds[phoneme=$sound]" >This was complex, but it works.
Another approach would be to have a small XML file with the names of the
two XML files you want to process. You could do a for-each to process each of the tags in this little file, use the document function to read in the file and copy th eoutput to where you need it.
So, in that case, you would be processsing 3 files rather than 2. If you are invoking from Java, the third file could be coded in a String rather than having to physically write it out.
You've got a few ideas to consider.
Dave Patterson -
Ps query results to xml using xml link function registry
In People tools version 8.46 we need something like where the ps query result output is in the form of XML so that it can be used for external system. The catch I cannot use webservices. It is something like opening peoplesoft queires form excel using hyperlink but in this case we need xml. I looked at David Vandiver's Excel XML libraries which open the data in excel but is there something where the hyperlink output is xml using xml link function registry. I have capatured the data in rowset and now need to create mime type of xml to write the data
thanks in advance
vinnIf I understand correctly, you want to use something like Microsoft Excel's web queries to get data from a PeopleSoft query in XML format. I have never done this before, but if I were to implement this, here is what I would do in PT 8.46:
1. Create an unstructured message in app designer.
2. Create a user that only has access to the queries you want to expose to Excel
3. Write synchronous message handler PeopleCode to call SwitchUser to switch to a specific query user rather than the generic integration broker user and execute a query, returning the results in XML (see [Query.RunToRowsest|http://download.oracle.com/docs/cd/E13292_01/pt849pbr0/eng/psbooks/tpcr/htm/tpcr31.htm#d0e113933] for an example).
4. Call the message through IB using the HTTP GET URL format as defined in PeopleBooks: [http://download.oracle.com/docs/cd/E13292_01/pt849pbr0/eng/psbooks/tibr/book.htm?File=tibr/htm/tibr33.htm#H4026|http://download.oracle.com/docs/cd/E13292_01/pt849pbr0/eng/psbooks/tibr/book.htm?File=tibr/htm/tibr33.htm#H4026]. -
How to generate XML file using select files manually option in MOPz
Hi Guru's!
Can someone tell me how can I generate XML file not using the calculate automatically option but using select files manually. thanks!Hi Maix,
You may manually add the files into download basket and then approve it.
Use the SCN document below for the steps.
http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/10b14f0c-b9af-2e10-ba83-f05ebcfbc3c2?QuickLink=index&…
Hope this helps.
Regards,
Deepak Kori -
Creating xml file using select statement
Hi,
when i run a select statement to generate Xml file in - oracle Db - 10.2.0.4.0
i'm getting,
SELECT XMLELEMENT("Emp", XMLATTRIBUTES(e.empno AS "ID")) AS "Emp Element" FROM emp e WHERE row
num=1
Emp Element()
XMLTYPE()
But, in 10.2.0.3.0 , i'm getting,
Emp Element
<Emp ID="7369"></Emp>
could anyone tell me whey this difference , is it version realted itself or i need to change any settings
thanks
Jodusfor 10.2.0.3.0 DB the client is 10.2.0.3.0
for 10.2.0.4.0 DB the client is 10.1.0.4.2 - Upgraded the client to 10.2.0.3.0 and it is working fine. Thanks.
the same select statement Executing from SqlPlus
Edited by: Jodus on Jul 30, 2009 1:47 PM -
How to use results from first select to run from second select w/subselect?
-- I create a table with three fields: Name, Amount, and a Trans_Date.
CREATE TABLE TEST
NAME VARCHAR2(19) NULL,
AMOUNT VARCHAR2(8) NULL,
TRANS_DATE DATE NULL
-- I insert a few rows into my table:
INSERT INTO TEST ( TEST.NAME, TEST.AMOUNT, TEST.TRANS_DATE ) VALUES ( 'Bill', '110', TO_DATE('06/01/2005 08:00:00 PM', 'MM/DD/YYYY HH12:MI:SS PM') );
INSERT INTO TEST ( TEST.NAME, TEST.AMOUNT, TEST.TRANS_DATE ) VALUES ( 'Bill', '20', TO_DATE('06/02/2005 08:00:00 PM', 'MM/DD/YYYY HH12:MI:SS PM') );
INSERT INTO TEST ( TEST.NAME, TEST.AMOUNT, TEST.TRANS_DATE ) VALUES ( 'Bill', '110', TO_DATE('06/03/2005 08:00:00 PM', 'MM/DD/YYYY HH12:MI:SS PM') );
INSERT INTO TEST ( TEST.NAME, TEST.AMOUNT, TEST.TRANS_DATE ) VALUES ( 'Bill', '21', TO_DATE('06/04/2005 08:00:00 PM', 'MM/DD/YYYY HH12:MI:SS PM') );
INSERT INTO TEST ( TEST.NAME, TEST.AMOUNT, TEST.TRANS_DATE ) VALUES ( 'Bill', '68', TO_DATE('06/04/2005 08:00:00 PM', 'MM/DD/YYYY HH12:MI:SS PM') );
INSERT INTO TEST ( TEST.NAME, TEST.AMOUNT, TEST.TRANS_DATE ) VALUES ( 'Bill', '110', TO_DATE('06/05/2005 08:00:00 PM', 'MM/DD/YYYY HH12:MI:SS PM') );
INSERT INTO TEST ( TEST.NAME, TEST.AMOUNT, TEST.TRANS_DATE ) VALUES ( 'Bill', '20', TO_DATE('06/06/2005 08:00:00 PM', 'MM/DD/YYYY HH12:MI:SS PM') );
INSERT INTO TEST ( TEST.NAME, TEST.AMOUNT, TEST.TRANS_DATE ) VALUES ( 'Bill', '43', TO_DATE('06/07/2005 08:00:00 PM', 'MM/DD/YYYY HH12:MI:SS PM') );
INSERT INTO TEST ( TEST.NAME, TEST.AMOUNT, TEST.TRANS_DATE ) VALUES ( 'Bill', '77', TO_DATE('06/08/2005 08:00:00 PM', 'MM/DD/YYYY HH12:MI:SS PM') );
INSERT INTO TEST ( TEST.NAME, TEST.AMOUNT, TEST.TRANS_DATE ) VALUES ( 'Bill', '221', TO_DATE('06/09/2005 08:00:00 PM', 'MM/DD/YYYY HH12:MI:SS PM') );
INSERT INTO TEST ( TEST.NAME, TEST.AMOUNT, TEST.TRANS_DATE ) VALUES ( 'Bill', '43', TO_DATE('06/10/2005 08:00:00 PM', 'MM/DD/YYYY HH12:MI:SS PM') );
INSERT INTO TEST ( TEST.NAME, TEST.AMOUNT, TEST.TRANS_DATE ) VALUES ( 'Bill', '73', TO_DATE('06/10/2005 08:00:00 PM', 'MM/DD/YYYY HH12:MI:SS PM') );
commit;
-- These are the current select statements I am using:
-- Last 10 days
SELECT SUM(t.AMOUNT) AMOUNT10, NULL AMOUNT5, NULL AMOUNT3
FROM test t
WHERE t.NAME = 'Bill'
AND t.TRANS_DATE >= TO_DATE('06/01/2005 08:00:00 PM','mm/dd/yyyy hh12:mi:ss am')
AND t.TRANS_DATE <= TO_DATE('06/10/2005 08:00:00 PM','mm/dd/yyyy hh12:mi:ss am')
UNION ALL
-- Last 5 days
SELECT NULL AMOUNT10, SUM(t.AMOUNT) AMOUNT5, NULL AMOUNT3
FROM test t
WHERE t.NAME = 'Bill'
AND t.TRANS_DATE >= TO_DATE('06/06/2005 08:00:00 PM','mm/dd/yyyy hh12:mi:ss am')
AND t.TRANS_DATE <= TO_DATE('06/10/2005 08:00:00 PM','mm/dd/yyyy hh12:mi:ss am')
UNION ALL
-- Last 3 days
SELECT NULL AMOUNT10, NULL AMOUNT5, SUM(t.AMOUNT) AMOUNT3
FROM test t
WHERE t.NAME = 'Bill'
AND t.TRANS_DATE >= TO_DATE('06/08/2005 08:00:00 PM','mm/dd/yyyy hh12:mi:ss am')
AND t.TRANS_DATE <= TO_DATE('06/10/2005 08:00:00 PM','mm/dd/yyyy hh12:mi:ss am');
-- This is the current output:
AMOUNT10 AMOUNT5 AMOUNT3
916 NULL NULL
NULL 477 NULL
NULL NULL 414
Is there a way to combine these statements to speed up performance?
I'm thinking there should be a way to select all the rows in the last tens days, and then just from those results, run another select to get the results for the last 2, 3, or 5 days using subselects in some way. Any help is appreciated. Thanks.
I don't mind getting results in one row like this:
AMOUNT10 AMOUNT5 AMOUNT3
916 477 414Thank you for providing create table and insert scripts, along with the query so far. It makes providing an answer so much easier.
Does this help?
SQL> select sum(amount10) amount10, sum(amount5) amount5, sum(amount3) amount3
2 from
3 (
4 select
5 case when
6 t.TRANS_DATE >= TO_DATE('06/01/2005 08:00:00 PM','mm/dd/yyyy hh12:mi:ss am')
7 AND t.TRANS_DATE <= TO_DATE('06/10/2005 08:00:00 PM','mm/dd/yyyy hh12:mi:ss am')
8 then
9 amount
10 end amount10,
11 case when
12 t.TRANS_DATE >= TO_DATE('06/06/2005 08:00:00 PM','mm/dd/yyyy hh12:mi:ss am')
13 AND t.TRANS_DATE <= TO_DATE('06/10/2005 08:00:00 PM','mm/dd/yyyy hh12:mi:ss am')
14 then
15 amount
16 end amount5,
17 case when
18 t.TRANS_DATE >= TO_DATE('06/08/2005 08:00:00 PM','mm/dd/yyyy hh12:mi:ss am')
19 AND t.TRANS_DATE <= TO_DATE('06/10/2005 08:00:00 PM','mm/dd/yyyy hh12:mi:ss am')
20 then
21 amount
22 end amount3
23 from
24 test t
25 where
26 t.name = 'Bill'
27 AND t.TRANS_DATE >= TO_DATE('06/01/2005 08:00:00 PM','mm/dd/yyyy hh12:mi:ss am')
28 AND t.TRANS_DATE <= TO_DATE('06/10/2005 08:00:00 PM','mm/dd/yyyy hh12:mi:ss am')
29 );
AMOUNT10 AMOUNT5 AMOUNT3
916 477 414
SQL>Message was edited by:
3360
Durn, pipped by flakey forums and the return of v garcia. -
SQL unicode to XML using XMLForest
I'm using XMLForest to retrieve some data from the db. One of the columns has unicode characters such as "Ă". I use XMLForest to read in this data, but the result turns this Ă into a "?". How do I keep the unicode format? I need to output this xml to html using an xsl sheet, and the xsl sheet just converts the "?" as is.
Example:
table with firstnames, and lastnames
firstname lastname
Ăbram Smîth
I use XMLForest as:
SELECT XMLForest (table.firstname, table.lastname);
The result returns as:
<firstname>?bram</firstname><lastname>Sm?th</lastname>
So my xsl sheet returns the xml as just
?bram Sm?th
Is there a method I can follow such that I know what unicode characters are being used?
fyi: this is to run in a java application using Oracle JDBC. I use the following to get the XML string from the XMLType. This is after executing the query using an OraclePreparedStatement and putting the result into an OracleResultSet (ors).
StringBuilder builder = new StringBuilder();
oracle.xdb.XMLType xml = XMLType.createXML(ors.getOPAQUE(1));
builder.append(xml.getStringVal()+"\n");
xml.close();
System.out.println(builder.toString());There is a slight work-around to this, but I wouldn't highly recommend it. Its just something that I was able to use, since our comany's database is using US7ASCII.
ASCIISTR will return the ASCII of the query result. When there is ascii that is not in the standard ASCII such as 죡, the character is replaced by its unicode value such as, "\C8E1". I parse the xml query result that is returned, for the character "\". Then using Java:
int i = queryResult.indexOf("\\");// i = the index of "\"
//there's usually 4 characters in the unicode, so i+1 to i+5.
String unicode = queryResult.substring(i+1,i+5);
int con = Integer.parseInt(unicode, 16);
char c = (char) con;
queryResult.replace(i, i+5, ""+c);//replace the ascii with actual character.
I replace the "\C8E1" in the query result with char c.
For the example that is provided, the query would be:
SELECT XMLElement("Row", XMLForest(ASCIISTR(data_value))) FROM test;
The result would return as:
<Row><DATA_VALUE>Abram Sm\00EEth</DATA_VALUE></Row>
the \00EE would be replaced with î.
Just an idea, if anyone else is in the same situation. -
Urgent- xml parsing failed - xmlelement
hi
what am i doing wrong here?
oracle 10.2.0.1
AL32UTF8 charset.
trying to generate an xml using xdk
running this
SELECT XMLELEMENT("date", sysdate) FROM dual
expecting this
<date>2005-10-25</date>
getting this
ORA-31011: XML parsing failed
tried this:
ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MM-YYYY'
result: session altered
tried re-running select query, but same bad result.
dbms_xmlgen,xmlagg and other commands run fine.
i need to do this so that i can use special inline formatting such as this:
<sa>
<object class="asdad" name="asd">
<attribute name="as">
<string>asd</string>
</attribute>
</object>
<object>
</object>
</sa>
setformattype doesnt help in xmlgen since such format (<object class="asd" name="sad">) doesnt seem to be possible.
YELP!
is there a workaround possible without using xmlelement? what am i doing wrong in xmlelement??XML Element isn't part of XDK at all. It's a part of the SQL/XML publishing capability of XML DB. Can you make sure that you do not have something that is masquerading as XMLElement on your system
Eg make sure you get this output
SQL> desc XMLELEMENT
ERROR:
ORA-04043: object XMLELEMENT does not existIf something get's described by the describe please drop it..
Can you try
SQL> select xmlElement("FOO",'baa') from dual;
XMLELEMENT("FOO",'BAA')
<FOO>baa</FOO>and
SQL> select XMLFOREST('baa' as "FOO") from dual;
XMLFOREST('BAA'AS"FOO")
<FOO>baa</FOO> -
Hi ,
I am forming XMLs using XMLBeans whose XSDs been provided.
The tag values are coming from the database which I am querying.
and then adding the various tags as per the XSD.
In the End,I am using the ,doc.toString() where doc is the Document object as per the XSD.
and then writing it to a file.
I want to know ,what limitations can this method have or what might be a better way.
Will there be a restriction on the size of the xml being formed??
Thanks in AdvanceI modified the code :
[code]
Select P.PAT_MRN,
XMLELEMENT("Patient",
(XMLELEMENT("pat_mrn", P.pat_mrn)),
(XMLForest(cm_results_o_t(CAST(MULTISET
(SELECT O.COMP_NAME AS "ID"
FROM oper O
WHERE O.ENCOUNTER_ID =
E.ENCOUNTER_ID) AS
component_list_t)) AS
"Results"))) AS Orderxml
FROM PATIENT P
JOIN ENCOUNT E
ON P.PAT_MRN = E.PAT_MRN
AND P.PAT_MRN = '63280'
AND E.ENCOUNTER_ID = 42
[/code]
Need the Res_LIST tag to be removed which is coming from object type. -
Hello,
I am using Oracle SOA Suite 11.1.1.4.0 While executing the XQuery example bpel-108-UsingXQuery I am facing the following problem/error.
The Xquery in the example is:
xquery version "1.0";
declare namespace ns0 = "http://example.com/bpel/books";
declare namespace ns1 = "http://samples.otn.com/xquerysample";
declare variable $category as node() external;
declare variable $publisher as xs:string external;
<bookReport>
for $b in //ns0:BOOKS/ns0:ITEM
where data($b/ns0:PUBLISHER) = $publisher
order by string-length($b/TITLE) return
<book>
<author> { data($b/ns0:AUTHOR) } </author>
<title> { data($b/ns0:TITLE) } </title>
<price>{ data(doc("pricelist.xml")/ns1:pricelist/ns1:product[1]/ns1:price) }</price>
<publisher>{ $publisher }</publisher>
{ $category }
</book>
</bookReport>
The variable $publisher, declared in 'declare variable $publisher as xs:string external' shall have the value 'Associated Press' as this has been assigned in the BPEL but it has in fact the value 'oracle.xml.parser.v2.XMLElement@8b8e58'.
The variable $category has the correct value.
What is here wrong or is it a bug in 11.1.1.4.0 in the oracle.xml.parser.v2.XMLElement class.What a mess:
org.w3c.Element element = (org.w3c.Element) payload.get("payload");
private Document writeOraXMLtoDocument(org.w3c.Element payload) throws ParserConfigurationException, SAXException, IOException, TransformerException{
ByteArrayInputStream inputStream = new ByteArrayInputStream(writeXMLToStream(new DOMSource(payload)).toByteArray());
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder =factory.newDocumentBuilder();
return builder.parse(inputStream);
private ByteArrayOutputStream writeXMLToStream(Source source) throws TransformerException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
// Prepare the output file
Result result = new StreamResult(out);
// Write the DOM document to the file
TransformerFactory x = TransformerFactory.newInstance();
Transformer xformer = x.newTransformer();
xformer.transform(source, result);
return out;
Note, that you have to use the oracle transformer located in the xmlparserv2.jar
if it is not your default transformer , you have to set it at least for the above code by System.setProperty("javax.xml.transform.TransformerFactory","..classname..."); -
How do I generate XML using internal variables in a procedure
I know there is a way to generate XML inside a procedure by querying the database such as
SELECT XMLELEMENT("Emp",
XMLFOREST(e.employee_id, e.last_name, e.salary))
"Emp Element"
FROM employees e WHERE employee_id = 204;
Emp Element
<Emp>
<EMPLOYEE_ID>204</EMPLOYEE_ID>
<LAST_NAME>Baer</LAST_NAME>
<SALARY>10000</SALARY>
</Emp>
What I have unsuccessfully been trying to do is to basically do the same thing except using internal variables like
DECLARE
l_keytype CONTACTINFO.KEYTYPE%TYPE;
l_keyvalue CONTACTINFO.KEYVALUE%TYPE;
l_pricetag CONTACTINFO.PRICATEG%TYPE;
l_xmlout CLOB;
BEGIN
l_keytype := '1';
l_keyvalue := '3333';
l_pricetag := '10';
SELECT XMLELEMENT("ParamSet", .........................this is line 13
XMLFOREST(l_keytype as "keytype", l_keyvalue as "keyvalue", l_pricetag as "pricetag"))
"ParamSet Element"
INTO l_xmlout FROM DUAL;
DBMS_OUTPUT.PUT_LINE('l_xmlout = ' || l_xmlout);
end;
What I'd like it to generate is
<ParamSet>
<KEYTYPE>1 </KEYTYPE>
<KEYVALUE>3333</KEYVALUE>
<PRICETAG>100</PRICETAG>
</ParamSet>
But what I get is a compile error
Error report:
ORA-06550: line 13, column 19: (line 13 is SELECT XMLELEMENT("ParamSet", )
PL/SQL: ORA-00932: inconsistent datatypes: expected NUMBER got -
ORA-06550: line 13, column 1:
PL/SQL: SQL Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Also, I've been told that one issue with XMLFOREST is that if the value is null it won't generate the XML for it. Not good. I will still need the XML even if it is empty. Please help.Darn, Marc beat me. Here was my answer showing an alternative for returning an XMLType, since that is what the query returns as he said.
DECLARE
l_keytype VARCHAR2(5);
l_keyvalue VARCHAR2(5);
l_pricetag VARCHAR2(5);
l_xmlout CLOB;
l_xmltype XMLTYPE;
BEGIN
l_keytype := '1';
l_keyvalue := '3333';
l_pricetag := '10';
SELECT XMLELEMENT("ParamSet",
XMLFOREST(l_keytype as "keytype",
l_keyvalue as "keyvalue",
l_pricetag as "pricetag")).getClobVal()
INTO l_xmlout
FROM DUAL;
DBMS_OUTPUT.PUT_LINE('l_xmlout = ' || l_xmlout);
SELECT XMLELEMENT("ParamSet",
XMLFOREST(l_keytype as "keytype",
l_keyvalue as "keyvalue",
l_pricetag as "pricetag"))
INTO l_xmltype
FROM DUAL;
DBMS_OUTPUT.PUT_LINE('l_xmlout = ' || l_xmltype.getClobVal());
end;Here is a link to Oracle's on-line documentation
http://www.oracle.com/technetwork/indexes/documentation/index.html
so that you can pick your version and search for XMLElement and XMLForest to see their difference as well as listening to us. -
Formatting XML using DBMS_XMLGEN
Hi.
Having Problems with generating XML out of a query using nested table types
-- Heres a test case
drop type test_tab
drop type test_type
drop type sub_type_tab
drop type sub_type
create or replace type sub_type as object ( "@a" varchar2(10), "@b" varchar2(10) );
create or replace type sub_type_tab as table of sub_type;
create or replace type test_type as object ( "@c" VARCHAR2(10), test sub_type_tab );
CREATE OR REPLACE TYPE test_tab AS TABLE OF test_type;
CREATE OR REPLACE VIEW test_view OF test_type
WITH OBJECT IDENTIFIER ("@c")
AS
SELECT
'C',
CAST(MULTISET(SELECT 'A', 'B' FROM DUAL) AS sub_type_tab)
FROM dual
The resultant XML out of DBMS_XMLGEN.GETXML is :
<?xml version="1.0"?>
<ROWSET>
<ROW c = "C">
<TEST>
<SUB_TYPE a="A" b="B"/>
</TEST>
</ROW>
</ROWSET>
As you can see as a consequence of the column collection type alias in the view
i have an extraneous <TEST> tag.
Does anyone know how I can remove this tag entry?
Thanks in advanceMarco,
I tryed to work with dbms_xslprocessor.clob2file,
that works good,
but what is in this matter with encoding UTF-8 ?
in my understandig, the xmltyp created should be UTF8 (16),
but when open the xml-file in xmlSpy as UTF-8,
it is not well ( german caracter like Ä, Ö .. ):
my dbms is
NLS_CHARACTERSET = WE8MSWIN1252
NLS_NCHAR_CHARACTERSET = AL16UTF16
NLS_RDBMS_VERSION = 10.2.0.1.0
-- test:
create table nh_test ( s0 number, s1 varchar2(20) ) ;
insert into nh_test (select 1,'hallo' from dual );
insert into nh_test (select 2,'straße' from dual );
insert into nh_test (select 3,'mäckie' from dual );
insert into nh_test (select 4,'euro_€' from dual );
commit;
select * from nh_test ;
S0 S1
1 hallo
1 hallo
2 straße
3 mäckie
4 euro_€
declare
rc sys_refcursor;
begin
open rc FOR SELECT * FROM ( SELECT s0,s1 from nh_test );
dbms_xslprocessor.clob2file( xmltype( rc ).getclobval( ) , 'XML_EXPORT_DIR','my_xml_file.xml');
end;
( its the same when using output with DBMS_XMLDOM.WRITETOFILE )
open in xmlSpy is:
<?xml version="1.0"?>
<ROWSET>
<ROW>
<S0>1</S0>
<S1>hallo</S1>
</ROW>
<ROW>
<S0>2</S0>
<S1>straޥ</S1>
</ROW>
<ROW>
<S0>3</S0>
<S1>m㢫ie</S1>
</ROW>
<ROW>
<S0>4</S0>
<S1>euro_</S1>
</ROW>
</ROWSET>
regards
Norbert -
Creating XML using DBMS_XMLGEN with a namespace
Is it possible to create an XMLTYPE using the DBMS_XMLGEN function set that contains a namespace. As far as I can see only the 'setrowsettag' function allows any control over what goes into the root element - should I be including, for example, an attribute called 'xmlns' with a value?
The reason I ask all this is I'm trying to validate xml created from a select statement against a registered xsd.
The xsd I've registered:
<?xml version="1.0" encoding="WINDOWS-1252"?>
<xs:schema targetNamespace="http://www.sepa.org/2007/XMLSchemas/Site" xmlns:sit="http://www.sepa.org/2007/XMLSchemas/Site" elementFormDefault="qualified" attributeFormDefault="unqualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sepa.org/2007/XMLSchemas/Site Site.xsd" xmlns:oraxdb="http://xmlns.oracle.com/xdb" oraxdb:flags="311" oraxdb:schemaURL="http://www.sepa.org/2007/XMLSchemas/Site.xsd" oraxdb:schemaOwner="XMLDBMASTER" oraxdb:numProps="14">
<xs:element name="site" oraxdb:propNumber="5953" oraxdb:global="true" oraxdb:SQLName="site" oraxdb:SQLType="site1681_T" oraxdb:SQLSchema="XMLDBMASTER" oraxdb:memType="258" oraxdb:defaultTable="site1683_TAB" oraxdb:defaultTableSchema="XMLDBMASTER">
<xs:annotation>
<xs:documentation>Comment describing your root element</xs:documentation>
</xs:annotation>
<xs:complexType oraxdb:SQLType="site1681_T" oraxdb:SQLSchema="XMLDBMASTER">
<xs:sequence>
<xs:element name="SiteIDType" type="xs:ID" oraxdb:propNumber="5940" oraxdb:global="false" oraxdb:SQLName="SiteIDType" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:SQLInline="true" oraxdb:MemInline="true" oraxdb:JavaInline="true"/>
<xs:element name="SiteNameType" type="xs:string" minOccurs="1" oraxdb:propNumber="5941" oraxdb:global="false" oraxdb:SQLName="SiteNameType" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:SQLInline="true" oraxdb:MemInline="true" oraxdb:JavaInline="true"/>
<xs:element name="SiteAddressStructure" oraxdb:propNumber="5947" oraxdb:global="false" oraxdb:SQLName="SiteAddressStructure" oraxdb:SQLType="SiteAddressStructure1682_T" oraxdb:SQLSchema="XMLDBMASTER" oraxdb:memType="258" oraxdb:SQLInline="true" oraxdb:MemInline="false" oraxdb:JavaInline="false">
<xs:complexType oraxdb:SQLType="SiteAddressStructure1682_T" oraxdb:SQLSchema="XMLDBMASTER">
<xs:sequence>
<xs:element name="AddressLine1" type="xs:string" minOccurs="1" oraxdb:propNumber="5942" oraxdb:global="false" oraxdb:SQLName="AddressLine1" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:SQLInline="true" oraxdb:MemInline="true" oraxdb:JavaInline="true"/>
<xs:element name="AddressLine2" type="xs:string" minOccurs="0" oraxdb:propNumber="5943" oraxdb:global="false" oraxdb:SQLName="AddressLine2" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:SQLInline="true" oraxdb:MemInline="true" oraxdb:JavaInline="true"/>
<xs:element name="AddressLine3" type="xs:string" minOccurs="0" oraxdb:propNumber="5944" oraxdb:global="false" oraxdb:SQLName="AddressLine3" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:SQLInline="true" oraxdb:MemInline="true" oraxdb:JavaInline="true"/>
<xs:element name="AddressLine4" type="xs:string" minOccurs="1" oraxdb:propNumber="5945" oraxdb:global="false" oraxdb:SQLName="AddressLine4" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:SQLInline="true" oraxdb:MemInline="true" oraxdb:JavaInline="true"/>
<xs:element name="PostCode" type="xs:string" minOccurs="0" oraxdb:propNumber="5946" oraxdb:global="false" oraxdb:SQLName="PostCode" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:SQLInline="true" oraxdb:MemInline="true" oraxdb:JavaInline="true"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="SiteTelephoneNoType" type="xs:string" minOccurs="0" oraxdb:propNumber="5948" oraxdb:global="false" oraxdb:SQLName="SiteTelephoneNoType" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:SQLInline="true" oraxdb:MemInline="true" oraxdb:JavaInline="true"/>
<xs:element name="SiteMobilePlantType" type="xs:string" minOccurs="0" oraxdb:propNumber="5949" oraxdb:global="false" oraxdb:SQLName="SiteMobilePlantType" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:SQLInline="true" oraxdb:MemInline="true" oraxdb:JavaInline="true"/>
<xs:element name="SiteFaxNoType" type="xs:string" minOccurs="0" oraxdb:propNumber="5950" oraxdb:global="false" oraxdb:SQLName="SiteFaxNoType" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:SQLInline="true" oraxdb:MemInline="true" oraxdb:JavaInline="true"/>
<!--***Location code must reference the code in the Location Dataset***-->
<xs:element name="SiteLocationCode" type="xs:string" minOccurs="1" oraxdb:propNumber="5951" oraxdb:global="false" oraxdb:SQLName="SiteLocationCode" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:SQLInline="true" oraxdb:MemInline="true" oraxdb:JavaInline="true"/>
<xs:element name="SitePopulationEquivType" type="xs:positiveInteger" minOccurs="0" oraxdb:propNumber="5952" oraxdb:global="false" oraxdb:SQLName="SitePopulationEquivType" oraxdb:SQLType="NUMBER" oraxdb:memType="2" oraxdb:SQLInline="true" oraxdb:MemInline="true" oraxdb:JavaInline="true"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The method for generating the XML:
DECLARE
v_ctx DBMS_XMLGEN.ctxhandle;
v_xml XMLTYPE;
BEGIN
v_ctx:=DBMS_XMLGEN.newcontext
SELECT e.site_id "SiteIDType", e.site_name "SiteNameType", sit_address(e.addr_line1, e.addr_line2,
e.addr_line3, e.addr_line4, e.post_code) AS "SiteAddressStructure", e.tel_no "SiteTelephoneNoType"
, e.mobile_plant "SiteMobilePlantType",
e.fax_no "SiteFaxNoType", e.ge1_location_code "SiteLocationCodeType" ,e.population_equivalent "SitePopulationEquivType"
FROM EL03_SITES e
WHERE e.site_id = 15'
DBMS_XMLGEN.setrowsettag (v_ctx, 'site');
DBMS_XMLGEN.setrowtag (v_ctx, NULL);
v_xml := DBMS_XMLGEN.getxmltype (v_ctx);
INSERT INTO js_xml_test
(ID, xml_data
VALUES ('site test', v_xml
COMMIT;
DBMS_XMLGEN.closecontext (v_ctx);
END;
The resulting XML:
<site>
<SiteIDType>15</SiteIDType>
<SiteNameType>Finlas Water Treatment Works</SiteNameType>
<SiteAddressStructure>
<AddressLine1>Finlas Water Treatment Works</AddressLine1>
<AddressLine2>Shermor Farm</AddressLine2>
<AddressLine3>Luss</AddressLine3>
<AddressLine4>Alexandria</AddressLine4>
<PostCode>G83 8RH</PostCode>
</SiteAddressStructure>
<SiteTelephoneNoType>01389 850224</SiteTelephoneNoType>
<SiteMobilePlantType>N</SiteMobilePlantType>
<SiteLocationCodeType>123428</SiteLocationCodeType>
</site>
When I try to validate it, I get:
ORA-30937: No schema definition for 'site' (namespace '') in parent '/'
ORA-06512: at "SYS.XMLTYPE", line 345
ORA-06512: at line 30
How do I get a namespace declaration in the XML? Any suggestions gratefully received.Did you change any of the text in the lob write statements ?
I believe you get this error if you increase the number of characters without increasing the 1st argument which looks as though it represents the number of characters
Maybe you are looking for
-
ORA-06562: type of out argument must match type of column or bind variab
Hi everybody I have this -6562 oracle error when running a procedure where ther's the dbms_sql package here is the code : PROCEDURE PROC_CREATE_CAT_FILES ( v_period in varchar2, v_cat_files_dir in varchar2 as v_detail varchar2(2000); cursor_name INTE
-
Windows XP mode with Virtual PC will not install / two problems
Hello! I posted this on the Microsoft Windows Answers forums and a moderator there suggested I post it here instead. I also searched here for similiar problems but did not find anyone having the exact same problem as I am having. Also for some rea
-
Unity Connection version clarification
Hi, We installed UC 7.0 last January 2009 and this weekend we updated to the October 2009 release of 7.0.2(a)SU2 Where can I find a doc that describes the version numbering between the OS and the Application? Before the upgrade my Inactive Version
-
I plan to purchase a new computer. How do I transfer my subscription to a new device?
I plan to purchase a new computer. How do I transfer my subscription to a new device?
-
How to download edraw mind map for mac?
I can not download edraw mind map for mac...