Generating XML using PL/SQL
hi All,
We have an interface across two different applications in an organisation. Data is ported across these two application in a flat file which has specific format. These files are generated using generic pro c programs. Now we are planning to replace these files with XML. Also to replace generic pro c with PL/SQL to generate and read XML files. Now my question is, whether using PL/SQL to generate/read XML file will be faster than generating/reading flat files using pro c? Will the performance improve significantly? If anybody has worked on this, your inputs will be valuable.
Thanks in advance. Hoping to hear something veru soon from the masters.
Regards,
Rajesh
hi All,
We have an interface across two different applications in an organisation. Data is ported across these two application in a flat file which has specific format. These files are generated using generic pro c programs. Now we are planning to replace these files with XML. Also to replace generic pro c with PL/SQL to generate and read XML files. Now my question is, whether using PL/SQL to generate/read XML file will be faster than generating/reading flat files using pro c? Will the performance improve significantly? If anybody has worked on this, your inputs will be valuable.
Thanks in advance. Hoping to hear something veru soon from the masters.
Regards,
Rajesh
Similar Messages
-
Generating xml using PL/SQL taking a lot of space in TEMP tablespace
We wrote a stored procedure that generate xml which will be stored in a CLOB column. Environment is 9i on Windows 2003.
The gnerated xml is about 800K. In the procedure there is one big cursor that will retrieve 200 records of 55 fields and many other small dynamic cursors that open and close here and there. The fields are pretty small. Biggest ones are like varchar2(30). The query for the big cursor does using union and need sorting.
Can anyone explain why it takes about 15G of TEMP tablespace to accomplish this job and is there a way to avoid this?The version is Enterprise Edition 9.2.0.1.0.
Below is the query.
SELECT ROWNUM + ( SELECT NVL(MAX(WQX_ACTIVITY_GEN_ID), 0) FROM WQX_ACTIVITY ) as WQX_ACTIVITY_GEN_ID
, A.ACTIVITYIDENTIFIER2 as ACTIVITY_IDENTIFIER
, (SELECT MAX(O.ORGANIZATION_NAME) FROM SYS_ORGANIZATION O WHERE O.ORGANIZATION_ID = 111242) as ORGANIZATION_NAME
, (SELECT MAX(P.PROJECT_IDENTIFIER) FROM SYS_PROJECT P WHERE P.PROJECT_ID = 111242) as PROJECT_IDENTIFIER
, A.ACTIVITYTYPECODE as ACTIVITY_TYPE_CD
, A.ActivityMediaName as ACTIVITY_MEDIA_NAME
, A.ActivityMediaSubDivisionName as MEDIA_SUB_DIVISION
, A.ActivityStartDate as ACTIVITY_START_DATE
, CASE WHEN A.ActivityStartTime is not NULL THEN
substr(A.ActivityStartTime,1,2)||':'||substr(A.ActivityStartTime,3,2)||':00'
WHEN A.ActivityStartTime is NULL THEN ''
END as ACTIVITY_START_TIME
-- , substr(A.ActivityStartTime,1,2)||':'||substr(A.ActivityStartTime,3,2)||':00' as ACTIVITY_START_TIME
, A.ACTIVITYENDDATE as ACTIVITY_END_DATE
, CASE WHEN A.ACTIVITYENDTIME is not NULL THEN
substr(A.ACTIVITYENDTIME,1,2)||':'||substr(A.ACTIVITYENDTIME,3,2)||':00'
WHEN A.ACTIVITYENDTIME is NULL THEN ''
END as ACTIVITY_END_TIME
-- , substr(A.ACTIVITYENDTIME,1,2)||':'||substr(A.ACTIVITYENDTIME,3,2)||':00' as ACTIVITY_END_TIME
, A.TIMEZONECODE1 as TIME_ZONE_CD
, A.ActivityRelativeDepthName as RELATIVE_DEPTH_NAME
, NULL as DEPTH_HEIGHT_MEASURE
, NULL as DEPTH_HEIGHT_UNIT
, 111242 as MONITORING_LOC_ID
, A.ACTIVITYCOMMENTTEXT as COMMENT_
, A.SamplerName as SAMPLER_NAME
, A.ActivityArea as ACTIVITY_AREA
, A.ReportingRound as REPORTING_ROUND
, A.SamplePanel as SAMPLEPANEL
, A.DataIncludedinReport as DATA_INCLUDED_IN_REPORT
, A.FlowStatusIndicator as FLOW_STATUS_IND
, A.SampleChainOfCustody as SAMPLE_COC
, A.ActivitySeason as ACTIVITY_SEASON
, A.RunoffImpact as RUNOFF_IMPACT
, (111242) as MONI_LOC_ID
, (SELECT MAX(B.MONI_LOC_IDENTIFIER) FROM WQX_MONITORING_LOC B WHERE B.MONI_LOC_IDENTIFIER = A.MONITORINGLOCATIONIDENTIFIER) as MONI_LOC_IDENTIFIER
, 111242 as PROJECT_ID
, NULL as BIO_ASSEMB_SAMPLED_NAME
, NULL as BIO_TOXICITY_TEST_TYPE
, A.METHODIDENTIFIER1 as SAMPLE_COLLECT_METHOD_IDENTIFI
, A.METHODIDENTIFIERCONTEXT1 as SAMPLE_COLLECT_METHOD_CONTEXT
, A.METHODNAME1 as SAMPLE_COLLECT_METHOD_NAME
, NULL as SAMPLE_COLLECT_QUALIFIER_TYPE
, A.METHODDESCRIPTIONTEXT1 as SAMPLE_COLLECT_DESC
, A.SampleCollectionEquipmentName as SAMPLE_COLLECT_EQUIP_NAME
, A.SAMPLECOLLECTIONEQUIPMENTTXT as SAMPLE_COLLECT_EQUIP_DESC
, A.METHODNAME2 as SAMPLE_PREP_METHOD_NAME
, A.METHODIDENTIFIER2 as SAMPLE_PREP_METHOD_IDENTIFIER
, A.METHODIDENTIFIERCONTEXT2 as SAMPLE_PREP_METHOD_CONTEXT
, NULL as SAMPLE_PREP_QUALIFIER_TYPE
, A.METHODDESCRIPTIONTEXT1 as SAMPLE_PREP_DESC
, A.SampleContainerTypeName as SAMPLE_CONTAINER_TYPE
, A.SampleContainerColorName as SAMPLE_CONTAINER_COLOR
, A.ChemicalPreservativeUsedName as CHEM_PRESERVATIVE_USED
, A.ThermalPreservativeUsedName as THERMAL_PRESERVATIVE_USED
, A.SAMPLETRANSPORTSTORAGEDESC as SAMPLE_TRANS_STORAGE
, A.AnalysisStartTime as AnalysisStartTime
, A.AnalysisEndTime as AnalysisEndTime
, A.MethodSpeciationName as MethodSpeciationName
, A.ResultLaboratoryCommentCode as ResultLaboratoryCommentCode
, A.UnidentifiedSpeciesIdentifier as UnidentifiedSpeciesIdentifier
FROM TMP_CHEMACTIVITYRESULTS A
WHERE A.SUBMISSION_ID = 111242
AND A.ACTIVITYIDENTIFIER2 NOT IN
( SELECT ACTIVITY_IDENTIFIER FROM WQX_ACTIVITY )
UNION
SELECT X.WQX_ACTIVITY_GEN_ID as WQX_ACTIVITY_GEN_ID
, A.ACTIVITYIDENTIFIER2 as ACTIVITY_IDENTIFIER
, (SELECT MAX(O.ORGANIZATION_NAME) FROM SYS_ORGANIZATION O WHERE O.ORGANIZATION_ID = 111242) as ORGANIZATION_NAME
, (SELECT MAX(P.PROJECT_IDENTIFIER) FROM SYS_PROJECT P WHERE P.PROJECT_ID = 111242) as PROJECT_IDENTIFIER
, NVL(A.ACTIVITYTYPECODE, (SELECT MAX(ACTYP_CD) FROM REF_ACTIVITY_TYPE WHERE TO_CHAR(ACTYP_UID) = TO_CHAR(X.ACTIVITY_TYPE_CD))) as ACTIVITY_TYPE_CD
, NVL(A.ActivityMediaName, X.ACTIVITY_MEDIA_NAME) as ACTIVITY_MEDIA_NAME
, NVL(A.ActivityMediaSubDivisionName, X.MEDIA_SUB_DIVISION) as MEDIA_SUB_DIVISION
, NVL(A.ActivityStartDate, TO_CHAR(X.ACTIVITY_START_DTTM, 'YYYY-MM-DD')) as ACTIVITY_START_DATE
, CASE WHEN A.ActivityStartTime is not NULL THEN
substr(A.ActivityStartTime,1,2)||':'||substr(A.ActivityStartTime,3,2)||':00'
WHEN A.ActivityStartTime is NULL THEN ''
END as ACTIVITY_START_TIME
-- , NVL((substr(A.ActivityStartTime,1,2)||':'||substr(A.ActivityStartTime,3,2)||':00'), TO_CHAR(X.ACTIVITY_START_DTTM, 'HH24:MI:SS')) as ACTIVITY_START_TIME
, NVL(A.ACTIVITYENDDATE, TO_CHAR(X.ACTIVITY_END_DTTM, 'YYYY-MM-DD')) as ACTIVITY_END_DATE
, NVL(A.ACTIVITYENDDATE, TO_CHAR(X.ACTIVITY_END_DTTM, 'HH24:MI:SS')) as ACTIVITY_END_TIME
, NVL(A.TIMEZONECODE1, X.TIME_ZONE_CD) as TIME_ZONE_CD
, NVL(A.ActivityRelativeDepthName, X.RELATIVE_DEPTH_NAME) as RELATIVE_DEPTH_NAME
, X.DEPTH_HEIGHT_MEASURE as DEPTH_HEIGHT_MEASURE
, X.DEPTH_HEIGHT_UNIT as DEPTH_HEIGHT_UNIT
, NVL(111242, X.MONITORING_LOC_ID) as MONITORING_LOC_ID
, NVL(A.ACTIVITYCOMMENTTEXT, X.COMMENT_) as COMMENT_
, NVL(A.SamplerName, X.SAMPLER_NAME) as SAMPLER_NAME
, NVL(A.ActivityArea, X.ACTIVITY_AREA) as ACTIVITY_AREA
, NVL(A.ReportingRound, X.REPORTING_ROUND) as REPORTING_ROUND
, NVL(A.SamplePanel, X.SAMPLEPANEL) as SAMPLEPANEL
, NVL(A.DataIncludedinReport, X.DATA_INCLUDED_IN_REPORT) as DATA_INCLUDED_IN_REPORT
, NVL(A.FlowStatusIndicator, X.FLOW_STATUS_IND) as FLOW_STATUS_IND
, NVL(A.SampleChainOfCustody, X.SAMPLE_COC) as SAMPLE_COC
, NVL(A.ActivitySeason, X.ACTIVITY_SEASON) as ACTIVITY_SEASON
, NVL(A.RunoffImpact, X.RUNOFF_IMPACT) as RUNOFF_IMPACT
, (111242) as MONI_LOC_ID
, (SELECT MAX(B.MONI_LOC_IDENTIFIER) FROM WQX_MONITORING_LOC B WHERE B.MONI_LOC_IDENTIFIER = A.MONITORINGLOCATIONIDENTIFIER) as MONI_LOC_IDENTIFIER
, 111242 as PROJECT_ID
, X.BIO_ASSEMB_SAMPLED_NAME as BIO_ASSEMB_SAMPLED_NAME
, X.BIO_TOXICITY_TEST_TYPE as BIO_TOXICITY_TEST_TYPE
, NVL(A.METHODIDENTIFIER1, X.SAMPLE_COLLECT_METHOD_IDENTIFI) as SAMPLE_COLLECT_METHOD_IDENTIFI
, NVL(A.METHODIDENTIFIERCONTEXT1, X.SAMPLE_COLLECT_METHOD_CONTEXT) as SAMPLE_COLLECT_METHOD_CONTEXT
, X.SAMPLE_COLLECT_METHOD_NAME as SAMPLE_COLLECT_METHOD_NAME
, X.SAMPLE_COLLECT_QUALIFIER_TYPE as SAMPLE_COLLECT_QUALIFIER_TYPE
, NVL(A.METHODDESCRIPTIONTEXT1, X.SAMPLE_COLLECT_DESC) as SAMPLE_COLLECT_DESC
, NVL(A.SampleCollectionEquipmentName, X.SAMPLE_COLLECT_EQUIP_NAME) as SAMPLE_COLLECT_EQUIP_NAME
, NVL(A.SAMPLECOLLECTIONEQUIPMENTTXT, X.SAMPLE_COLLECT_EQUIP_DESC) as SAMPLE_COLLECT_EQUIP_DESC
, NVL(A.METHODNAME2, X.SAMPLE_PREP_METHOD_NAME) as SAMPLE_PREP_METHOD_NAME
, NVL(A.METHODIDENTIFIER2, X.SAMPLE_PREP_METHOD_IDENTIFIER) as SAMPLE_PREP_METHOD_IDENTIFIER
, NVL(A.METHODIDENTIFIERCONTEXT2, X.SAMPLE_PREP_METHOD_CONTEXT) as SAMPLE_PREP_METHOD_CONTEXT
, X.SAMPLE_PREP_QUALIFIER_TYPE as SAMPLE_PREP_QUALIFIER_TYPE
, NVL(A.METHODDESCRIPTIONTEXT1, X.SAMPLE_PREP_DESC) as SAMPLE_PREP_DESC
, NVL(A.SampleContainerTypeName, X.SAMPLE_CONTAINER_TYPE) as SAMPLE_CONTAINER_TYPE
, NVL(A.SampleContainerColorName, X.SAMPLE_CONTAINER_COLOR) as SAMPLE_CONTAINER_COLOR
, NVL(A.ChemicalPreservativeUsedName, X.CHEM_PRESERVATIVE_USED) as CHEM_PRESERVATIVE_USED
, NVL(A.ThermalPreservativeUsedName, X.THERMAL_PRESERVATIVE_USED) as THERMAL_PRESERVATIVE_USED
, NVL(A.SAMPLETRANSPORTSTORAGEDESC, X.SAMPLE_TRANS_STORAGE) as SAMPLE_TRANS_STORAGE
, NVL(A.AnalysisStartTime, '') as AnalysisStartTime
, NVL(A.AnalysisEndTime, '') as AnalysisEndTime
, NVL(A.MethodSpeciationName, '') as MethodSpeciationName
, NVL(A.ResultLaboratoryCommentCode, '') as ResultLaboratoryCommentCode
, NVL(A.UnidentifiedSpeciesIdentifier, '') as UnidentifiedSpeciesIdentifier
FROM TMP_CHEMACTIVITYRESULTS A
JOIN WQX_ACTIVITY X ON A.ACTIVITYIDENTIFIER2 = X.ACTIVITY_IDENTIFIER
WHERE A.SUBMISSION_ID = 111242; -
Generating XML through PL/SQL
Hi everyone,
I got a new task at work, and my task is to generate XML through PL/SQL.
I am using Oracle 11g database, and SQL Developer 3.0.
The purpose of this procedure is to upload xml file to a queue, so my BPEL process can access the queue and do what it does.
This is my first time writing a procedure that generates xml so bear with me.
Below is a sample of the xml file I received. I need to generate xml file below through PL/SQL. All the information in xml file will need to be retrieved from the database.
I need your help to start working on this procedure. Your help is very much appreciated.
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body xmlns:ns1="http://www.ussc.gov/soa/casefile/event/types">
<caseFileUploadEvent xmlns:xsi="http://www.w3XX.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.XXXX.gov/soa/casefile/event/types ../xsd/Case_META.xsd"
xmlns="http://www.XXXX.gov/soa/casefile/event/types">
<taskEvent>SUBMIT</taskEvent>
<defendentDetails>
<sentensingDate>2008-11-10-05:00</sentensingDate>
<personDetails>
<personNameDetails>
<firstName>FIRSTNAME</firstName>
<middleName>B</middleName>
<lastName>LASTNAME</lastName>
</personNameDetails>
<dateOfBirth>1969-09-23-04:00</dateOfBirth>
</personDetails>
</defendentDetails>
<documentStatusDetails>
<otherStatus>
<intCode>61</intCode>
<description>Other documents included</description>
</otherStatus>
</documentStatusDetails>
<uploadOtherDetails>
<submissionId>427000447</submissionId> // NOTE: SUBMISSIONID WILL BE PASSED IN THROUGH THE PROCEDURE TO QUERY ALL THE INFORMATION NEEDED FOR THE XML FILE
<submissionSessionId>401622</submissionSessionId>
<submissionMethod>
<intCode>1</intCode>
<description>WebApplication</description>
</submissionMethod>
<submissionReason>
<intCode>1</intCode>
<description>InitialSubmission</description>
</submissionReason>
<district>
<intCode>99</intCode>
<description>Test District</description>
</district>
<caseFileType>
<intCode>10</intCode>
<description>Individual - Original</description>
</caseFileType>
<primaryDocketInfo>
<yearYY>5</yearYY>
<id>55555</id>
<defendentNumber>555</defendentNumber>
</primaryDocketInfo>
<PACTSId>55555555</PACTSId>
<AOJudgeId>
<intCode>2512</intCode>
<description>FABER, DAVID, A.</description>
</AOJudgeId>
<missingCasefile>false</missingCasefile>
<creator>
<firstName>will</firstName>
<lastName>smith</lastName>
<email>[email protected]</email>
<actionDate>2005-09-07T09:48:09.811-04:00</actionDate>
</creator>
<lastModifier>
<firstName>john</firstName>
<lastName>doe</lastName>
<email>[email protected]</email>
<actionDate>2006-10-03T08:51:21.5-04:00</actionDate>
</lastModifier>
</uploadOtherDetails>
</caseFileUploadEvent>
</soap:Body>
</soap:Envelope>procedure below
procedure upload_process(submission_id number) as
begin
-- retrieve information from database based on submission_id (passed in)
-- generate XML
-- send xml to queue
end upload_process;ThanksRooney,
First of all, I would use Oracle package UTL_DBWS to handle web service calls.
But if you choose to do all the work yourself to call web service, this is one of the options:
Since the size of your xml soap request is about 4k, you can just use pl/sql varchar2 variable to construct your xml.
Example:
cSoapRequest VARCHAR2(5000);
BEGIN
cSoapRequest := '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body xmlns:ns1="http://www.ussc.gov/soa/casefile/event/types">
<caseFileUploadEvent xmlns:xsi="http://www.w3XX.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.XXXX.gov/soa/casefile/event/types ../xsd/Case_META.xsd"
xmlns="http://www.XXXX.gov/soa/casefile/event/types">';
FOR recRow IN <your cursor> LOOP
cSoapRequest := cSoapRequest || '<dateOfBirth>'|| TO_CHAR(recRow.DOB,'YYYY-MM-DD HH:MI' )|| '</dateOfBirth>';
END LOOP;
...Then use package utl_http to send the request and recieve response.
Google pl/sql webservice,
Here is one:
Calling Web Service from PL/SQL (ORA-31011: XML parsing failed)
Hope this will give you an idea.
Thomas -
Generating XML using oracle10g (plsql)
Hi,
I have to generate XML using plsql, please somebody help me in this.
Query is as below.
First I need to select few columns COL1,COL2 AND COL3 from table let say TEMP1 on the basis of PK_ID.
this selected columns should be in XML document which I need to return as OUT parameter.
Now on the basis of COL1 fetched in the above query from TEMP table
I need to fetch all the columns COL4,COL5 AND COL6 from its child table let say TEMP2 on the basis of COL1.
Please suggest.SQL> select dbms_xmlgen.getxml('select * from emp where deptno = 10')
2 from dual
3 /
DBMS_XMLGEN.GETXML('SELECT*FROMEMPWHEREDEPTNO=10')
<?xml version="1.0"?>
<ROWSET>
<ROW>
<EMPNO>7782</EMPNO>
<ENAME>CLARK</ENAME>
<JOB>MANAGER</JOB>
<MGR>7839</MGR>
<HIREDATE>09-JUN-81</HIREDATE>
<SAL>2450</SAL>
<DEPTNO>10</DEPTNO>
</ROW>
DBMS_XMLGEN.GETXML('SELECT*FROMEMPWHEREDEPTNO=10')
<ROW>
<EMPNO>7839</EMPNO>
<ENAME>KING</ENAME>
<JOB>PRESIDENT</JOB>
<HIREDATE>17-NOV-81</HIREDATE>
<SAL>5000</SAL>
<DEPTNO>10</DEPTNO>
</ROW>
<ROW>
<EMPNO>7934</EMPNO>
<ENAME>MILLER</ENAME>
DBMS_XMLGEN.GETXML('SELECT*FROMEMPWHEREDEPTNO=10')
<JOB>CLERK</JOB>
<MGR>7782</MGR>
<HIREDATE>23-JAN-82</HIREDATE>
<SAL>1300</SAL>
<DEPTNO>10</DEPTNO>
</ROW>
</ROWSET>
SQL> SY. -
How to generate XML file from SQL file !
I am new to XML publisher. I known one way to generate XML file is register one report file in concurrent manager.
But I want to generate XML file from sql file.
Could someone show me how to code in sql file, how to register is in concurrent manager.
Thanks !Hi
Phew ... not sure we have the space here. So I can point you in the right direction:
1. XML data generation - there are two packages in the db you can use with a plsql procedure, XMLGEN and SQL XML. You can also use java APIs too. Try checking the db documentation and search for the above methods.
2. Registering the report - the system administrators guide will provide this info. Hooking the program up with XMLP is covered here - http://www.oracle.com/technology/products/applications/publishing/resource/CM%20Whitepaper5.0.pdf
Regards, Tim -
How to append the declaration tags to generated xml using Xquery
Hi,
How to append the declaration tags to generated xml using Xquery.generated XML is like
<ROOT>
<CHILD1></CHILD1>
<CHILD2></CHILD2>
</ROOT>
Here I want to append the <?xml version="1.0" encoding="ISO-8859-1"?> and the result xml should be
<?xml version="1.0" encoding="ISO-8859-1"?>
<ROOT>
<CHILD1></CHILD1>
<CHILD2></CHILD2>
</ROOT>
Can anybody help to do this.
Thanks
ManiFirst assign this element to a temp variable
<ROOT>
<CHILD1></CHILD1>
<CHILD2></CHILD2>
</ROOT>
Now in XQuery expression create a new variable
<?xml version="1.0" encoding="ISO-8859-1"?>
$temp -
Hi All,
We have a situation as in where we have to generate a XML out of Oracle UCM. I want to know is there any way where i can generate XML using the reaultset of some query.
Any inputs will be useful..
Thanks.Hi!
In IdocScript, you can work with the resultset and generate XML as you want ....
You could also make your own java component that would generate XML.
Romain. -
Generating XML using Varray or Pl/SQL table
I am trying to convert an old plsql procedure to generate XML data. The program is getting all the data to report from various sources to a pl/sql table.
Is there any way to directly convert data into xml from plsql table ??
Here is the plsql table defination
TYPE Emp_rec IS RECORD ( Batch_name VARCHAR2(240)
,Employee_name VARCHAR2(240)
,Employee_number VARCHAR2(240)
,Element_name VARCHAR2(240)
,Bee_value NUMBER
,Ele_scr_value NUMBER
TYPE emp_data IS TABLE OF Emp_rec
INDEX BY BINARY_INTEGER;
E emp_data;
And i am trying to get xml using following code:
FOR i IN E.FIRST.. E.LAST
LOOP
SELECT
XMLConcat (
XMLELEMENT(
"batch",
XMLFOREST(
E(i).Batch_name AS "Batch_name",
E(i).Employee_number AS "Employee_number",
E(i).Element_name AS "Element_name"
INTO l_xml
FROM dual;
end loop;
I am not sure whether this can actually be done or not. I have option to write the xml file manually to output ; but just wondering whether this method of getting xml is correct or not ? If yes, then how can we use plsql table data and merge it into a single XML file
Please let me know your views and opinions.
Thanks
AnkurI am trying to convert an old plsql procedure to generate XML data. The program is getting all the data to report from various sources to a pl/sql table.
Is there any way to directly convert data into xml from plsql table ??
Here is the plsql table defination
TYPE Emp_rec IS RECORD ( Batch_name VARCHAR2(240)
,Employee_name VARCHAR2(240)
,Employee_number VARCHAR2(240)
,Element_name VARCHAR2(240)
,Bee_value NUMBER
,Ele_scr_value NUMBER
TYPE emp_data IS TABLE OF Emp_rec
INDEX BY BINARY_INTEGER;
E emp_data;
And i am trying to get xml using following code:
FOR i IN E.FIRST.. E.LAST
LOOP
SELECT
XMLConcat (
XMLELEMENT(
"batch",
XMLFOREST(
E(i).Batch_name AS "Batch_name",
E(i).Employee_number AS "Employee_number",
E(i).Element_name AS "Element_name"
INTO l_xml
FROM dual;
end loop;
I am not sure whether this can actually be done or not. I have option to write the xml file manually to output ; but just wondering whether this method of getting xml is correct or not ? If yes, then how can we use plsql table data and merge it into a single XML file
Please let me know your views and opinions.
Thanks
Ankur -
Generate connections.xml using only sql commands
Hello,
I have a database, where all connection information (Hostname, User, Port, SID, etc.) are stored for several databases. Now I want to create the connections.xml which I can import to the SQL Developer. The idea is to administer the connection information in a single point. Then anyone can query and import the connections easily to the SQL Developer.
The structure itself was easy to understand and implement using XMLELEMENT. My Problem is, how can I save the password respectively how is the password encrypted? I have found several tools that can decode the password, but I have the plaintext. I found a solution using Jython, but I want to use only SQL. There should be a suitable algorithm in the dbms_crypto package, I hope. I don´t want to use other tools or languages.
Thanks for help,
Frank
Edited by: frank_nillies on 20.03.2013 04:28
- renamed connection.xml to connections.xmlHello,
I have a database, where all connection information (Hostname, User, Port, SID, etc.) are stored for several databases. Now I want to create the connections.xml which I can import to the SQL Developer. The idea is to administer the connection information in a single point. Then anyone can query and import the connections easily to the SQL Developer.
The structure itself was easy to understand and implement using XMLELEMENT. My Problem is, how can I save the password respectively how is the password encrypted? I have found several tools that can decode the password, but I have the plaintext. I found a solution using Jython, but I want to use only SQL. There should be a suitable algorithm in the dbms_crypto package, I hope. I don´t want to use other tools or languages.
Thanks for help,
Frank
Edited by: frank_nillies on 20.03.2013 04:28
- renamed connection.xml to connections.xml -
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. -
Hi All,
I am trying to use XML for building an application. Is it
possible to generate page by only using a PL-SQL?
I know how to generate XML by using PL-SQL.
--How can I apply XSL document to it?
Thanks,
SamirThe XML Developers kit available on this site at: http://technet.oracle.com/tech/xml/
contains utilities for parsing XML with PL/SQL and other methods. -
Generate XML using package xmlgen
I have the following query:
select employ_id, last_name, first_name, salary from employ;
I need generate xml like this:
<row>
<employ>
<employ_id last_name="Dennis" First_name="david">1</employ>
<salary>6</salary>
</employ>
</row>
How can I get it using xmlgen package? Thanks.
nullNo, you will not be able to do that. The
problem is that the columns of the db table
are mapped to XML elements rather then
attributes. Your best bet at achieving your
goal is that after you get your xml document
from the XSU, you transform it using XSLT.
The Oracle Parser does include the xsl processor.
visar
ps.: Today, when using XSU's java API, you can directly get a DOM tree representation of the XML document, which then you can pass directly to the XSL processor and transform it; unfortunately, the PL/SQL API (i.e. xmlgen) doesn only return a string (i.e. lob) representation of the XML doc. So you have to use the PL/SQL Parser to parse it, get it in the DOM format, and only then can you transform it. The good news is that I was assured that in the future the XMLGEN will have a call to get the XML doc in DOM rep. -
How to generate XML usng java without using following.
import org.apache.xerces.dom.DocumentImpl;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
XML to be generated is as follows.
<?xml version="1.0" encoding="UTF-8"?>
<Modi xmlns:xsi="Modi/Modi1">
<docConfig>
<className>PO</className>
<classDesc>Purchase</classDesc>
<create>Y</create>
</docConfig>
<indexConfig>
<index sequence="1">
<shortName>PODATE</shortName>
<displayName>PO Date</displayName>
<type>date</type>
<length>10</length>
</index>
</indexConfig>
</upload>Two answers.
If you want to not use any of the XML-oriented classes, you can use a PrintWriter. Just code:
PrintWriter pw = new PrinteWriter(whatever);
pw.println( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" );
etc.If you want to use XML-oriented classes, but just not these 3 (can't imagine why), then use
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
instead of XMLSerializer and OutputFormat, and
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
instead of the DocumentImpl
Dave Patterson -
Remove the unnecessary tags in XML using PL/SQL
Hi Friends
from the below XML, its generate by a complex SQL query, Now we need to remove all the object type tags, and all the empty tags.
Version - PL/SQL Release 11.2.0.3.0 - Production
<MajorLine>
<MAJOR_LINE_OBJECT_TYPE> -- Need to remove these Objects types showing in the XML
<LINEID>143424538</LINEID>
<ITEMNAME>TC-ABC-123</ITEMNAME>
<ITEMPATH>78245</ITEMPATH>
<QUANTITY>10</QUANTITY>
<SERVICELINE/> -- Need to remove all the Empty tags
<MINORLINE>
<MINOR_LINE_OBJECT_TYPE> -- Need to remove these Objects types showing in the XML
<LINEID>143424799</LINEID>
<ITEMNAME>TCC-abc</ITEMNAME>
<ITEMPATH>78245</ITEMPATH>
<QUANTITY>10</QUANTITY>
<SERVICELINE/>-- Need to remove all the Empty tags
<MINOR_MINOR_LINES>
<M_MINOR_LINE_TYPE> -- Need to remove these Objects types showing in the XML
<LINEID>143424798</LINEID>
<ITEMNAME>SF15-abc-xyz</ITEMNAME>
<ITEMPATH>78245</ITEMPATH>
<QUANTITY>10</QUANTITY>
</M_MINOR_LINE_TYPE>-- Need to remove these Objects types showing in the XML
</MINOR_MINOR_LINES>
</MINOR_LINE_OBJECT_TYPE>--Need to remove these Objects types showing in the XML
</MINORLINE>
</MAJOR_LINE_OBJECT_TYPE>-- Need to remove these Objects types showing in the XML
</MajorLine>
i tried one of the queries posted in this blog ,PFB to remove the empty tags , but it didnt work for me unfortunately. Please help.
PFB
WITH sample_data AS (
SELECT xmltype('<MajorLine>
<MAJOR_LINE_OBJECT_TYPE>
<LINEID>143424538</LINEID>
<ITEMNAME>hijk</ITEMNAME>
<ITEMPATH>78245</ITEMPATH>
<QUANTITY>10</QUANTITY>
<SERVICELINE/>
<MINORLINE>
<MINOR_LINE_OBJECT_TYPE>
<LINEID>143424799</LINEID>
<ITEMNAME>efg</ITEMNAME>
<ITEMPATH>78245</ITEMPATH>
<QUANTITY>10</QUANTITY>
<SERVICELINE/>
<MINOR_MINOR_LINES>
<M_MINOR_LINE_TYPE>
<LINEID>143424798</LINEID>
<ITEMNAME>abc</ITEMNAME>
<ITEMPATH>78245</ITEMPATH>
<QUANTITY>10</QUANTITY>
</M_MINOR_LINE_TYPE>
</MINOR_MINOR_LINES>
</MINOR_LINE_OBJECT_TYPE>
</MINORLINE>
</MAJOR_LINE_OBJECT_TYPE>
</MajorLine>') xmldoc
FROM dual
SELECT deleteXML( t.xmldoc
, '/MajorLine/*[.="" or contains(.,"?")]'
) as result
FROM sample_data t
My email ID is [email protected] -- You can reach me
thanks in advance ... Arun thomas THey Odie. Great to see you again, the query is
SELECT XMLELEMENT (
"MajorLine",
major_line_object_type (
oola_major.line_id,
oola_major.ordered_item,
oola_major.header_id,
oola_major.ordered_quantity,
CAST (
MULTISET (
SELECT oola_ser.line_id,
oola_ser.ordered_item,
--oola_ser.header_id,
oola_ser.ordered_quantity,
CAST (
MULTISET (
SELECT oola_ser2.service_start_date,
oola_ser2.service_end_date,
oola_ser2.service_duration
FROM oe_order_lines_all oola_ser2
WHERE oola_major.line_id =
oola_ser2.service_reference_line_id
AND oola_ser2.header_id =
oola_major.header_id) AS service_period_table_type)
FROM oe_order_lines_all oola_ser
WHERE oola_major.line_id =
oola_ser.service_reference_line_id
AND oola_ser.header_id = oola_major.header_id) --As of now excluding cross order service line
AS SERVICE_TABLE_TYPE),
CAST (
MULTISET (
SELECT oola_minor.line_id,
oola_minor.ordered_item,
oola_minor.header_id,
oola_minor.ordered_quantity,
CAST (
MULTISET (
SELECT oola_ser1.line_id,
oola_ser1.ordered_item,
-- oola_ser1.header_id,
oola_ser1.ordered_quantity,
CAST (
MULTISET (
SELECT oola_ser3.
service_start_date,
oola_ser3.
service_end_date,
oola_ser3.
service_duration
FROM oe_order_lines_all oola_ser3
WHERE oola_minor.line_id =
oola_ser3.
service_reference_line_id
AND oola_ser3.header_id =
oola_major.
header_id) AS service_period_table_type)
FROM oe_order_lines_all oola_ser1
WHERE oola_minor.line_id =
oola_ser1.service_reference_line_id
AND oola_ser1.header_id =
oola_major.header_id) --As of now excluding cross order service line
AS SERVICE_TABLE_TYPE),
CAST (
MULTISET (
SELECT oola_minor_m.line_id,
oola_minor_m.ordered_item,
oola_minor_m.header_id,
oola_minor_m.ordered_quantity
FROM oe_order_lines_all oola_minor_m
WHERE oola_minor.line_id =
oola_minor_m.link_to_line_id
AND oola_minor_m.header_id =
oola_major.header_id) --As of now excluding cross order service line
AS m_minor_line_table_type)
FROM oe_order_lines_all oola_minor
WHERE --oola_minor.top_model_line_id=oola_major.line_id
oola_minor.link_to_line_id = oola_major.line_id
AND oola_minor.header_id = oola_major.header_id
AND oola_minor.item_type_code != 'SERVICE') AS MINOR_LINE_TABLE_TYPE)))
AS "XMLOutput"
FROM oe_order_lines_all oola_major
WHERE oola_major.line_id = 143424538 AND oola_major.link_to_line_id IS NULL;
can we rewirte it to get the desired out put ..
Desired output is Just remove the Object_type tags and empty tags coming in the output xml.
The previous issues i mentioned are not solved yet . actually will update the challenges ..
Odie .. thanks.. again -
Generate xml using FOR XML PATH from table with hierarchy
I need to create xml from a table like:
EL1 EL2 EL3 Attr01 Attr02 Attr03 Attr04
E10, , ,a,b,c,d
E10,E1010, ,a,b,c,d
E10,E1010,E101010,a,b,c,d
E10,E1010,E101020,a,b,c,d
E10,E1010,E101030,a,b,c,d
E10,E1020, ,a,b,c,d
E10,E1020,E102010,a,b,c,d
E20, , ,a,b,c,d
E20,E2010, ,a,b,c,d
E20,E2010,E201010,a,b,c,d
E20,E2020, ,a,b,c,d
E20,E2020,E202010,a,b,c,d
E20,E2020,E202020,a,b,c,d
The hierarchy is EL1--EL2--EL3, and the 3 columns should be elements of xml;
The other for columns Attr01,Attr02,Attr03,Attr04 should be attributes of xml;
The actual table could have more than 500 rows(there are many values for El1,EL2,and EL3).
The expected xml should like:
<root>
<E10 Attr01="a" Attr02="b" Attr03="c" Attr04="d">
<E1010 Attr01="a" Attr02="b" Attr03="c" Attr04="d">
<E101010 Attr01="a" Attr02="b" Attr03="c" Attr04="d" />
<E101020 Attr01="a" Attr02="b" Attr03="c" Attr04="d" />
<E101030 Attr01="a" Attr02="b" Attr03="c" Attr04="d" />
</E1010>
<E1020 Attr01="a" Attr02="b" Attr03="c" Attr04="d">
<E102010 Attr01="a" Attr02="b" Attr03="c" Attr04="d" />
</E1020>
</E10>
<E20 Attr01="a" Attr02="b" Attr03="c" Attr04="d">
<E2010 Attr01="a" Attr02="b" Attr03="c" Attr04="d">
<E201010 Attr01="a" Attr02="b" Attr03="c" Attr04="d" />
</E2010>
<E2020 Attr01="a" Attr02="b" Attr03="c" Attr04="d">
<E202010 Attr01="a" Attr02="b" Attr03="c" Attr04="d" />
<E202020 Attr01="a" Attr02="b" Attr03="c" Attr04="d" />
</E2020>
</E20>
</root>
I create a sample Src table:
CREATE TABLE Src
EL1 VARCHAR(10),
EL2 VARCHAR(10),
EL3 VARCHAR(10),
Attr01 VARCHAR(10),
Attr02 VARCHAR(10),
Attr03 VARCHAR(10),
Attr04 VARCHAR(10)
GO
INSERT INTO Src
(EL1,EL2,EL3,Attr01,Attr02,Attr03,Attr04
SELECT 'E10','','','a','b','c','d'
UNION SELECT 'E10','E1010','','a','b','c','d'
UNION SELECT 'E10','E1010','E101010','a','b','c','d'
UNION SELECT 'E10','E1010','E101020','a','b','c','d'
UNION SELECT 'E10','E1010','E101030','a','b','c','d'
UNION SELECT 'E10','E1020','','a','b','c','d'
UNION SELECT 'E10','E1020','E102010','a','b','c','d'
UNION SELECT 'E20','','','a','b','c','d'
UNION SELECT 'E20','E2010','','a','b','c','d'
UNION SELECT 'E20','E2010','E201010','a','b','c','d'
UNION SELECT 'E20','E2020','','a','b','c','d'
UNION SELECT 'E20','E2020','E202010','a','b','c','d'
UNION SELECT 'E20','E2020','E202020','a','b','c','d'
GO
I tried to use FOR XML PATH to generate xml for the sample data. When the records increase to a few hundreds, it's not a good idea.
Here is my script:
SELECT
(SELECT Attr01 AS '@Attr01'
,Attr02 AS '@Attr02'
,Attr03 AS '@Attr03'
,Attr04 AS '@Attr04'
,( SELECT
Attr01 AS '@Attr01'
,Attr02 AS '@Attr02'
,Attr03 AS '@Attr03'
,Attr04 AS '@Attr04'
,( SELECT
Attr01 AS '@Attr01'
,Attr02 AS '@Attr02'
,Attr03 AS '@Attr03'
,Attr04 AS '@Attr04'
FROM Src
WHERE EL3 = 'E101010'
FOR XML PATH('E101010'),TYPE
) AS 'node()'
,( SELECT
Attr01 AS '@Attr01'
,Attr02 AS '@Attr02'
,Attr03 AS '@Attr03'
,Attr04 AS '@Attr04'
FROM Src
WHERE EL3 = 'E101020'
FOR XML PATH('E101020'),TYPE
) AS 'node()'
,( SELECT
Attr01 AS '@Attr01'
,Attr02 AS '@Attr02'
,Attr03 AS '@Attr03'
,Attr04 AS '@Attr04'
FROM Src
WHERE EL3 = 'E101030'
FOR XML PATH('E101030'),TYPE
) AS 'node()'
FROM Src
WHERE EL2 = 'E1010' AND (EL1 <>'' AND EL3 ='')
FOR XML PATH('E1010'),TYPE
) AS 'node()'--1010
,( SELECT
Attr01 AS '@Attr01'
,Attr02 AS '@Attr02'
,Attr03 AS '@Attr03'
,Attr04 AS '@Attr04'
,( SELECT
Attr01 AS '@Attr01'
,Attr02 AS '@Attr02'
,Attr03 AS '@Attr03'
,Attr04 AS '@Attr04'
FROM Src
WHERE EL3 = 'E102010'
FOR XML PATH('E102010'),TYPE
) AS 'node()'
FROM Src
WHERE EL2 = 'E1020' AND (EL1 <>'' AND EL3 ='')
FOR XML PATH('E1020'),TYPE
) AS 'node()'--1020
FROM Src
WHERE EL1 = 'E10' AND (EL2 ='' AND EL3 ='')
FOR XML PATH('E10'),TYPE) 'node()'
,(SELECT Attr01 AS '@Attr01'
,Attr02 AS '@Attr02'
,Attr03 AS '@Attr03'
,Attr04 AS '@Attr04'
,( SELECT
Attr01 AS '@Attr01'
,Attr02 AS '@Attr02'
,Attr03 AS '@Attr03'
,Attr04 AS '@Attr04'
,( SELECT
Attr01 AS '@Attr01'
,Attr02 AS '@Attr02'
,Attr03 AS '@Attr03'
,Attr04 AS '@Attr04'
FROM Src
WHERE EL3 = 'E201010'
FOR XML PATH('E201010'),TYPE
) AS 'node()'
FROM Src
WHERE EL2 = 'E2010' AND (EL1 <>'' AND EL3 ='')
FOR XML PATH('E2010'),TYPE
) AS 'node()'--2010
,( SELECT
Attr01 AS '@Attr01'
,Attr02 AS '@Attr02'
,Attr03 AS '@Attr03'
,Attr04 AS '@Attr04'
,( SELECT
Attr01 AS '@Attr01'
,Attr02 AS '@Attr02'
,Attr03 AS '@Attr03'
,Attr04 AS '@Attr04'
FROM Src
WHERE EL3 = 'E202010'
FOR XML PATH('E202010'),TYPE
) AS 'node()'
,( SELECT
Attr01 AS '@Attr01'
,Attr02 AS '@Attr02'
,Attr03 AS '@Attr03'
,Attr04 AS '@Attr04'
FROM Src
WHERE EL3 = 'E202020'
FOR XML PATH('E202020'),TYPE
) AS 'node()'
FROM Src
WHERE EL2 = 'E2020' AND (EL1 <>'' AND EL3 ='')
FOR XML PATH('E2020'),TYPE
FROM Src
WHERE EL1 = 'E20' AND (EL2 ='' AND EL3 ='')
FOR XML PATH('E20'),TYPE) AS 'node()'
FOR XML PATH(''),ROOT('root')
If I get a few hundreds of rows, how huge the script should be. Does anyone have better solution for this? Thanks.
TaowBob,
Thanks! And sorry for late feedback.
The XSD requires the xml structures like the following
<Schools>
<School01>Some school</School01>
<School02>Some other school</School02>
</Schools>
I have to use the number in the element name.
Right now I just use the nested FOR XML PATH, although I have to write thousand lines code.
Thanks anyway.
Tao
Tao
Maybe you are looking for
-
Camera settings & FCE settings
I shoot with a Canon XHA1 I am trying to determine the most compatible settings between the camera and FCE for creating the highest quality DVD. The camera setting options are: Frame rates of 60i, 30F, 24F; comp out of 480i or 1080i/480i. My other ca
-
Cannot open step in workflow due to constructor class exception
Dear experts, We are creating custom workflow using ABAP class. In the constructor method, we want to raise exception, for example if the approver doesn't exist. However, after putting the code, when we go to workflow definition in pftc and go into t
-
Live Stream Stuttering (Bet365 etc)
Hi, I've noticed when I watch certain live streams they stutter badly and are unwatchable as a result. It happens on both my PC and laptop so it's not an issue with flash player etc. I also tried the same streams at a friend's who is with Sky and the
-
Getting an error message when trying to download Adobe - HELP
Have tried uninstalling - but that does not work either. How can you help me? Caryn
-
Alternative Ports for Firewall
The hotel I'm staying at has the port blocked. Are there alternative ports anyone would recommend??? Thank you!!!!