DBMS_XMLQUERY
I have downloaded the tar xdk_plsql_9_0_1_0_0.tar file and installed
the XDK onto my 8.1.7.2 database on a sun sparc server.
My problem is this , for the user scott the following statement works fine in that it produces the xml output :
select dbms_xmlquery.getxml('select * from emp', 2) from dual;
However when I try to use the same package above as another user trying to generate xml on one of its tables , I get the following error:
ORA-06502: PL/SQL: numeric or value error: character to number conversion error
Both user scott and my "test user" have identical privileges, which includes the
JAVASYSPRIV and the JAVAUSERPRIV.
My question is this what do I have to do in order for another user to be able to use the
dbms_xmlquery without getting any problems?
RTFM.
Function DBMS_XMLQUERY.GETXML takes 2 number parameters and returns a CLOB.
If you do a describe on DBMS_XMLQUERY you will find :
FUNCTION GETXML RETURNS CLOB
Argument Name Type In/Out Default?
CTX NUMBER IN
METATYPE NUMBER IN DEFAULT
You have to call DBMS_XMLQUERY.NEWCONTEXT and pass it the SQL statement. This function returns a CONTEXT ( number ) which you use in DBMS_XMLQUERY.GETXML.
Similar Messages
-
Error while executing DBMS_XMLQUERY
I'm using a Function to generate a XML file for the given query.
When the functions calls DBMS_XMLQUERY to access a method named : setXSLT ,where it further calls to p_setXSLT .The error comes in p_setXSLT
The error is:
ORA-29532: Java call terminated by uncaught Java exception: java.lang.NoSuchMethodError
The code in the p_setXSLT is:
PROCEDURE setXSLT(ctxHdl IN ctxType, stylesheet IN CLOB, ref IN VARCHAR2 := null) IS
begin
p_setXSLT(ctxHdl, stylesheet, ref);
end setXSLT;
Some1 help on this plz///
Regds,
Jignesh SDear I am also facing the same problem. Did you get any solution for that...
My problem is like this, i created a java stored procedure which returns XML Output. The java class standalone is working fine.
Thanks in advance.
Ravi kumar varma.N -
I need to pass a query in form of string to DBMS_XMLQUERY.GETXML package...the parameters to the query are date and varchar ..please help me build the string .Below is the query and the out put. ( the string is building fine except the parameters are with out quotes)
here is the procedure
create or replace
procedure temp(
P_MTR_ID VARCHAR2,
P_FROM_DATE IN DATE ,
P_THROUGH_DATE IN DATE ) AS
L_XML CLOB;
l_query VARCHAR2(2000);
BEGIN
l_query:= 'SELECT
a.s_datetime DATETIME,
a.downdate Ending_date,
a.downtime Ending_time,
TO_CHAR(ROUND(a.downusage,3),''9999999.000'') kWh_Usage,
TO_CHAR(ROUND(a.downcost,2),''$9,999,999.00'') kWh_cost,
TO_CHAR(ROUND(B.DOWNUSAGE,3),''9999999.000'') KVARH
FROM
(SELECT s_datetime + .000011574 s_datetime,
TO_CHAR(S_DATETIME ,''mm/dd/yyyy'') DOWNDATE,
DECODE(TO_CHAR(s_datetime+.000011574 ,''hh24:'
||'mi''), ''00:'
||'00'',''24:'
||'00'', TO_CHAR(s_datetime+.000011574,''hh24:'
||'mi'')) downtime,
s_usage downusage,
s_cost downcost
FROM summary_qtrhour
WHERE s_mtrid = '
||P_MTR_ID||
' AND s_mtrch = ''1''
AND s_datetime BETWEEN TO_DATE('
||P_FROM_DATE||
',''DD-MON-YY'') AND (TO_DATE('
||P_THROUGH_DATE||
',''DD-MON-YY'') + 1)
) a,
(SELECT s_datetime + .000011574 s_datetime,
s_usage downusage
FROM summary_qtrhour
WHERE s_mtrid = '
||P_MTR_ID||
' AND s_mtrch = ''2''
AND s_datetime BETWEEN TO_DATE('
||P_FROM_DATE||
',''DD-MON-YY'') AND (TO_DATE('
||P_THROUGH_DATE||
','' DD-MON-YY'') + 1)
) B
where a.S_DATETIME = B.S_DATETIME(+)';
SELECT DBMS_XMLQUERY.GETXML('L_QUERY') INTO L_XML FROM DUAL;
INSERT INTO NK VALUES (L_XML);
DBMS_OUTPUT.PUT_LINE('L_QUERY IS :'||L_QUERY);
END;
OUTPUT parameters are in bold (the issue is they are coming without single quotes otherwise th equery is fine
L_QUERY IS :SELECT
a.s_datetime DATETIME,
a.downdate Ending_date,
a.downtime Ending_time,
TO_CHAR(ROUND(a.downusage,3),'9999999.000') kWh_Usage,
TO_CHAR(ROUND(a.downcost,2),'$9,999,999.00') kWh_cost,
TO_CHAR(ROUND(B.DOWNUSAGE,3),'9999999.000') KVARH
FROM
(SELECT s_datetime + .000011574 s_datetime,
TO_CHAR(S_DATETIME ,'mm/dd/yyyy') DOWNDATE,
DECODE(TO_CHAR(s_datetime+.000011574 ,'hh24:mi'), '00:00','24:00', TO_CHAR(s_datetime+.000011574,'hh24:mi')) downtime,
s_usage downusage,
s_cost downcost
FROM summary_qtrhour
WHERE s_mtrid = N3165 AND s_mtrch = '1'
AND s_datetime BETWEEN TO_DATE(01-JAN-13,'DD-MON-YY') AND (TO_DATE(31-JAN-13,'DD-MON-YY') + 1)
) a,
(SELECT s_datetime + .000011574 s_datetime,
s_usage downusage
FROM summary_qtrhour
WHERE s_mtrid = N3165 AND s_mtrch = '2'
AND s_datetime BETWEEN TO_DATE(01-JAN-13,'DD-MON-YY') AND (TO_DATE(31-JAN-13,' DD-MON-YY') + 1)
) B
where a.S_DATETIME = B.S_DATETIME(+)The correct way to handle this is to use bind variables.
And use DBMS_XMLGEN instead of DBMS_XMLQUERY :
create or replace procedure temp (
p_mtr_id in varchar2
, p_from_date in date
, p_through_date in date
is
l_xml CLOB;
l_query VARCHAR2(2000);
l_ctx dbms_xmlgen.ctxHandle;
begin
l_query:= 'SELECT
a.s_datetime DATETIME,
a.downdate Ending_date,
a.downtime Ending_time,
TO_CHAR(ROUND(a.downusage,3),''9999999.000'') kWh_Usage,
TO_CHAR(ROUND(a.downcost,2),''$9,999,999.00'') kWh_cost,
TO_CHAR(ROUND(B.DOWNUSAGE,3),''9999999.000'') KVARH
FROM
(SELECT s_datetime + .000011574 s_datetime,
TO_CHAR(S_DATETIME ,''mm/dd/yyyy'') DOWNDATE,
DECODE(TO_CHAR(s_datetime+.000011574 ,''hh24:'
||'mi''), ''00:'
||'00'',''24:'
||'00'', TO_CHAR(s_datetime+.000011574,''hh24:'
||'mi'')) downtime,
s_usage downusage,
s_cost downcost
FROM summary_qtrhour
WHERE s_mtrid = :P_MTR_ID
AND s_mtrch = ''1''
AND s_datetime BETWEEN TO_DATE(:P_FROM_DATE,''DD-MON-YY'')
AND (TO_DATE(:P_THROUGH_DATE,''DD-MON-YY'') + 1)
) a,
(SELECT s_datetime + .000011574 s_datetime,
s_usage downusage
FROM summary_qtrhour
WHERE s_mtrid = :P_MTR_ID
AND s_mtrch = ''2''
AND s_datetime BETWEEN TO_DATE(:P_FROM_DATE,''DD-MON-YY'')
AND (TO_DATE(:P_THROUGH_DATE,'' DD-MON-YY'') + 1)
) B
where a.S_DATETIME = B.S_DATETIME(+)';
l_ctx := dbms_xmlgen.newContext(l_query);
dbms_xmlgen.setBindValue(l_ctx, 'P_MTR_ID', p_mtr_id);
dbms_xmlgen.setBindValue(l_ctx, 'P_FROM_DATE', to_char(p_from_date, 'DD-MON-YY'));
dbms_xmlgen.setBindValue(l_ctx, 'P_THROUGH_DATE', to_char(p_through_date, 'DD-MON-YY'));
l_xml := dbms_xmlgen.getXML(l_ctx);
dbms_xmlgen.closeContext(l_ctx);
insert into nk values (l_xml);
end; -
DBMS_XMLQuery and DBMS_XMLSave package
I have Oracle 8.1.7
Where can I get DBMS_XMLQuery and DBMS_XMLSave package using samples
The Documentation I have doesn't contain any.I did what you asked, but still get the following error when running my statement to create xml from a sql statement.
SQL> @xml01
declare
ERROR at line 1:
ORA-29541: class SYS.oracle/xml/sql/query/OracleXMLStaticQuery could not be
resolved
ORA-06512: at "SYS.DBMS_XMLQUERY", line 46
ORA-06512: at line 7
Below is copy of the contents of catxsu.sql script.
call sys.dbms_java.loadjava ('-v -r -s -grant PUBLIC rdbms/jlib/xsu12.jar');
@@dbmsxsu.sql
@@xmlgen.sql
create public synonym dbms_xmlsave for dbms_xmlsave;
create public synonym dbms_xmlquery for dbms_xmlquery;
create public synonym xmlgen for xmlgen;
Below is output from catxsu.sql run this time.
SQL> @catxsu
Call completed.
Package created.
No errors.
Package body created.
No errors.
Grant succeeded.
Package created.
No errors.
Package body created.
No errors.
Grant succeeded.
Package created.
No errors.
Package body created.
No errors.
Grant succeeded.
create public synonym dbms_xmlsave for dbms_xmlsave
ERROR at line 1:
ORA-00955: name is already used by an existing object
create public synonym dbms_xmlquery for dbms_xmlquery
ERROR at line 1:
ORA-00955: name is already used by an existing object
create public synonym xmlgen for xmlgen
ERROR at line 1:
ORA-00955: name is already used by an existing object
SQL> exit
I appreciate your help. Any more ideas? This is working for me on another server and database, but not sure what the difference is with this one.
Thanks,
Tim Gerringer -
Error using DBMS_XMLQuery() with XMLElement().
Select dbms_xmlquery.getXML('Select SYS_XMLAGG(
2 XMLElement("SDI",
3 active_flag)) ' ||
4 'from Sdi s where s.sdi_num = 22261')
5* From Dual
SQL> /
DBMS_XMLQUERY.GETXML('SELECTSYS_XMLAGG(XMLELEMENT("SDI",ACTIVE_FLAG))'||'FROMSDI
<?xml version = '1.0'?>
<ERROR>oracle.xml.sql.OracleXMLSQLException: Character
')' is not allowed in an XML tag name.</ERROR>
SQL>please help.
This is urgent
No offence meant
~
~
~
~
~
Select dbms_xmlquery.getXML('Select SYS_XMLAGG(
XMLElement("SDI",
active_flag) ) ' ||
'from Sdi s where s.sdi_num = 22261')
From Dual
~
~
~
~
~
~
~
~
~
~
~
~
~
Select dbms_xmlquery.getXML('Select SYS_XMLAGG(
XMLElement("SDI",
active_flag) ) ppp ' ||
'from Sdi s where s.sdi_num = 22261')
From Dual
~
~
~
~
~
~
~
~
~
~
~
~
~
Select dbms_xmlquery.getXML('Select SYS_XMLAGG(
XMLElement("SDI",
active_flag) ) ' ||
'from Sdi s where s.sdi_num = 22261')
From Dual
~
~
~
~
Select dbms_xmlquery.getXML('Select SYS_XMLAGG(
XMLElement('||"S^?,
active_flag) ) ' ||
'from Sdi s where s.sdi_num = 22261')
From Dual
~
~
~
Select dbms_xmlquery.getXML('Select SYS_XMLAGG(
XMLElement("SDI",
active_flag) ) ' ||
'from Sdi s where s.sdi_num = 22261')
From Dual
~
~
~
~
~
~
~
~
~
~
~
~
~
Select dbms_xmlquery.getXML('Select SYS_XMLAGG(
XMLElement("SDI",
active_flag) ) ' ||
'from Sdi s where s.sdi_num = 22261')
From Dual
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
Select DBMS_XMLQuery.getXML('Select ' ||
'SYS_XMLAGG(XMLElement(NULL,active_flag)) ' ||
'FROM SDI S where S.sdi_num = 22261 ')
FROM DUAL
~
~
~
~
~
~
~
~
~
~
~
~
~
~
Select DBMS_XMLQuery.getXML('Select ' ||
'SYS_XMLAGG(XMLElement(S,active_flag)) ' ||
'FROM SDI S where S.sdi_num = 22261 ')
FROM DUAL
~
~
~
~
~
~
~
~
~
~
~
~
~
Select DBMS_XMLQuery.getXML('Select ' ||
'SYS_XMLAGG(XMLElement(S, active_flag)) ' ||
'FROM SDI S where S.sdi_num = 22261 ')
FROM DUAL
~
~
~
~
~
~
~
~
~
~
~
~
~
Select DBMS_XMLQuery.getXML('Select ' ||
'SYS_XMLAGG(XMLElement("S", active_flag)) ' ||
'FROM SDI S where S.sdi_num = 22261 ')
FROM DUAL
~
~
~
~
~
~
~
~
~
~
~
~
~
Select DBMS_XMLQuery.getXML('Select ' ||
'SYS_XMLAGG(XMLElement("S", active_flag)) ' ||
'FROM SDI S where S.sdi_num = 22261 ')
FROM DUAL
~
~
~
Select DBMS_XMLQuery.getXML('Select ' ||
'SYS_XMLAGG(XMLElement("S", active_flag)) ' ||
'FROM SDI S where S.sdi_num = 22261 ')
FROM DUAL
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
:q
1 Select DBMS_XMLQuery.getXML('Select ' ||
2 'SYS_XMLAGG(XMLElement("SDI", active_flag)) ' ||
3 'FROM SDI S where S.sdi_num = 22261 ')
4* FROM DUAL
SQL> /
DBMS_XMLQUERY.GETXML('SELECT'||'SYS_XMLAGG(XMLELEMENT("S",ACTIVE_FLAG))'||'FROMS
<?xml version = '1.0'?>
<ERROR>oracle.xml.sql.OracleXMLSQLException: Character
')' is not allowed in an XML tag name.</ERROR>
SQL>
same error
AM I OVERLOOKING SOMETHING? DOES DBMS_XMLQUERY() NOT SUPPORT
XMLFOREST()? -
Method "SYS.DBMS_XMLQUERY.getXML()" seems to always want to prefix "<?xml version = '1.0'?>" to the returned output.
I don't think this is always called for.
I want to extract data from the database as an XML fragment. Outside of the RDBMS, I would then combine multiple fragments together into a larger XML document. If each fragment is prefixed with "<?xml version = '1.0'?>", I have to add logic to strip out this offending line.
I tried method setXslt(). Even when my XSL stylesheet transforms the XML into HTML or TEXT, the output gets prefixed with "<?xml version = '1.0'?>", which I feel is wrong.
Question: Is there any way to instruct DBMS_XMLQUERY to omit "<?xml version = '1.0'?>" ?
Thanks!
LouisHi,
Use DBMS_XMLGEN.getXMLType to retrieve the XML data into an XMLType variable.
Then, with getClobVal method, you can convert it to CLOB :
SQL> DECLARE
2 v_xml XMLType;
3 v_lob CLOB;
4 BEGIN
5 v_xml := dbms_xmlgen.getXMLType('select * from scott.emp where rownum = 1');
6 v_lob := v_xml.getClobVal();
7
8 dbms_output.put_line(v_lob);
9 END;
10 /
<ROWSET>
<ROW>
<EMPNO>7369</EMPNO>
<ENAME>SMITH</ENAME>
<JOB>CLERK</JOB>
<MGR>7902</MGR>
<HIREDATE>17/12/80</HIREDATE>
<SAL>800</SAL>
<DEPTNO>20</DEPTNO>
</ROW>
</ROWSET>
PL/SQL procedure successfully completed -
XML Generation Using DBMS_XMLQuery
Hi,
I am generating XML using "DBMS_XMLQuery".
Requirement: To generate blank xml tag(Without data).
e.g : Table XXX has A,B,C,D columns.
I am using SQL : SELECT a AA,b BB,c CC,d DD FROM XXX;
<AA>1 </AA>
<BB>2 </BB>
<CC>3 </CC>
(Note : Columns A,B and C has Values but "d" column does not have value).
Since "D" column doesnot have value,it is not generating XML tag.
So ,How to generate XML tag(e.g <DD> </DD>) without Value?
Any idea,how to achieve the above?
Thanks in advance.
Rgds,
Manoj
==========================
<?xml version = '1.0'?>
<ORDERS>
<ORDER num="1">
<MESSAGE_ID>1</MESSAGE_ID>
<SOURCE_SYSTEM>Oracle</SOURCE_SYSTEM>
<OPERATION>OrderRMA</OPERATION>
<DATETIME>3/21/2006 15:30:44</DATETIME>
<VERSION>1</VERSION>
<COUNTRY>AUS</COUNTRY>
<LANGUAGE>ENG</LANGUAGE>
<DESTINATION_SYSTEM>Manhattan</DESTINATION_SYSTEM>
<DESTINATION_WAREHOUSE>AUSVIS</DESTINATION_WAREHOUSE>
<ORDER_HEADER>
<ORDER_HEADER_ROW num="1">
----You can set the null attribute to true , so that the tag appears in your XML
see the statement in Bold.
DECLARE
queryCtx dbms_xmlquery.ctxType;
result CLOB;
BEGIN
-- set up the query context
queryCtx := dbms_xmlquery.newContext(
'SELECT empno "EMP_NO"
, ename "NAME"
, deptno "DEPT_NO"
, comm "COMM"
FROM scott.emp
WHERE deptno = :DEPTNO'
dbms_xmlquery.setRowTag(
queryCtx
, 'EMP'
dbms_xmlquery.setRowSetTag(
queryCtx
, 'EMPSET'
DBMS_XMLQUERY.useNullAttributeIndicator(queryCtx,true);
dbms_xmlquery.setBindValue(
queryCtx
, 'DEPTNO'
, 30
result := dbms_xmlquery.getXml(queryCtx);
insert into clobtable values(result);commit;
dbms_xmlquery.closeContext(queryCtx);
END;
select * from clobtable
<?xml version = '1.0'?>
<EMPSET>
<EMP num="1">
<EMP_NO>7499</EMP_NO>
<NAME>ALLEN</NAME>
<DEPT_NO>30</DEPT_NO>
<COMM>300</COMM>
</EMP>
<EMP num="2">
<EMP_NO>7521</EMP_NO>
<NAME>WARD</NAME>
<DEPT_NO>30</DEPT_NO>
<COMM>500</COMM>
</EMP>
<EMP num="3">
<EMP_NO>7654</EMP_NO>
<NAME>MARTIN</NAME>
<DEPT_NO>30</DEPT_NO>
<COMM>1400</COMM>
</EMP>
<EMP num="4">
<EMP_NO>7698</EMP_NO>
<NAME>BLAKE</NAME>
<DEPT_NO>30</DEPT_NO>
<COMM NULL="YES"/>
</EMP>
<EMP num="5">
<EMP_NO>7844</EMP_NO>
<NAME>TURNER</NAME>
<DEPT_NO>30</DEPT_NO>
<COMM>0</COMM>
</EMP>
<EMP num="6">
<EMP_NO>7900</EMP_NO>
<NAME>JAMES</NAME>
<DEPT_NO>30</DEPT_NO>
<COMM NULL="YES"/>
</EMP>
</EMPSET>
http://sqltech.cl/doc/oracle9i/appdev.901/a89852/d_xmlque.htm -
How to create Nested (Multi level ) tag in XML using DBMS_XMLQUERY function
Hi,
I need Following out put in CLOB Column.
XML format Like :
<?xml version="1.0" encoding="UTF-8"?>
<ReceiptHeader>
<Id>1234556</Id>
<Type>DD</Type>
<Receipts>
<ReceiptDEO>
<StoreId>11380001</StoreId>
<EmployeeId>NOLO980</EmployeeId>
<LineItems>
<ReceiptLineItem>
<CartonId>ABC12345</CartonId>
<ShippedQty>1.0000</ShippedQty>
<UnitCost>118.500000</UnitCost>
</ReceiptLineItem>
</LineItems>
<ReceiptDate>Wed Jun 20 11:50:01 CEST 2012</ReceiptDate>
<ReceiptNumber>3127855</ReceiptNumber>
</ReceiptDEO>
</Receipts>
</ReceiptHeader>
And i'm using dbms_xmlquery.newcontext ( );
Can you please help to get above output.
- Thanks,
PallaviHi ,
Thanks for reply .
Version is "Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production".
First I tried with DBMS_XMLGEN ,, it doesnt work properly.
Then tried with XMLAGG and XMLELEMENT but giving me output in 1 row. I need proper XML format.
Following is some data, For which I had created view of 2 tables.
ID STORE_ID EMPLOYEE_ID ACTUAL_ARRIVAL_DATE CARTON_ID SHIPMENT_ID QUANTITY_RECEIVED UNIT_COST RECEIPT_DOC_ID RECEIPT_Date
3772 12340001 PALS001 16-Feb-11 2A632 29 28.000 118.50000 1234 16-Feb-11
3775 12340001 PALS001 16-Feb-11 1A633 30 120.000 218.50000 7866 16-Feb-11
3776 12340001 PALS001 16-Feb-11 2A634 30 75.000 345.75000 7876 16-Feb-11
3773 12340001 PALS001 16-Feb-11 3A632 30 45.000 200.10000 7869 16-Feb-11
3774 12340001 PALS001 16-Feb-11 3A632 30 10.000 450.45000 7869 16-Feb-11
Please suggest better way..
-Thanks,
Pallavi -
DBMS_XMLQuery behavior when using stored function within cursor select
Consider the following SQL Statement
select t1.id
, t1.name
, cursor ( select t2.id
from tab t2
where t2.t1_id
= t1.id
and validate(t2.xyz,:bd1)
= 1
from tab t1
where t1.id = :bd2
DBMS_XMLQuery is used to create a context and to bind the appropriate values. In this case 'validate' is a stored function. I get the following error message upon execution:
ORA-29532: Java call terminated by uncaught Java exception:
java.sql.SQLException: Missing IN or OUT parameter at index:: 1
Issuing a similar statement in SQL*Plus works fine. I was wondering whether this is a known issue when using a stored function in the cursor select statement in the context of DBMS_XMLQuery or whether I'm doing something wrong.Hi Jan,
This problem has been identified and fixed. The fix should be available in the next release. Thank you for bringing this up to our attention.
visar -
Generating XML in Parallel Mode-DBMS_XMLGEN/ DBMS_XMLQUERY / SQLX?
Is it possible to generate XML in parallel mode for big result sets using DBMS_XMLGEN or DBMS_XMLQUERY or SQLX?
ThanksSQL/XML may work. WHat does the showplan output show
-
"Missing IN or OUT parameter at index:: 1" - dbms_xmlquery vs dbms_xmlgen
It looks like DBMS_XMLQuery doesn't like bind variables among selected columns.
While DBMS_XMLGEN handles them without any problems.
A simple example:
-- xml query - fails
declare
ctx dbms_xmlquery.ctxHandle;
begin
ctx := dbms_xmlquery.newContext(
'select a.*, :r_max the_end from scott.emp a where rownum <= :r_max');
dbms_xmlquery.setBindValue(ctx, 'r_max', 10);
dbms_output.put_line(dbms_xmlquery.getxml(ctx));
dbms_xmlquery.closeContext(ctx);
end;
The error is <ERROR>oracle.xml.sql.OracleXMLSQLException: Missing IN or OUT parameter at index:: 1</ERROR>
-- xml gen - works
declare
ctx dbms_xmlgen.ctxHandle;
begin
ctx := dbms_xmlgen.newContext(
'select a.*, :r_max the_end from scott.emp a where rownum <= :r_max');
dbms_xmlgen.setBindValue(ctx, 'r_max', 10);
dbms_output.put_line(dbms_xmlgen.getxml(ctx));
dbms_xmlgen.closeContext(ctx);
end;
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - ProdLooks like you need two binds to accomplish your task:
SQL> declare
2 ctx dbms_xmlquery.ctxhandle;
3 begin
4 ctx := dbms_xmlquery.newcontext('select emp.*, :r_max1 the_end from emp where rownum <= :r_max2');
5 dbms_xmlquery.setbindvalue (ctx, 'r_max1', 4);
6 dbms_xmlquery.setbindvalue (ctx, 'r_max2', 4);
7 dbms_output.put_line (dbms_xmlquery.getxml (ctx));
8 dbms_xmlquery.clearbindvalues (ctx);
9 dbms_xmlquery.closecontext (ctx);
10 end;
11 /
PL/SQL procedure successfully completed.
SQL> set serverout on
SQL> /
<?xml version = '1.0'?>
<ROWSET>
<ROW num="1">
<EMPNO>7369</EMPNO>
<ENAME>SMITH</ENAME>
<JOB>CLERK</JOB>
<MGR>7902</MGR>
<HIREDATE>12/17/1980 0:0:0</HIREDATE>
<SAL>800</SAL>
<DEPTNO>20</DEPTNO>
<THE_END>4</THE_END>
</ROW>
<ROW num="2">
<EMPNO>7499</EMPNO>
<ENAME>ALLEN</ENAME>
<JOB>SALESMAN</JOB>
<MGR>7698</MGR>
<HIREDATE>2/20/1981 0:0:0</HIREDATE>
<SAL>1600</SAL>
<COMM>300</COMM>
<DEPTNO>30</DEPTNO>
<THE_END>4</THE_END>
</ROW>
<ROW num="3">
<EMPNO>7521</EMPNO>
<ENAME>WARD</ENAME>
<JOB>SALESMAN</JOB>
<MGR>7698</MGR>
<HIREDATE>2/22/1981 0:0:0</HIREDATE>
<SAL>1250</SAL>
<COMM>500</COMM>
<DEPTNO>30</DEPTNO>
<THE_END>4</THE_END>
</ROW>
<ROW num="4">
<EMPNO>7566</EMPNO>
<ENAME>JONES</ENAME>
<JOB>MANAGER</JOB>
<MGR>7839</MGR>
<HIREDATE>4/2/1981
0:0:0</HIREDATE>
<SAL>2975</SAL>
<DEPTNO>20</DEPTNO>
<THE_END>4</THE_END>
</ROW>
</ROWSET>
PL/SQL procedure successfully completed. -
Supress of rownum tag in dbms_xmlquery
Hi,
I have created the following scrip which uses dbms_xmlquery utility.
queryctx := dbms_xmlquery.newcontext
('select field1,
cursor(field2,
field3
from temp_table2 t2
where t2.field1 = t1.field1) as Header
from temp_table1 t1
where field1 = :p_field);
dbms_xmlquery.setbindvalue(queryctx,'p_field','12435');
result:=dbms_xmlquery.getxml(queryctx);
Which creates this output file:
<ROWSET>
<ROW num="1">
<Field1>226600</Field1>
<Header>
<Header_ROW num="1">
<Field2>87658</Field2>
<Field3>23456</Field3>
</Header_ROW>
</Header>
</ROW>
</ROWSET>
I need to know how to suppress printing of row tag so that the output file
look like this:
<ROWSET>
<Field1>226600</Field1>
<Header>
<Field2>87658</Field2>
<Field3>23456</Field3>
</Header>
</ROWSETI see. But I have a cursor in my query and that's where it doesn't work. This is my query:
queryctx := dbms_xmlquery.newcontext
('select field1,
cursor(field2,
field3
from temp_table2 t2
where t2.field1 = t1.field1) as Header
from temp_table1 t1
where field1 = :p_field);
dbms_xmlquery.setbindvalue(queryctx,'p_field','12435');
result:=dbms_xmlquery.getxml(queryctx);
I get this result:
<ROWSET>
<Field1>226600</Field1>
<Header>
<Header_ROW num="1">
<Field2>87658</Field2>
<Field3>23456</Field3>
</Header_ROW>
</Header>
</ROWSET>
And I need to get rid of <Header_ROW num="1"> and </Header_ROW> tags. I don't need those tags for any records at all. -
Dbms_xmlquery.getxml problem
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM --------- ---------- --------- ---------- --------- ---------- ---------- ---------- --------- ------------
7369 SMITH CLERK 7902 17-DEC-80 800 20
14 rows selected.
SQL> select dbms_xmlquery.getxml('select * from emp where rownum<2') from dual;
DBMS_XMLQUERY.GETXML('SELECT*FROMEMPWHEREROWNUM<2')
<?xml version = '1.0'?>
<ROWSET>
<ROW num="1">
<EMPNO>7369</EMPNO>
I'm just wondering why the query output XML has EMPNO alone, and not the other column data.Please help.
Thanks,
BhagatIt's because of the parameter settings in SQL*Plus. It's just not showing the whole output for you...
SQL> select dbms_xmlquery.getxml('select * from emp where rownum<2') from dual;
DBMS_XMLQUERY.GETXML('SELECT*FROMEMPWHEREROWNUM<2')
<?xml version = '1.0'?>
<ROWSET>
<ROW num="1">
<EMPNO>7369</EMPNO>
SQL> set long 2000
SQL> select dbms_xmlquery.getxml('select * from emp where rownum<2') from dual;
DBMS_XMLQUERY.GETXML('SELECT*FROMEMPWHEREROWNUM<2')
<?xml version = '1.0'?>
<ROWSET>
<ROW num="1">
<EMPNO>7369</EMPNO>
<ENAME>SMITH</ENAME>
<JOB>CLERK</JOB>
<MGR>7902</MGR>
<HIREDATE>12/17/1980 0:0:0</HIREDATE>
<SAL>800</SAL>
<DEPTNO>20</DEPTNO>
</ROW>
</ROWSET>
SQL> -
Storing Chinese data as clob using dbms_xmlquery
Hi,
I am writing a procedure that creates a query and same is stored as CLOB in a database table. Below is a sample test program for same. I am using UTF-8 to accomodate Chinese data. The CLOB however doesn't contain valid chinese data. Please guide me on what needs to be done....
declare
l_ctx dbms_xmlquery.ctxtype;
l_xml_schema NCLOB;
begin
l_ctx := dbms_xmlquery.newcontext('SELECT * FROM (SELECT "SEC","coretypeid","coreid","Record Type","您ID" FROM (SELECT "您MultiCurrency Object".coreid "SEC","您MultiCurrency Object".coretypeid "coretypeid", "您MultiCurrency Object".coreid "coreid", "您MultiCurrency Object".CoreTypeAssocAliasDescr "Record Type", "您MultiCurrency Object".F_3441961635 "您ID"
FROM ( SELECT SUBSTR(RFN_FlexSQL_Cache.GetCTAliasDescr(CORETYPEID,3441940070,3443315783),0,50) CoreTypeAliasDescr,
SUBSTR(RFN_FlexSQL_Cache.GetCTAssocAliasDescr(CORETYPEID,3441940070,3443315783),0,50) CoreTypeAssocAliasDescr,
SUBSTR(RFN_FlexSQL_Cache.GetCTDescr(CORETYPEID,3441940070,3443315783),0,50) COREDESCRIPTION,
COREID, CORETYPEID ,F_3441961635 FROM CT_3420185025
WHERE coretypeid IN (3420185025)) "您MultiCurrency Object" )) WHERE 1 = 2');
dbms_xmlquery.setraiseexception(l_ctx, TRUE);
dbms_xmlquery.setsqltoxmlnameescaping(l_ctx, TRUE);
-- dbms_xmlquery.setdateformat(l_ctx, l_xml_sformat);
dbms_xmlquery.setencodingtag(l_ctx, 'ISO-8859-1');
l_xml_schema := dbms_xmlquery.getxml(l_ctx,2);
insert into testingXMLgen values (l_xml_schema);
-- :xml_data := dbms_xmlquery.getxml(l_ctx);
dbms_xmlquery.closecontext(l_ctx);
end;I have tried UTF-8 encoding set as well. It didn't work toodbms_xmlquery.setencodingtag(l_ctx, 'UTF-8');
Corresponding database column is NCLOB
select * from nls_database_parameters;PARAMETER VALUE
NLS_LANGUAGE AMERICAN
NLS_NCHAR_CHARACTERSET AL16UTF16
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
NLS_CHARACTERSET WE8ISO8859P1
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD-MON-RR
NLS_DATE_LANGUAGE AMERICAN
NLS_SORT BINARY
PARAMETER VALUE
NLS_TIME_FORMAT HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY $
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE
NLS_RDBMS_VERSION 10.2.0.5.0
20 rows selected. -
Mixed case parsing using DBMS_XMLquery
I have created a view using mixed case column names. However, when I use DBMS_XMLquery to pass the select "column_name" from table_name, it does not parse and does not work. However it works fine with passing 'select * from table_name'. Any idea how a mixed case column can be passed to dbms_xmlquery? Or any idea how a mixed case column name is passed in dynamic sql queries.
I found the problem. It was not with mixed case column names. Rather it was because of the NULL value returns from the sql query which the java procedure for transforming sql was not able to trap and throwing out exception.
However, still it is quite funny. If I use all the columns in the query or do select * , I get back the generated XML. If I just select a few columns, I get the error message
ORA-29532: Java call terminated by uncaught java exception (java.lang.NullPointerException
ORA-06512: at "SYS.DBMS_XMLQUERY" line 206
Any idea
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Jinyu Wang ([email protected]):
Would you send the test case you are using for reproducing the problem?<HR></BLOCKQUOTE>
null
Maybe you are looking for
-
Airport Extreme (time capsule model) internet speed EXTREMELY slow.
Hello, first thank you for any help on this as it is a bit frustrating for me. I recently noticed my internet speed was running significantly slower on both my MacBook Pro and on my wifes MacBook. I had my ISP come and check out the problem. They hoo
-
Business Catalyst templates not containing content in Muse built site
I am currently upgrading a clients website and have recently got into designing using Muse and thought I would try out the BUsiness Catalyst system to host it all etc. I wanted to use muse for the more static opages and the the blog for case studies
-
How do I update a folder of DNGs to the new 2010 (Current) Raw Process?
Is there an efficient method to update an entire folder of DNG images to the newer RAW process in Camera Raw 6.1 - to "2010 (Current)"? And as an added bonus, it would also be great to simultaneously update the Camera Profile - to "Adobe Standard". I
-
Unexpected behavior when creating Objects in a Vector
I have a situation where Objects in a Vector appear to be getting corrupted. The context is this: I obtain a ResultSet from a database, create a Vector of Strings for each row, and a Vector of these row vectors for the entire ResultSet. This is passe
-
How to use a ps3 controller with labview
Hello, I am trying to implement a ps3 controller in labview but am having trouble. I was wondering if anyone knew how to do this or had any ideas for me. Thanks for the help