Generating xml from oracle table
Hi,
I want to generate xml form an oracle table and using sql developer, oracle express 10g, xdk forler is also unzipped under oracle express folder, still getting following error: code used
var g_clob clob;
declare
l_ctx dbms_xmlquery.ctxHandle;
l_clob clob;
begin
l_ctx := dbms_xmlquery.newContext('select * from scott.emp');
dbms_lob.createtemporary(:g_clob,true,dbms_lob.session);
:g_clob := dbms_xmlquery.getXml(l_ctx);
end;
/ORA-06550: line 2, column 14:
PLS-00201: identifier 'DBMS_XMLQUERY.CTXHANDLE' must be declared
Thanks in advance
Hi,
DBMS_XMLQUERY is a wrapper for methods from the Java class "oracle.xml.sql.query.OracleXMLStaticQuery".
The problem is that Oracle 10g XE doesn't have a JVM, so you can't use this package.
Use DBMS_XMLGEN instead, it provides similar functionalities and is more efficient (C-based) :
SQL> var g_clob clob
SQL> DECLARE
2 l_ctx dbms_xmlgen.ctxHandle;
3 BEGIN
4 l_ctx := dbms_xmlgen.newContext('select * from scott.emp');
5 :g_clob := dbms_xmlgen.getXML(l_ctx);
6 dbms_xmlgen.closeContext(l_ctx);
7 END;
8 /
PL/SQL procedure successfully completed.
SQL> set long 5000
SQL> set pages 1000
SQL> print g_clob
G_CLOB
<?xml version="1.0"?>
<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>
<ROW>
<EMPNO>7499</EMPNO>
<ENAME>ALLEN</ENAME>
<JOB>SALESMAN</JOB>
<MGR>7698</MGR>
<HIREDATE>20/02/81</HIREDATE>
<SAL>1600</SAL>
<COMM>300</COMM>
<DEPTNO>30</DEPTNO>
</ROW>
<ROW>
<EMPNO>7521</EMPNO>
<ENAME>WARD</ENAME>
<JOB>SALESMAN</JOB>
<MGR>7698</MGR>
<HIREDATE>22/02/81</HIREDATE>
<SAL>1250</SAL>
<COMM>500</COMM>
<DEPTNO>30</DEPTNO>
</ROW>
<ROW>
<EMPNO>7566</EMPNO>
<ENAME>JONES</ENAME>
<JOB>MANAGER</JOB>
<MGR>7839</MGR>
<HIREDATE>02/04/81</HIREDATE>
<SAL>2975</SAL>
<DEPTNO>20</DEPTNO>
</ROW>
<ROW>
<EMPNO>7654</EMPNO>
<ENAME>MARTIN</ENAME>
<JOB>SALESMAN</JOB>
<MGR>7698</MGR>
<HIREDATE>28/09/81</HIREDATE>
<SAL>1250</SAL>
<COMM>1400</COMM>
<DEPTNO>30</DEPTNO>
</ROW>
<ROW>
<EMPNO>7698</EMPNO>
<ENAME>BLAKE</ENAME>
<JOB>MANAGER</JOB>
<MGR>7839</MGR>
<HIREDATE>01/05/81</HIREDATE>
<SAL>2850</SAL>
<DEPTNO>30</DEPTNO>
</ROW>
<ROW>
<EMPNO>7782</EMPNO>
<ENAME>CLARK</ENAME>
<JOB>MANAGER</JOB>
<MGR>7839</MGR>
<HIREDATE>09/06/81</HIREDATE>
<SAL>2450</SAL>
<DEPTNO>10</DEPTNO>
</ROW>
<ROW>
<EMPNO>7839</EMPNO>
<ENAME>KING</ENAME>
<JOB>PRESIDENT</JOB>
<HIREDATE>17/11/81</HIREDATE>
<SAL>5000</SAL>
<DEPTNO>10</DEPTNO>
</ROW>
<ROW>
<EMPNO>7844</EMPNO>
<ENAME>TURNER</ENAME>
<JOB>SALESMAN</JOB>
<MGR>7698</MGR>
<HIREDATE>08/09/81</HIREDATE>
<SAL>1500</SAL>
<COMM>0</COMM>
<DEPTNO>30</DEPTNO>
</ROW>
<ROW>
<EMPNO>7900</EMPNO>
<ENAME>JAMES</ENAME>
<JOB>CLERK</JOB>
<MGR>7698</MGR>
<HIREDATE>03/12/81</HIREDATE>
<SAL>950</SAL>
<DEPTNO>30</DEPTNO>
</ROW>
<ROW>
<EMPNO>7902</EMPNO>
<ENAME>FORD</ENAME>
<JOB>ANALYST</JOB>
<MGR>7566</MGR>
<HIREDATE>03/12/81</HIREDATE>
<SAL>3000</SAL>
<DEPTNO>20</DEPTNO>
</ROW>
<ROW>
<EMPNO>7934</EMPNO>
<ENAME>MILLER</ENAME>
<JOB>CLERK</JOB>
<MGR>7782</MGR>
<HIREDATE>23/01/82</HIREDATE>
<SAL>1300</SAL>
<DEPTNO>10</DEPTNO>
</ROW>
</ROWSET>Or, using SQL/XML functions :
SELECT XMLElement("ROWSET",
XMLAgg(
XMLElement("ROW",
XMLForest(empno, ename, job, mgr, hiredate, sal, comm, deptno)
).getClobVal()
FROM scott.emp
;
Similar Messages
-
Generate XML from Oracle Table Data
Hi All,
I am new to this network. I am also new to oracle XML package. I want a help for the below query.
CREATE TABLE EMP(ID NUMBER PRIMARY KEY, NAME VARCHAR2(10), PHONE NUMBER);
INSERT INTO EMP(ID,NAME,PHONE) VALUES (11,'Joy',1234);
INSERT INTO EMP(ID,NAME,PHONE) VALUES (22,'Mike',5678);
INSERT INTO EMP(ID,NAME,PHONE) VALUES (33,'Jason',NULL);
COMMIT;
I want to export the EMP table data in a XML file with the below format.
Required Output:
<?xml version="1.0" encoding="UTF-8"?><STATICDATA><EMP><ID>11</ID><NAME>Joy</NAME></EMP></STATICDATA>
<?xml version="1.0" encoding="UTF-8"?><STATICDATA><EMP><ID>22</ID><NAME>Mike</NAME></EMP></STATICDATA>
<?xml version="1.0" encoding="UTF-8"?><STATICDATA><EMP><ID>33</ID><NAME>Jason</NAME></EMP></STATICDATA>
I have used some XML functions and have written the below query.
select XMLROOT(XMLELEMENT(staticdata,XMLELEMENT(EMP,XMLELEMENT(ID,ID),XMLELEMENT(NAME,NAME))), version '1.0" encoding="UTF-8') xml FROM EMP;
output of my query:
<?xml version="1.0" encoding="UTF-8"?>
<STATICDATA>
<EMP>
<ID>11</ID>
<NAME>Joy</NAME>
</EMP>
</STATICDATA>
<?xml version="1.0" encoding="UTF-8"?>
<STATICDATA>
<EMP>
<ID>22</ID>
<NAME>Mike</NAME>
</EMP>
</STATICDATA>
<?xml version="1.0" encoding="UTF-8"?>
<STATICDATA>
<EMP>
<ID>33</ID>
<NAME>Jason</NAME>
</EMP>
</STATICDATA>
But i want the out as the required output above. every record in a single line. can any one help me in achieving the required output. also can i export all the columns of the table by some thing like select * from the table in XML file ?
Thanks,
Sartajuser13683418 wrote:
Hi All,
I am new to this network. I am also new to oracle XML package. I want a help for the below query.
CREATE TABLE EMP(ID NUMBER PRIMARY KEY, NAME VARCHAR2(10), PHONE NUMBER);
INSERT INTO EMP(ID,NAME,PHONE) VALUES (11,'Joy',1234);
INSERT INTO EMP(ID,NAME,PHONE) VALUES (22,'Mike',5678);
INSERT INTO EMP(ID,NAME,PHONE) VALUES (33,'Jason',NULL);
COMMIT;
I want to export the EMP table data in a XML file with the below format.
Required Output:
<?xml version="1.0" encoding="UTF-8"?><STATICDATA><EMP><ID>11</ID><NAME>Joy</NAME></EMP></STATICDATA>
<?xml version="1.0" encoding="UTF-8"?><STATICDATA><EMP><ID>22</ID><NAME>Mike</NAME></EMP></STATICDATA>
<?xml version="1.0" encoding="UTF-8"?><STATICDATA><EMP><ID>33</ID><NAME>Jason</NAME></EMP></STATICDATA>
I have used some XML functions and have written the below query.
select XMLROOT(XMLELEMENT(staticdata,XMLELEMENT(EMP,XMLELEMENT(ID,ID),XMLELEMENT(NAME,NAME))), version '1.0" encoding="UTF-8') xml FROM EMP;
output of my query:
<?xml version="1.0" encoding="UTF-8"?>
<STATICDATA>
<EMP>
<ID>11</ID>
<NAME>Joy</NAME>
</EMP>
</STATICDATA>
<?xml version="1.0" encoding="UTF-8"?>
<STATICDATA>
<EMP>
<ID>22</ID>
<NAME>Mike</NAME>
</EMP>
</STATICDATA>
<?xml version="1.0" encoding="UTF-8"?>
<STATICDATA>
<EMP>
<ID>33</ID>
<NAME>Jason</NAME>
</EMP>
</STATICDATA>
But i want the out as the required output above. every record in a single line.Why?
Some things output XML all as one stream, some things naturally display it structured. It doesn't matter as the XML is still the same because by it's very nature it is a structured data definition. Anything that reads XML will be able to read it whether it's on one line (streamed) or structured.
also can i export all the columns of the table by some thing like select * from the table in XML file ?A couple of ways of exporting XML to a file...
-- DBMS_XSLPROCESSOR.clob2file
-- outputs a clob to a file
DECLARE
ctx DBMS_XMLGEN.ctxtype;
BEGIN
ctx := DBMS_XMLGEN.newcontext ('select * from emp');
DBMS_XSLPROCESSOR.clob2file (DBMS_XMLGEN.getxml (ctx), 'TEMP', 'emp.xml');
DBMS_XMLGEN.closecontext (ctx);
END;
PL/SQL procedure successfully completed.or
..snip..
v_xml XMLTYPE;
v_doc XMLDOM.DOMDocument;
v_dir VARCHAR2(2000);
v_file VARCHAR2(2000);
BEGIN
v_xml := ... populate with XML ...;
v_dir := 'TEST_DIR'; -- directory object name (in UPPER CASE)
v_file := 'myfile.xml';
v_doc := DBMS_XMLDOM.NEWDOMDOCUMENT(v_xml);
DBMS_XMLDOM.WRITETOFILE(v_doc, v_dir||'\'||v_file, 'UTF-8');
DBMS_XMLDOM.FREEDOCUMENT(v_doc);
..snip.. -
Generating xml from diff tables in a db
hi,
i need to write a oracle procedure, which when called generates xml doc (building xml from different tables in database.). i got the DTDs . but i still dont understand how can the data be pulled from diff tables and put in the one xml? can anyone give me rough idea.. i know that i have to use xmlquery and xml_save packages... but still not much clear..
i m working on oracle 8i database. any help is appreciated.. thanks.Any feedback to the above questions would be greatly appreciated!
-
Creating XML from Oracle Tables
Would it be possible to post me a snapshot of the ODI Flow diagram for an Oracle to XML conversion? Does the staging area have to be on the Target (XML)? What KMs & CM should be used? Can the XML be written straight back to an .xml file? What should the XML Schema look like?
These are the KMs I use: LKM-SQL to SQL; IKM-SQL Incremental Update; CKM-SQL.
My flow is straight from source (oracle) to target (xml), with staging area on target (doesn't feel right).
My Oracle Dataserver & Schema work fine. Not sure about the XML dataserver setup though - I think this is where the problem lies. These are my JDBC settings:
- com.sunopsis.jdbc.driver.xml.SnpsXmlDriver
- jdbc:snps:xml?f=E:\Oracle ODI\Member.xsd
I am evaluating ODI for a client and I wanted to throw together a quick demo showing how easily ODI can generate XML from any source. I know this is the case as I understand the concept of ODI's components - just haven't had time to read manuals thoroughly.
Many thanks for your help,
SteveHello,
1. Try to test the connection to the XML dataserver.
2. Create a model and reverse-engineer this dataserver. You'll see what the XML structure is mapped to immediately.
3. Integrate data to this model (using standard KM targeting "SQL").
You can put the staging area on the Oracle source or in the XML driver if you want. Both solutions will work.
just haven't had time to read manuals thoroughly.I think you should quickly read the "Sunopsis ODI with... XML" section in the manual.
It is not very long and very helpful. Have also a quick look at the XML driver documentation.
Regards,
-FX -
Generating xml from oracle 10g with BLOB image
Hello All,
I have employee table with id(primary key), firstname,lastname
and I have portrait table with id(secondary key from employee table),image (blob)
portrait table store images of the employees which are in the employee table.
I want to generate following xml output
<rowset>
<id> </id>
<firstname> </firstname>
<lastname> </lastname>
<portrait>base64formatted string containing image of the employee for the particular id specified in the id tag</portrait>
</rowset>
and save this xml as id.xml into a particular folder in the c drive and generate such xmls for each and every row of the emplyee table...
e.g. if i have 200 emplyees with id as 1 ,2 ,.....,200 and their respective portraits into portrait table; then I want to save these as separate xml files with the names 1.xml , 2.xml , .....200.xml inside a folder say : C:\temp...
Any help is highly appreciated
Edited by: user1030398 on Sep 28, 2010 12:01 PM
Edited by: user1030398 on Sep 28, 2010 12:02 PMI was going to write up a longer answer, but then I realized this post contains pretty much all you need
http://www.liberidu.com/blog/?p=365
I like using XMLElement/XMLForest to build the XML as it gives you the most control.
In the first example on Marco's website, you would just use dbms_xslprocessor.clob2file to write each file out to disk with a CURSOR FOR loop instead of doing a single OPEN/FETCH/CLOSE. The cursor would return two columns, employee.id and the generated XML. The filename would be based on the "id" column returned by the CURSOR.
Assumption: The machine that Oracle resides on has the "C:\temp" directory that you want to write to. You cannot use this method to right files onto a client machine.
Hope that gets you started. -
Generate xml from a table and insert the xml into another table
I want to generate an xml file from a table and insert it into another table all in one tsql
insert into table B(xmlfile)
select * from tableA
FOR
XML
PATH('ac'),TYPE,ELEMENTS
XSINIL,ROOT('Accum')
Is not working any helpI have solved my issue all I did was to change my column datatype to xml
-
While generating XML data from Oracle relational database, using the following SQL statement,
SELECT XMLElement("Date", VioDate)
FROM TableName
WHERE VioId= 10;
I am getting the result as :
[][][][]<Date>2010-03-22</Date>
There four small squares coming before the xml element.
Can anyone let me know why I am getting this and how to correct it.
I am using Oracle SQL Developer version 1.2.1 Build MAIN - 32.13 to run the above statement.
RegardsHi,
Probably an issue about how the client "implicitly" converts an XMLType to display its lob content.
You may use getStringVal() or getClobVal() methods to get the content :
SQL*Plus: Release 10.1.0.4.2 - Production on Lun. Mars 29 16:28:39 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connecté à :
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select xmlelement("TEST", 'ABC') from dual;
XMLELEMENT("TEST",'ABC')
SQL> select xmlelement("TEST", 'ABC').getclobval() from dual;
XMLELEMENT("TEST",'ABC').GETCLOBVAL()
<TEST>ABC</TEST>HTH -
Hi all,
I have to generate an xml as given in the below format:
There are 5 subjects.
Rules to frame the xml:
1) Whether students have opted for each subjects empty tags should be present , for eg: subCodeOne
2) If there are duplicates in studid it has to be removed for each subject code.
3) <subCodeOneStud> -- student details about subject code 1
<studId> --- students name without duplicates
<subCodeOnemarks> --- student marks for subject code1
<subCodeOnePass> -- If atleast one student has passed in that subject this has to be set to Y
In case of scenarios like 1 it should be N
FORMAT:
=======
<subCodeOneStud>
<StudId></StudId>
</subCodeOneStud>
<subCodeOnemarks>
<marks></marks>
</subCodeOnemarks>
<subCodeOnePass>N</subCodeOnePass>
<subCodeTwoStud>
<StudId>531</StudId>
</subCodeTwoStud>
<subCodeTwomarks>
<marks>9414</marks>
</subCodeTwomarks>
<subCodeTwoPass>N</subCodeTwoPass>
<subCodeThreeStud>
<StudId>531</StudId>
</subCodeThreeStud>
<subCodeThreemarks>
<marks>8450</marks>
<marks>0634</marks>
</subCodeThreemarks>
<subCodeThreePass>N</subCodeThreePass>
<subCodeFourStud>
<StudId>1757</StudId>
</subCodeFourStud>
<subCodeFourmarks>
<marks>0405</marks>
</subCodeFourmarks>
<subCodeFourPass>N</subCodeFourPass>
<subCodeFiveStud>
<StudId>1757</StudId>
</subCodeFiveStud>
<subCodeFivemarks>
<marks>0412</marks>
</subCodeFivemarks>
<subCodeFivePass>N</subCodeFivePass>
SELECT
sub_i,/*to remove duplicate studnames */
extract(
deleteXML(
xmlelement("root", xmlparse(content stud_ids))
, '/root/studId[preceding-sibling::studId=.]'
, '/root/studId'
) students,
marks,
pass_flag,
,sub_i_w
FROM
SELECT
sub_i,sub_i_w,
'<studId>'||LTRIM(MAX(sys_connect_by_path(stud_name,'</studId><studId>')),'</studId><studId>')||'</studId>' stud_ids,
'<marks>'||LTRIM(MAX(sys_connect_by_path(marks,'</marks><marks>')),'</marks><marks>')||'</marks>' marks,
DECODE(MAX(pass_f),1,'Y','N') pass_flag
FROM
(SELECT
sub_i,sub_i_w,
stud_name,
marks,
pass_f,
ROW_NUMBER() OVER(PARTITION BY PSN_ID ORDER BY sub_i ) RN
FROM
SELECT
LEVEL sub_i,
REPLACE(REPLACE(INITCAP(to_char(to_date(LEVEL,'J'), 'JSP')),' ',''),'-','') sub_i_w /*subject id in words for the outer most tag */
FROM
DUAL
CONNECT
LEVEL <= 5
)A
LEFT OUTER JOIN
(SELECT sub_i,
stud_name,
marks,
decode(result,'Y',1,0) pass_f,
FROM
marklist
)B
ON (A.sub_i=B.sub_i)
START WITH RN = 1
CONNECT BY PRIOR RN = RN - 1 AND PRIOR sub_i = sub_i
GROUP BY sub_i,sub_i_w
)Doubts:
========
1) I am using the above query to generate studId and marks tag for all the five subjects
I am getting an error: "ORA-01854:julian date must be between 1 and 5373484"
Can any one help me in resolving this?
2) To get the final xml i may have to add the below select query to the above query. But this kind of concatenation to get the tag , throws an error: right parenthesis
SELECT
REPLACE(
REPLACE(
XMLAGG(
XMLELEMENT("subCode"||sub_i||"Stud",students),
XMLELEMENT("subCode"||sub_i||"marks",marks),
)).getStringVal(),'&<','<'),'&>','>')
FROM3) Is this way of writing a query to generate the xml is effiecient .I am using oracle 10g
Thanks in advance
Edited by: BluShadow on 17-Oct-2011 08:09
added {noformat}{noformat} tags for formatting. Please read {message:id=9360002} and learn to do this yourself.Java application expects the tags to be like this :(I see...
Don't forget to format what you post here as BluShadow kindly did for you earlier.
Apart from the obvious readability reasons, that's particularly important for XML or HTML code because the forum software here might interpret some tags and not render them correctly.
Thanks for the sample data anyway.
This should get you going :
with subjects as (
select level as sub_id
, initcap(to_char(to_date(level,'J'), 'JSP')) as sub_id_sp
from dual
connect by level <= 5
select xmlagg(
xmlconcat(
xmlelement(evalname('subCode'||sub_id_sp||'Stud'),
xmlagg( case when rn = 1 then xmlelement("StudId", stud_name) end )
, xmlelement(evalname('subCode'||sub_id_sp||'marks'),
xmlagg( xmlelement("marks", marks) )
, xmlelement(evalname('subCode'||sub_id_sp||'Pass'),
nvl(max(case when pass_f = 'Y' then pass_f end), 'N')
).extract('/*') -- to "pretty-print" the result (not mandatory)
as result
from (
select s.sub_id
, s.sub_id_sp
, m.stud_name
, m.marks
, m.pass_f
, row_number() over(partition by s.sub_id, m.stud_name order by null) rn
from subjects s
left outer join marklist m on m.sub_id = s.sub_id
group by sub_id, sub_id_sp
RESULT
<subCodeOneStud>
<StudId/>
</subCodeOneStud>
<subCodeOnemarks>
<marks/>
</subCodeOnemarks>
<subCodeOnePass>N</subCodeOnePass>
<subCodeTwoStud>
<StudId>raj</StudId>
<StudId>rosy</StudId>
</subCodeTwoStud>
<subCodeTwomarks>
<marks>20</marks>
<marks>80</marks>
</subCodeTwomarks>
<subCodeTwoPass>Y</subCodeTwoPass>
<subCodeThreeStud>
<StudId/>
</subCodeThreeStud>
<subCodeThreemarks>
<marks/>
</subCodeThreemarks>
<subCodeThreePass>N</subCodeThreePass>
<subCodeFourStud>
<StudId>jaya</StudId>
<StudId>padma</StudId>
<StudId>rosy</StudId>
</subCodeFourStud>
<subCodeFourmarks>
<marks>100</marks>
<marks>40</marks>
<marks>30</marks>
<marks>80</marks>
</subCodeFourmarks>
<subCodeFourPass>Y</subCodeFourPass>
<subCodeFiveStud>
<StudId>jai</StudId>
<StudId>padma</StudId>
</subCodeFiveStud>
<subCodeFivemarks>
<marks>100</marks>
<marks>90</marks>
</subCodeFivemarks>
<subCodeFivePass>Y</subCodeFivePass> -
Create XML from oracle table if not null
Hello dear community,
I have a problem by creating an XML file in oracle and hope you could help me.
What I have is an table named "description" with three rows there:
person varchar2(50)
adress varchar2(50)
Nr number
Reading this table I am going to create an XML file like that:
Procedure Create_XML (iNr IN number, cXmlFile OUT clob) is
varPerson varchar2(50);
varAdress varchar2(50);
Begin
varPerson := ... ;
varAdress := ... ;
select
xmlserialize
content
xmlelement
"Head",
xmlelement
"Node",
xmlelement
"Line",
xmlelement("ATNAM", 'PERSON'),
xmlelement("ATWRT", PERSON),
xmlelement("ATFOR", varPerson)
xmlelement
"Line",
xmlelement("ATNAM", 'ADRESS'),
xmlelement("ATWRT", ADRESS),
xmlelement("ATFOR", varAdress)
indent
) as xml
into cXmlFile
from description
where Nr = iNr;
End Create_XML;
What I want to do, is just to take the value from the both rows "person" and "adress" and fill the xml file with additional info.
1. My first question is, if it is possible to create any kind of routine for the xmlelement "Line" instead of doing it all over and over again? How?
2. An other issue is very important to me: how can I check here if f.i. the row person is empty or not? If it is, the xmlelement "Line" with person information in it should not be created at all.
Any answer would really help me!
Thank you a lot in advance!Hi,
Could you elaborate a little on your first question?
Are you looking for something like :
SELECT xmlquery(
'<head>
<node>
for $i in ora:view("DESCRIPTION")/ROW[NR=$nr]/*[local-name()!="NR"]
return element Line {
element ATNAM {local-name($i)},
element ATWRT {$i/text()}
</node>
</head>'
passing sys_xmlgen(1) as "nr"
returning content
FROM dual;but since you use a specific variable for each "line" type, I don't see how we can generalize the construction of the line element. -
Generating XML from relational tables and storing back in CLOB field
I have been reviewing the documentation and trying to figure out the best approach. I am on v 10.2.0.3 and need to select from a parent table and three child tables and want to generate the results as xml that I will place in a clob field in another table. I looked at XMLQuery and dbms_xmlgen.getxml. The difference appears to be that getxml allows you to code traditional sql to join the tables.
I would greatly appreciate it if someone could provide some feedback and any sample code along the line that I describe above.
Thank you in advance for your help!
JerryAny feedback to the above questions would be greatly appreciated!
-
Generating xml from oracle-data
In our company we have to export customer-data to xml using a predefined format (which we cannot change).
This xml will subsequently be used to import the data into another system.
I'm not that familiar with XML. Most of the work can be done using dbms_xmlgen which is pretty simple and straightforward to use
There is one type of element I cannot place correctly in the specification
The use of foreign keys. For instance
A employee has a foreign key to a bussiness unit that should be written down in the xml
when using "normal" dbms_xmlgen the tag would be like
<bussinessunit>"bisut100"</bussinessunit>
But the specification specifies the following format
<bussinessunit bussinesunitId="bisut100"/>
Any idea how to get this using dbms_xmlgen?
Or if not possible with dbms_xmlgen how could this easily be achieved?Thanks for the reply and the challenge is more to generate the closing tag exactly like in the specification
The following is a snippet of what is required
-<employee>
<id>2</id>
<empno>102105<empno>
-<name>
<firstname>Tom</firstname>
<lastname>Hanks</lastname>
</name>
<bussinessunit bussinesunitId="bisut100"/>
<employee>
-<employee>
<id>3</id>
I wonder how to achieve the line
<bussinessunit bussinesunitId="bisut100"/>
I tried using
DBMS_XMLGEN.setNullHandling(qryCtx, DBMS_XMLGEN.EMPTY_TAG);
and then the construction
qryCtx := DBMS_XMLGEN.newContext(
' select id, custom0 bussinessunit , company_id "@bussinessunitId", lname
from tpt_employees t
where rownum < 2
and custom0 is null');
Unfortunately, the resulting xml-line
<BUSSINESSUNIT bussinessunitId = "1" <BUSSINESSUNIT/>
is not the xml I had hoped for (it's not valid as well) -
Generate PDF file from oracle Table
We need to populate pdf file into oracle table of column blob through informatica by taking
path\name(/path/filename.PDF) as input from source table.
The pdf file is on some other server so, we need to create a stored procedure which will give pdf file as output from
other server by taking path\name from source table column as mentioned above.
So please suggest how we can create a stored procedure for that purpose.
If possible please share some script.Dear all,am new to oracle report and oracle forms and i know the
basics how to generate the report and to create the form, Now my doubt is, like generating report
from oracle report how to generate the report from oracle from,should i add any command button? and where
to add the coding and what coding ? when i click that command button the report should be generated like oracle
report,what should i do?Please help me to learn.
my table name is 'student' and it has the following columns,
sid,sname,grade,result.
Am using oracle from 10.1.2.0.2 version and
oracle report version is 10.1.2.0.2.
Please give step by step procss.
Thank you. -
Using FDM to load data from oracle table (Integration Import Script)
Hi,
I am using Integration Import Script to load data from oracle table to worktables in FDM.
i am getting following error while running the script.
Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done
Attaching the full error report
ERROR:
Code............................................. -2147217887
Description...................................... Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
At line: 22
Procedure........................................ clsImpProcessMgr.fLoadAndProcessFile
Component........................................ upsWObjectsDM
Version.......................................... 1112
Thread........................................... 6260
IDENTIFICATION:
User............................................. ******
Computer Name.................................... *******
App Name......................................... FDMAPP
Client App....................................... WebClient
CONNECTION:
Provider......................................... ORAOLEDB.ORACLE
Data Server......................................
Database Name.................................... DBNAME
Trusted Connect.................................. False
Connect Status.. Connection Open
GLOBALS:
Location......................................... SCRTEST
Location ID...................................... 750
Location Seg..................................... 4
Category......................................... FDM ACTUAL
Category ID...................................... 13
Period........................................... Jun - 2011
Period ID........................................ 6/30/2011
POV Local........................................ True
Language......................................... 1033
User Level....................................... 1
All Partitions................................... True
Is Auditor....................................... False
I am using the following script
Function ImpScrTest(strLoc, lngCatKey, dblPerKey, strWorkTableName)
'Oracle Hyperion FDM Integration Import Script:
'Created By: Dhananjay
'Date Created: 1/17/2012 10:29:53 AM
'Purpose:A test script to import data from Oracle EBS tables
Dim cnSS 'ADODB.Connection
Dim strSQL 'SQL string
Dim rs 'Recordset
Dim rsAppend 'tTB table append rs object
'Initialize objects
Set cnSS = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
Set rsAppend = DW.DataAccess.farsTable(strWorkTableName)
'Connect to SQL Server database
cnss.open "Provider=OraOLEDB.Oracle.1;Data Source= +server+;Initial Catalog= +catalog+;User ID= +uid+;Password= +pass+"
'Create query string
strSQL = "Select AMOUNT,DESCRIPTION,ACCOUNT,ENTITY FROM +catalog+.TEST_TMP"
'Get data
rs.Open strSQL, cnSS
'Check for data
If rs.bof And rs.eof Then
RES.PlngActionType = 2
RES.PstrActionValue = "No Records to load!"
Exit Function
End If
'Loop through records and append to tTB table in location’s DB
If Not rs.bof And Not rs.eof Then
Do While Not rs.eof
rsAppend.AddNew
rsAppend.Fields("PartitionKey") = RES.PlngLocKey
rsAppend.Fields("CatKey") = RES.PlngCatKey
rsAppend.Fields("PeriodKey") = RES.PdtePerKey
rsAppend.Fields("DataView") = "YTD"
rsAppend.Fields("CalcAcctType") = 9
rsAppend.Fields("Amount") = rs.fields("Amount").Value
rsAppend.Fields("Desc1") = rs.fields("Description").Value
rsAppend.Fields("Account") = rs.fields("Account").Value
rsAppend.Fields("Entity") = rs.fields("Entity").Value
rsAppend.Update
rs.movenext
Loop
End If
'Records loaded
RES.PlngActionType = 6
RES.PstrActionValue = "Import successful!"
'Assign Return value
SQLIntegration = True
End Function
Please help me on this
Thanks,
Dhananjay
Edited by: DBS on Feb 9, 2012 10:21 PMHi,
I found the problem.It was because of the connection string.The format was different for oracle tables.
PFB the format
*cnss.open"Provider=OraOLEDB.Oracle.1;Data Source= servername:port/SID;Database= DB;User Id=aaaa;Password=aaaa;"*
And thanks *SH* for quick response.
So closing the thread......
Thanks,
Dhananjay -
I'm a total newbie in XML DB and need advice on generating XML from database.
The situation is the following: there is a legacy web application which uses an XML document as a configuration file. This document conforms to some well-defined schema. For instance:
<config>
<title value="TITLE" />
<subtitle value="SUBTITLE" />
<style url="default.css" />
<widgets>
<widget id="1" opened="true" />
<widget id="2" opened="false" />
</widgets>
</config>
It contains portions of static data which are common for all users as well as dynamic personal data.
Dynamic data comes from two sources:
1) security considerations (for instance, not all widgets are available for some users) - thus the "master" configuration content must be filtered, but not otherwise modified;
2) user preferences (for instance, user can set widget2 to be opened by default) - thus values of some attributes must be different for each user. When the user saves her preferences, the entire document with new values is posted back to server.
We want to try to store user preferences, apply security and generate personalized configuration documents using XML DB.
So we need advice on storage models and generation procedures - which should be more efficient and easy to support or extend.
Please note, that there is no requirement to actually store data as XML.
Thanks in advance!
P.S.: Sorry for the incomplete initial post.
Edited by: WxD on 27.09.2010 11:45Hi,
See this link for more details
http://www.stanford.edu/dept/itss/docs/oracle/10g/appdev.101/b10790/xdb13gen.htm -
Namespaces when Composing XML from Reational Tables
Hi,
I am trying to create XML documents from Oracle tables that look like this (this is a very abbreviated version):
<?xml version="1.0" encoding="UTF-8" ?>
<Document xmlns="urn:iso:std:etc:etc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:iso:std:etc:etc.03 ZZZZZ6A.xsd">
<Cstmr>
<GrpHdr>
<MsgId>1006</MsgId>
<CreDtTm>2011-07-12T11:49:07.0Z</CreDtTm>
<NbOfTxs>4624</NbOfTxs>
<CtrlSum>1133772055</CtrlSum>
</GrpHdr>
</Cstmr>
</Document>
I have a SELECT statement that works successfully as follows:
SELECT XMLElement(NOENTITYESCAPING "Document"
,XMLAttributes('urn:iso:std:iso:etc:etc' AS "xmlns"
,'http://www.w3.org/2001/XMLSchema-instance' AS "xmlns:xsi"
,'urn:iso:std:iso:etc:etc.03 ZZZZZ6A.xsd' AS "xsi:schemaLocation"
,XMLElement(NOENTITYESCAPING "Cstmr"
,XMLElement(NOENTITYESCAPING "GrpHdr"
,XMLForest(spi1.msg_id AS "MsgId"
,TO_CHAR(SYSDATE,'YYYY-MM-DD') || 'T' || TO_CHAR(SYSDATE,'HH24:MI:SS') || '.0Z'
AS "CreDtTm"
,COUNT(*) AS "NbOfTxs"
,SUM(spi1.payment_pence_amt) / 100
AS "CtrlSum"
) AS xml_doc
FROM t_std18_payment_item_test spi1
GROUP BY spi1.msg_id;
This succesffully produces the desired output:
XML_DOC
<Document xmlns="urn:iso:std:iso:etc:etc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:
schemaLocation="urn:iso:std:iso:etc:etc.03 ZZZZZ6A.xsd"><Cstmr><GrpHdr><MsgId>1006</MsgId><CreDtTm>2
011-07-12T13:20:19.0Z</CreDtTm><NbOfTxs>4624</NbOfTxs><CtrlSum>1133772055</CtrlSum></GrpHdr></Cstmr>
</Document>
I can then successfully create a VIEW for this:
CREATE OR REPLACE VIEW payment_xml of XMLType
WITH OBJECT ID (XMLCast(XMLQuery('/Document/CstmrCdtTrfInitn' Passing OBJECT_VALUE RETURNING CONTENT) AS BINARY_DOUBLE))
AS
SELECT XMLElement(NOENTITYESCAPING "Document"
,XMLAttributes('urn:iso:std:iso:etc:etc' AS "xmlns"
,'http://www.w3.org/2001/XMLSchema-instance' AS "xmlns:xsi"
,'urn:iso:std:iso:etc:etc.03 ZZZZZ6A.xsd' AS "xsi:schemaLocation"
,XMLElement(NOENTITYESCAPING "Cstmr"
,XMLElement(NOENTITYESCAPING "GrpHdr"
,XMLForest(spi1.msg_id AS "MsgId"
,TO_CHAR(SYSDATE,'YYYY-MM-DD') || 'T' || TO_CHAR(SYSDATE,'HH24:MI:SS') || '.0Z'
AS "CreDtTm"
,COUNT(*) AS "NbOfTxs"
,SUM(spi1.payment_pence_amt) / 100
AS "CtrlSum"
FROM t_std18_payment_item_test spi1
GROUP BY spi1.msg_id;
But when I select from it using:
SELECT XMLSerialize(Content OBJECT_VALUE AS CLOB indent) AS "Payments"
FROM payment_xml;
I get this:
FROM payment_xml
ERROR at line 2:
ORA-19276: XPST0005 - XPath step specifies an invalid element/attribute name: (Document)
I guess this is to do with my namespace declarations as I can successfully select from the view without the <Document> tag. However, I cannot fathom out quite what I have done wrong or how to fix it.
Any help gratefully received.
Thanks you,
GrahamThat said, have you already looked into the FAQ on this forum. You could have found stuff like
SQL> begin
2 dbms_xmlschema.registerSchema
3 (
4 :schemaURL,
5 xdbURIType(:schemaPath).getClob(),
6 TRUE,TRUE,FALSE,FALSE
7 );
8 end;
9 /
PL/SQL procedure successfully completed.
SQL> create or replace view PURCHASEORDER_XML
2 of xmltype
3 xmlSCHEMA "http://xfiles:8080/home/SCOTT/poSource/xsd/purchaseOrder.xsd" Element "PurchaseOrder"
4 with object id
5 (
6 substr(extractValue(object_value,'/PurchaseOrder/Reference'),1,32)
7 )
8 as
9 select xmlElement
10 (
11 "PurchaseOrder",
12 xmlAttributes
13 (
14 'http://xfiles:8080/home/SCOTT/poSource/xsd/purchaseOrder.xsd' as "xsi:noNamespaceSchemaLocation",
15 'http://www.w3.org/2001/XMLSchema-instance' as "xmlns:xsi"
16 ),
17 xmlElement("Reference",p.REFERENCE),
18 xmlElement
19 (
20 "Actions",
21 ( select xmlAgg
22 (
23 xmlElement
24 (
25 "Action",
26 xmlElement("User",ACTIONEDBY),
27 case
28 when DATEACTIONED is not null
29 then xmlElement("Date",DATEACTIONED)
30 end
31 )
32 )
33 from PURCHASEORDER_ACTION a
34 where a.REFERENCE = p.REFERENCE
35 )
36 ),
37 xmlElement
38 (
39 "Reject",
40 xmlForest
41 (
42 REJECTEDBY as "User",
43 DATEREJECTED as "Date",
44 COMMENTS as "Comments"
45 )
46 ),
47 xmlElement("Requestor",REQUESTER),
48 xmlElement("User",USERID),
49 xmlElement("CostCenter",COSTCENTER),
50 xmlElement
51 (
52 "ShippingInstructions",
53 xmlElement("name",SHIPTONAME),
54 xmlElement("address",ADDRESS),
55 xmlElement("telephone",PHONE)
56 ),
57 xmlElement("SpecialInstructions",SPECIALINSTRUCTIONS),
58 xmlElement
59 (
60 "LineItems",
61 ( select xmlAgg
62 (
63 xmlElement
64 (
65 "LineItem",
66 xmlAttributes(LINENO as "ItemNumber"),
67 xmlElement("Description",DESCRIPTION),
68 xmlElement
69 (
70 "Part",
71 xmlAttributes
72 (
73 UPC as "Id",
74 QUANTITY as "Quantity",
75 UNITPRICE as "UnitPrice"
76 )
77 )
78 )
79 )
80 from PURCHASEORDER_LINEITEM l
81 where l.REFERENCE = p.REFERENCE
82 )
83 )
84 )
85 from PURCHASEORDER_TABLE p, PURCHASEORDER_REJECTION r, PURCHASEORDER_SHIPPING s
86 where r.REFERENCE = p.REFERENCE
87 and s.REFERENCE = p.REFERENCE
88 /
View created.
and how to do this based on relational content...
Maybe you are looking for
-
IMac G4 startup has slowed to a crawl on 10.4.3
I have used the Tiger installation disc to attempt to repair disk permissions and repair disk. When I run verify disk, it indictes "keys out of order" and gives me a "repair disk" message. When I run the repair disk from the installation DVD, the blu
-
Error in writing to directory /tmp/OraInstall2007-08-27_12-58-31AM.
hi. i am new to oracle installation. i set all parameters and environment values. when i entered runinstaller, i recieving this error message. [oracle@localhost Disk1]$ ./runInstaller Error in writing to directory /tmp/OraInstall2007-08-27_12-58-31AM
-
I am using acrobat 9 pro. Using the optimise pdf. File size increases?
I am trying to clean up some previously scanned images containing mainly text. The original file sizes are 80K. I use the optimise pdf tool to 'despeckle' with all the other option set to off. When I save and then check the new file size it has incre
-
User cannot see tax amount while creating PO
Hi All My user cannot see tax amount while creating PO but on displaying the PO after saving he can see the tax amount in the PO. Is there any authorisation issue or what is the proble
-
Re-provisioning to RTC for re-created users
Seems that there's a problem with RTC provisioning when re-creating a user with the same name in OID. The only workaround I've found so far is to restart the RTC component with opmnctl. Doing this, there was another problem - restart fails: [oracle@p