Inserting parent /child records from a xml file ...
XML file pasted below:
I have loaded the xml file into a table called xml_demo which has a column xml_data of type xmltype.
The select for parent record is as follows and it works:
INSERT INTO balit_submissions (balitdoc, documentversion, datetime_from,job_id, status,creation_datetime)
(SELECT 'MOL'
,to_number(extract(x.xml_data,'/MolDocument/DocumentVersion/@v'))
,to_date(substr(extract(x.xml_data,'/MolDocument/ValidTimeInterval/@v'),1,16),
'yyyy-mm-dd"T"hh24:mi')
,123456
,'CREATED',
NULL
FROM xml_DEMO x WHERE
existsnode(x.xml_data,'/MolDocument/DocumentIdentification[@v="MOL_20100331_1500_1600"]') = 1)
Having problem creating child records. From this file I expect to create 3 records.
insert into balit_energy_blocks
SO_ID,
DATETIME_FROM,
DIRECTION,
BLOCK_NUMBER,
ENERGY,
LAST_SUBMIT_DATETIME,
PRICE_POUNDS,
PRICE_EUROS,
BALIT_REF,
STATUS,
LAST_EDIT_DATETIME,
MOL_REASON,
ACQUIRING_SO_AREA)
(SELECT 'RTE'
,to_date(substr(extract(x.xml_data,'/MolDocument/ValidTimeInterval/@v'),1,16),
'yyyy-mm-dd"T"hh24:mi')
,DECODE(extract(x.xml_data,'/MolDocument/MolTimeSeries/Direction/@v'),'AO1','Up','Down')
,to_number(substr(extract(x.xml_data,'/MolDocument/MolTimeSeries/ContractIdentification/@v'),19))
,to_number(extract(x.xml_data,'/MolDocument/MolTimeSeries/Period/Interval/EnergyPrice/@v'))
,sysdate
,null -- price pounds
,null -- price euro
,extract(x.xml_data,'/MolDocument/MolTimeSeries/ContractIdentification/@v')
,'SUBMITTED'
,'A96'
,NULL -- acquiring area
,sysdate
FROM xml_DEMO x WHERE
existsnode(x.xml_data,'/MolDocument/DocumentIdentification[@v="MOL_20100331_1500_1600"]') = 1)
For example, there are 3 ContractIdentification tags. Example of 1:
<ContractIdentification v="RTE_20100331_1500_16"/>
I was expecting this select to pluck the last number from this string. In this case 16.
The select was:
to_number(substr(extract(x.xml_data,'/MolDocument/MolTimeSeries/ContractIdentification/@v'),19))
The result I got was:
16RTE_20100331_1500_20NG_20100331_1500_6
All contractident values are concatnated and returns from position 19 onwards.
Can anyone help me to extract the last number from each ContractIdentification tag value and to create the 3 records
Thanks
James Sathiaraj
<?xml version="1.0" encoding="UTF-8"?>
<MolDocument DtdVersion="3" DtdRelease="0">
<DocumentIdentification v="MOL_20100331_1500_1600"/>
<DocumentVersion v="1"/>
<DocumentType v="A43"/>
<SenderIdentification codingScheme="A01" v="17X100Z100Z0001H"/>
<SenderRole v="A35"/>
<ReceiverIdentification codingScheme="A01" v="10XFR-RTE------Q"/>
<ReceiverRole v="A04"/>
<CreationDateTime v="2010-03-31T14:10:00Z"/>
<ValidTimeInterval v="2010-03-31T15:00Z/2010-03-31T16:00Z"/>
<Domain codingScheme="A01" v="10YDOM-1001A001A"/>
<MolTimeSeries>
<ContractIdentification v="RTE_20100331_1500_16"/>
<ResourceProvider codingScheme="A01" v="10XFR-RTE------Q"/>
<AcquiringArea codingScheme="A01" v="17Y100Z100Z00013"/>
<ConnectingArea codingScheme="A01" v="10YFR-RTE------C"/>
<AuctionIdentification v="AUCTION_20100331_1500_1600"/>
<BusinessType v="A10"/>
<BidTimeInterval v="2010-03-31T15:00Z/2010-03-31T16:00Z"/>
<MeasureUnitQuantity v="MAW"/>
<Currency v="EUR"/>
<MeasureUnitPrice v="MWH"/>
<Direction v="A02"/>
<MinimumActivationQuantity v="50"/>
<Status v="A06"/>
<Period>
<TimeInterval v="2010-03-31T15:00Z/2010-03-31T16:00Z"/>
<Resolution v="PT60M"/>
<Interval>
<Pos v="1"/>
<Qty v="50"/>
<EnergyPrice v="50.45"/>
</Interval>
</Period>
</MolTimeSeries>
<MolTimeSeries>
<ContractIdentification v="RTE_20100331_1500_20"/>
<ResourceProvider codingScheme="A01" v="10XFR-RTE------Q"/>
<AcquiringArea codingScheme="A01" v="17Y100Z100Z00013"/>
<ConnectingArea codingScheme="A01" v="10YFR-RTE------C"/>
<AuctionIdentification v="AUCTION_20100331_1500_1600"/>
<BusinessType v="A10"/>
<BidTimeInterval v="2010-03-31T15:00Z/2010-03-31T16:00Z"/>
<MeasureUnitQuantity v="MAW"/>
<Currency v="EUR"/>
<MeasureUnitPrice v="MWH"/>
<Direction v="A02"/>
<MinimumActivationQuantity v="50"/>
<Status v="A06"/>
<Period>
<TimeInterval v="2010-03-31T15:00Z/2010-03-31T16:00Z"/>
<Resolution v="PT60M"/>
<Interval>
<Pos v="1"/>
<Qty v="50"/>
<EnergyPrice v="50.48"/>
</Interval>
</Period>
</MolTimeSeries>
<MolTimeSeries>
<ContractIdentification v="NG_20100331_1500_6"/>
<ResourceProvider codingScheme="A01" v="10X1001A1001A515"/>
<AcquiringArea codingScheme="A01" v="17Y100Z100Z00013"/>
<ConnectingArea codingScheme="A01" v="10YGB----------A"/>
<AuctionIdentification v="AUCTION_20100331_1500_1600"/>
<BusinessType v="A10"/>
<BidTimeInterval v="2010-03-31T15:00Z/2010-03-31T16:00Z"/>
<MeasureUnitQuantity v="MAW"/>
<Currency v="EUR"/>
<MeasureUnitPrice v="MWH"/>
<Direction v="A01"/>
<MinimumActivationQuantity v="50"/>
<Status v="A06"/>
<Period>
<TimeInterval v="2010-03-31T15:00Z/2010-03-31T16:00Z"/>
<Resolution v="PT60M"/>
<Interval>
<Pos v="1"/>
<Qty v="50"/>
<EnergyPrice v="17.0"/>
</Interval>
</Period>
</MolTimeSeries>
</MolDocument>
Hi,
The result I got was:
16RTE_20100331_1500_20NG_20100331_1500_6In the query you tried, you access a single record so you can't expect to get three rows "magically". The EXTRACT function just works as expected, it extracts the requested nodes, but the result is still an XML fragment (a scalar value).
In order to achieve your goal, you have to break the MolTimeSeries sequence into relational rows.
Two similar solutions are possible, XMLTable (10gR2 and up) or Table/XMLSequence.
In your other post you mentioned db version 10.1, so I guess we'll go with XMLSequence :
SELECT 'RTE'
,to_date(substr(extractvalue(x.xml_data,'/MolDocument/ValidTimeInterval/@v'),1,16),'yyyy-mm-dd"T"hh24:mi')
,decode(extractvalue(x2.column_value,'/MolTimeSeries/Direction/@v'),'A01','Up','Down')
,to_number(regexp_substr(extractvalue(x2.column_value,'/MolTimeSeries/ContractIdentification/@v'),'\d+$'))
,to_number(extractvalue(x2.column_value,'/MolTimeSeries/Period/Interval/EnergyPrice/@v'))
,sysdate
,null
,null
,extractvalue(x2.column_value,'/MolTimeSeries/ContractIdentification/@v')
,'SUBMITTED'
,'A96'
,null
,sysdate
FROM xml_demo x,
table(
xmlsequence(
extract(x.xml_data, '/MolDocument/MolTimeSeries')
) x2
WHERE existsnode(x.xml_data,'/MolDocument/DocumentIdentification[@v="MOL_20100331_1500_1600"]') = 1;Please also note the use of REGEXP_SUBSTR instead of the regular SUBSTR because it didn't work for "NG_20100331_1500_6".
Hope that helps.
Edited by: odie_63 on 24 juin 2010 21:18 - added regexp comment
Similar Messages
-
Parent/child records from same table
I want to create a query that is a union such that the 2nd resultset is based on the 1st resultset. I have a table that has parent/child records in the same table.
Table: EVENTS
EVENT_ID
PARENT_EVENT_ID
CREATED_DATE
(other columns)
if PARENT_EVENT_ID is null then it is a parent record, else it is a child record. I want to select all parent records then union them with all the associated child records...something like this:
select * from EVENTS where CREATED_DATE < sysdate - 90 and PARENT_EVENT_ID is null -- All parents
union
select * from EVENTS where PARENT_EVENT_ID in (select EVENT_ID from EVENTS where CREATED_DATE < sysdate - 90 and PARENT_EVENT_ID is null) -- include any children of parents selected from above
This works but it's kind of ugly, I want to avoid using the sub-select in the 2nd because it is a repeat of the 1st statement, is there a way to alias the first statement and just refer to it in the 2nd query?Hi,
kev374 wrote:
Thanks, one question...
I did a test and it seems the child rows have to also satisfy the parent row's where clause, take this example:
EVENT_ID|PARENT_EVENT_ID|CREATED_DATE
2438 | (null) | April 9 2013
2439 | 2438 | April 11 2013
2440 | 2438 | April 11 2013
select * from EVENTS where CREATED_DATE < sysdate - 9
start with EVENT_ID = 2438
connect by PARENT_EVENT_ID = prior EVENT_IDSo you've changed the condition about only wanting roots and their children, and now you want descendants at all levels.
This pulls in record #2438 (per the sysdate - 9 condition) but 2439 and 2440 are not connected. Is there a way to supress the where clause evaluation for the child records? I just want to pull ALL child records associated with the parent and only want to do the date check on the parent.Since the roots (the only rows you want to exclude) have LEVEL=1, you can get the results you requested like this:
WHERE created_date < SYSDATE - 9
OR LEVEL > 1However, since you're not ruling out the grandchildren and great-grandchildren any more, why wouldn't you just say:
SELECT *
FROM events
WHERE created_date < SYSDATE - 9
OR parent_event_id IS NOT NULL;?
CONNECT BY is slow. Don't use it if you don't need it.
If you x-reference my original query:
select * from EVENTS where CREATED_DATE < sysdate - 90 and PARENT_EVENT_ID is null -- All parents
union
select * from EVENTS where PARENT_EVENT_ID in (select EVENT_ID from EVENTS where CREATED_DATE < sysdate - 90 and PARENT_EVENT_ID is null) -- include any children of parents selected from above
The 2nd select does not apply the created_date < sysdate - 90 on the children but rather pulls in all related children :)Sorry; my mistake. That's what happens when you don't post sample data, and desired results; people can't test their solutions and find mistakes like that. -
Need to insert values into a table from a XML file
Hi,
I'm an Oracle 9i/10g DBA with quite a few years experience, but I'm new to XML and dealing with it in database terms. I've been given a project that entails pulling XML values out of a file (or 100's of them) and storing them in the database so that they are searchable by end-users. The project is classified as secret so I'm unable to upload the specific XML or any info relating to the structire of the XML or the table I will use to insert the values into - sorry!! So, I've created an XML file with a similar structure to help people understand my predicament.
The end-users only need to search on a subset of the total amount of columns from the table I'll insert data into, although the XML file has a lot more, so I dont need to store the other values - but I will need to store the name of the XML file (or a pointer to it so I know what XML file a particular set of values belong to) in another column of the table along with its associated values.
I've been using the XMLTABLE function with some degree of success, although I had better succes using the XMLSEQUENCE function. However, I found out this is deprecated in 10g and replaced with XMLTABLE, so I guess it's better if I use this in case we ever need to upgrade to 11g.
The main problem I've been having is that some elements in the XML files have multiple values for the one record when all the other records are the same. In terms of storing this in the database, I guess it would mean inserting multiple rows in the table for each element where the value differs. Here is a dumbed down XML file similar to what I've got along with the other SQL I've used:
+<?xml version="1.0" encoding="UTF-8"?>+
+<House>+
+<Warehouse>+
+<WarehouseId>1</WarehouseId>+
+<WarehouseName>+
+<Town>Southlake</Town>+
+<State>Texas</State>+
+</WarehouseName>+
+<Building>Owned</Building>+
+<Area>25000</Area>+
+<Docks>2</Docks>+
+<DockType>Rear load</DockType>+
+<WaterAccess>true</WaterAccess>+
+<RailAccess>N</RailAccess>+
+<Parking>Street</Parking>+
+<VClearance>10</VClearance>+
+</Warehouse>+
+<Warehouse>+
+<WarehouseId>2</WarehouseId>+
+<WarehouseName>+
+<Town>Poole</Town>+
+<State>Dorset</State>+
+</WarehouseName>+
+<WarehouseName>+
+<Town>Solihull</Town>+
+<County>West Midlands</State>+
+</WarehouseName>+
+<Building>Owned</Building>+
+<Area>40000</Area>+
+<Docks>5</Docks>+
+<DockType>Rear load</DockType>+
+<WaterAccess>true</WaterAccess>+
+<RailAccess>N</RailAccess>+
+<Parking>Bay</Parking>+
+<VClearance>10</VClearance>+
+</Warehouse>+
+<Warehouse>+
+<WarehouseId>3</WarehouseId>+
+<WarehouseName>+
+<Town>Fleet</Town>+
+<County>Hampshire</County>+
+</WarehouseName>+
+<Building>Owned</Building>+
+<Area>10000</Area>+
+<Docks>1</Docks>+
+<DockType>Side load</DockType>+
+<WaterAccess>false</WaterAccess>+
+<RailAccess>N</RailAccess>+
+<Parking>Bay</Parking>+
+<VClearance>20</VClearance>+
+</Warehouse>+
+</House>+
CREATE TABLE xmltest OF XMLTYPE;
INSERT INTO xmltest
VALUES(xmltype(bfilename('XML_DIR', 'test.xml'), nls_charset_id('AL32UTF8')));
Consequently, I need to...
1) Retrieve the results from the XML file for all 3 warehouses where multiple values for the same sub-element are shown as 2 rowsthe result set. (I am guessing there will be 4 rows returned as warehouse sub-2 has 2 different elements for <WarehouseName>.
2) Build a case statement into the query so that regardless of the sub-element name (i.e State or County), it is returned into the 1 column, for instance County.
So, if I run a query similar to the following...
select y.WarehouseId, y.Town, y.County, y.Area
from xmltest x, xmltable('/House/Warehouse' .......
I would like to get results back like this...
ID Town County Area
1 Southlake Texas 25000
2 Poole Dorset 40000
2 Solihull West Midlands 40000
3 Fleet hampshire 10000
Sorry for the non-formatting but I hope this all makessense to someone out there with what I'm trying to do.
I appreciate any help whatsoever because, as i said before, I'm totally new to XML and trying to read the vast amount of information there is out there on XML is all a bit daunting.
Many thanks in advance,
Shaun.Hi again,
Thanks for keeping the post open for me. I've had a look at the post illustrating the XFileHandler package, and tried to alter it to make it fit with my XML files. To help explain things, my XML file looks like this:
<?xml version="1.0"?>
<!DOCTYPE CMF_Doc SYSTEM "CMF_Doc.dtd">
<House>
<Warehouse>
<WarehouseId>1</WarehouseId>
<WarehouseName>
<Town>Southlake</Town>
<State>Texas</State>
</WarehouseName>
<Building>Owned</Building>
<Area>25000</Area>
<Docks>2</Docks>
<DockType>Rear load</DockType>
<WaterAccess>true</WaterAccess>
<RailAccess>N</RailAccess>
<Parking>Street</Parking>
<VClearance>10</VClearance>
</Warehouse>
<Warehouse>House
<WarehouseId>2</WarehouseId>
<WarehouseName>
<Town>Poole</Town>
<State>Dorset</State>
</WarehouseName>
<WarehouseName>
<Town>Solihull</Town>
<County>West Midlands</County>
</WarehouseName>
<Building>Owned</Building>
<Area>40000</Area>
<Docks>5</Docks>
<DockType>Rear load</DockType>
<WaterAccess>true</WaterAccess>
<RailAccess>N</RailAccess>
<Parking>Bay</Parking>
<VClearance>10</VClearance>
</Warehouse>
<Warehouse>
<WarehouseId>3</WarehouseId>
<WarehouseName>
<Town>Fleet</Town>
<County>Hampshire</County>
</WarehouseName>
<Building>Owned</Building>
<Area>10000</Area>
<Docks>1</Docks>
<DockType>Side load</DockType>
<WaterAccess>false</WaterAccess>
<RailAccess>N</RailAccess>
<Parking>Bay</Parking>
<VClearance>20</VClearance>
</Warehouse>
</House>
<?xml version="1.0" encoding="UTF-8"?>
<House>
<Warehouse>
<WarehouseId>4</WarehouseId>
<WarehouseName>
<Town>Dallas</Town>
<State>Texas</State>
</WarehouseName>
<Building>Owned</Building>
<Area>25000</Area>
<Docks>2</Docks>
<DockType>Rear load</DockType>
<WaterAccess>true</WaterAccess>
<RailAccess>N</RailAccess>
<Parking>Street</Parking>
<VClearance>10</VClearance>
</Warehouse>
<Warehouse>
<WarehouseId>5</WarehouseId>
<WarehouseName>
<Town>Dorchester</Town>
<State>Dorset</State>
</WarehouseName>
<WarehouseName>
<Town>Solihull</Town>
<County>West Midlands</County>
</WarehouseName>
<Building>Owned</Building>
<Area>40000</Area>
<Docks>5</Docks>
<DockType>Rear load</DockType>
<WaterAccess>true</WaterAccess>
<RailAccess>N</RailAccess>
<Parking>Bay</Parking>
<VClearance>10</VClearance>
</Warehouse>
<Warehouse>
<WarehouseId>6</WarehouseId>
<WarehouseName>
<Town>Farnborough</Town>
<County>Hampshire</County>
</WarehouseName>
<Building>Owned</Building>
<Area>10000</Area>
<Docks>1</Docks>
<DockType>Side load</DockType>
<WaterAccess>false</WaterAccess>
<RailAccess>N</RailAccess>
<Parking>Bay</Parking>
<VClearance>20</VClearance>
</Warehouse>
</House>
<?xml version="1.0" encoding="UTF-8"?>
<House>
<Warehouse>
<WarehouseId>7</WarehouseId>
<WarehouseName>
<Town>Southlake</Town>
<State>Texas</State>
</WarehouseName>
<Building>Owned</Building>
<Area>25000</Area>
<Docks>2</Docks>
<DockType>Rear load</DockType>
<WaterAccess>true</WaterAccess>
<RailAccess>N</RailAccess>
<Parking>Street</Parking>
<VClearance>10</VClearance>
</Warehouse>
<Warehouse>
<WarehouseId>8</WarehouseId>
<WarehouseName>
<Town>Bournemouth</Town>
<State>Dorset</State>
</WarehouseName>
<WarehouseName>
<Town>Shirley</Town>
<County>West Midlands</County>
</WarehouseName>
<Building>Owned</Building>
<Area>30000</Area>
<Docks>5</Docks>
<DockType>Rear load</DockType>
<WaterAccess>true</WaterAccess>
<RailAccess>N</RailAccess>
<Parking>Bay</Parking>
<VClearance>10</VClearance>
</Warehouse>
<Warehouse>
<WarehouseId>9</WarehouseId>
<WarehouseName>
<Town>Clapham</Town>
<County>London</County>
</WarehouseName>
<Building>Owned</Building>
<Area>10000</Area>
<Docks>1</Docks>
<DockType>Side load</DockType>
<WaterAccess>false</WaterAccess>
<RailAccess>N</RailAccess>
<Parking>Bay</Parking>
<VClearance>20</VClearance>
</Warehouse>
</House>And the XFilehandler package looks like this (I'm just trying to do a simple select only on WarehouseId & WaterAccess for the time being to keep things simple):
create or replace package XFileHandler as
TYPE TRECORD IS RECORD (
WID NUMBER(2)
, WACCESS VARCHAR2(5)
type TRecordTable is table of TRecord;
function getRows (p_directory in varchar2, p_filename in varchar2) return TRecordTable pipelined;
end;
create or replace package body XFileHandler is
function getRows (p_directory in varchar2, p_filename in varchar2)
return TRecordTable pipelined
is
nb_rec number := 1;
tmp_xml clob;
tmp_file clob;
rec TRecord;
begin
DBMS_LOB.CREATETEMPORARY(TMP_FILE, TRUE);
tmp_file := dbms_xslprocessor.read2clob(p_directory, p_filename);
LOOP
tmp_xml := regexp_substr(tmp_file, '<\?xml[^?]+\?>\s*<([^>]+)>.*?</\1>', 1, nb_rec, 'n');
exit when length(tmp_xml) = 0;
--dbms_output.put_line(tmp_rec);
nb_rec := nb_rec + 1;
select y.WID, y.WACCESS
into rec.WID, rec.WACCESS
from xmltable('/House' passing xmltype(tmp_xml)
columns WID NUMBER(2) PATH 'Warehouse/WarehouseId',
WACCESS VARCHAR2(5) PATH 'WaterAccess') y;
pipe row ( rec );
end loop;
dbms_lob.freetemporary(tmp_file);
return;
end;
end;Now, when I run the query:
select * from table(XFileHandler.getRows('XML_DIR', 'XFileHandler_test.xml'));I get the error: ORA-00600: internal error code, arguments: [17285], [0x5CFE8DC8], [4], [0x45ABE1C8], [], [], [], []
I had a look in the dump file for anything obvious, but nothing really stands out. Is there anything obvious in my code that I'm missing or something else which you may think could be causing this error, e.g in the regular expression regexp_substr?
Many thanks,
Shaun. -
How to populate a form from an xml file with multiple records
I want to be able to create a single form that will add pages as needed based upon the number of records being imported from an xml file.
I have an IRS form that does this exactly, but I do not know how to re-create it. I entered data into the form, then exported that data to xml. Then I opened that xml file in excel and added more records (this is just an easy way to manage the xml data in a tabular form). Then I import the changed xml file into the IRS form and it adds as many pages as I have records. Perfect! Unfortunately, I cannot edit the form to examine the technique. It does not appear to be relying upon any additional local javascript files. It does use an 'add page' button which may suggest the form is using the template .spawn() technique, but when I try that in my own form, it gives me unique field names for each page which are then not consistent with the xml data. Hopefully someone can help me understand what I am missing.did you want
<record>0
<data>"11.97.23.174/32"
<record>address <data>
<record>address <data>
<record>subnet <data>
<record>ip <data>"10.97.23.174"</data></record>
</data></record>
</data></record>
</data></record>
</data></record>
or
<record>0
<data>"11.97.23.174/32"
<record>address <data>
<record>address <data>
<record>subnet <data>
<record>ip <data>"10.97.23.174"</data></record> -
Hello
I am trying to mimic the FOR XML EXPLICIT behavior of SQL Server code in Oracle 11g.
The XML EXPILICT mode transforms the rowset that results from the query execution into an XML document and it preserves the parent child relationship in the XML output. For example
SELECT customer.id,customer.name,order.id,order.date,orderdetail.id,orderdetail.pid
FROM CUSTOMER,ORDER,ORDERDETAIL
WHERE CUSTOMER.ORDERID=ORDER.ORDERID
AND
ORDER.ORDERID=ORDERDETAIL.ORDERID
<Customer ID="C1" name="Ann">
<Order id="O1" date="1/20/2008">
<OrderDetail id="OD1" pid="P1"/>
<OrderDetail id="OD2" pid="P2"/>
</Order>
<Order id="O2" date="3/29/1997">
</Customer>
<Customer ID="C2" name="Jack">
<Order id="O1" date="1/20/2009">
<OrderDetail id="OF1" pid="P1"/>
<OrderDetail id="OF2" pid="P2"/>
</Order>
<Order id="O2" date="3/29/1997">
<OrderDetail id="OX1" pid="D1"/>
<OrderDetail id="OX2" pid="D2"/>
</Order>
</Customer>
Appreciate if you can help me to write an Oracle equivalent of this code.
Thanks & RegardsYou can use xmlelement and xmlagg functions this way:
SQL> with customer as (
2 select 'C1' id, 'Ann' name from dual union
3 select 'C2' id, 'Jack' name from dual),
4 Orders as (
5 Select 'O1' id, '1/20/2008' odate, 'C1' custid from dual union
6 Select 'O2' id, '3/29/1997' odate, 'C1' custid from dual union
7 Select 'O3' id, '1/20/2008' odate, 'C2' custid from dual union
8 Select 'O4' id, '3/29/1997' odate, 'C2' custid from dual),
9 orderdetail as (
10 select 'OD1' id, 'P1' pid, 'O1' orderid from dual union
11 select 'OD2' id, 'P2' pid, 'O1' orderid from dual union
12 select 'OF1' id, 'P1' pid, 'O3' orderid from dual union
13 select 'OF2' id, 'P2' pid, 'O3' orderid from dual union
14 select 'OX1' id, 'D1' pid, 'O4' orderid from dual union
15 select 'OX2' id, 'D2' pid, 'O4' orderid from dual
16 )
17 -- End of test data, actual query follows
18 SELECT xmlagg(
19 xmlelement("Customer",
20 xmlattributes(id, name),
21 (select xmlagg(
22 xmlelement("Order",
23 xmlattributes(o.id, o.odate as "date"),
24 (select xmlagg(
25 xmlelement("OrderDetail",
26 xmlattributes(id,pid),
27 null
28 )
29 )
30 from orderdetail d
31 where d.orderid = o.id
32 )
33 )
34 )
35 from orders o
36 where CUSTOMER.ID=O.CUSTID
37 )
38 )
39 ).extract('/*') xml
40 from customer;
XML
<Customer ID="C1" NAME="Ann">
<Order ID="O1" date="1/20/2008">
<OrderDetail ID="OD1" PID="P1"/>
<OrderDetail ID="OD2" PID="P2"/>
</Order>
<Order ID="O2" date="3/29/1997"/>
</Customer>
<Customer ID="C2" NAME="Jack">
<Order ID="O3" date="1/20/2008">
<OrderDetail ID="OF1" PID="P1"/>
<OrderDetail ID="OF2" PID="P2"/>
</Order>
<Order ID="O4" date="3/29/1997">
<OrderDetail ID="OX1" PID="D1"/>
<OrderDetail ID="OX2" PID="D2"/>
</Order>
</Customer>Max
[My Italian Oracle blog|http://oracleitalia.wordpress.com/2010/02/07/aggiornare-una-tabella-con-listruzione-merge/] -
Pooling data from an XML file to another XML file using File Adapter
Hi,
I am trying to Pool data from an XML file to another XML file using File Adapter. I have added "Target Namespace" in both the XML and XSD.The problem is "At the destination given in the FileAdapter" only a blank XML file is created and it doesnot have any data.
Kindly suggest me some methods
Thanks in Advance.Ok here is a solution with external tables.
SQL> CREATE DIRECTORY my_xml_dir AS 'E:\oracle\Log_files\UTL_AKIVATST'
2 /
Directory created.
SQL> DROP TABLE my_xml_et
2 /
Table dropped.
SQL> CREATE TABLE my_xml_et
2 ( EMPNO NUMBER,
3 EMPNAME VARCHAR2(10),
4 JOB VARCHAR2(10),
5 HIREDATE DATE,
6 SAL NUMBER
7 )
8 ORGANIZATION EXTERNAL
9 (
10 TYPE ORACLE_LOADER
11 DEFAULT DIRECTORY my_xml_dir
12 ACCESS PARAMETERS
13 (
14 records delimited by "</EMP>"
15 badfile my_xml_dir:'empxt%a_%p.bad'
16 logfile my_xml_dir:'empxt%a_%p.log'
17 FIELDS
18 (
19 filler char(2000) terminated by "<EMP>",
20 EMPNO char(2000) enclosed by "<EMPNO>" and "</EMPNO>",
21 EMPNAME char(2000) enclosed by "<ENAME>" and "</ENAME>",
22 JOB char(2000) enclosed by "<JOB>" and "</JOB>",
23 HIREDATE char(2000) enclosed by "<HIREDATE>" and "</HIREDATE>",
24 SAL char(2000) enclosed by "<SAL>" and "</SAL>"
25 )
26 )
27 LOCATION ('emp.xml')
28 )
29 PARALLEL
30 REJECT LIMIT UNLIMITED
31 /
Table created.
SQL> SELECT * FROM my_xml_et
2 /
EMPNO EMPNAME JOB HIREDATE SAL
7369 SMITH CLERK 17-DEC-80 800
7499 ALLEN SALESMAN 20-FEB-81 1600
This is the XML file i used emp.xml
<EMPLOYEES>
<EMP>
<EMPNO>7369</EMPNO>
<ENAME>SMITH</ENAME>
<JOB>CLERK</JOB>
<HIREDATE>17-DEC-80</HIREDATE>
<SAL>800</SAL>
</EMP>
<EMP>
<EMPNO>7499</EMPNO>
<ENAME>ALLEN</ENAME>
<JOB>SALESMAN</JOB>
<HIREDATE>20-FEB-81</HIREDATE>
<SAL>1600</SAL>
<COMM>300</COMM>
</EMP>
</EMPLOYEES>
Use this external table to insert into your table.
Thanks,
Karthick. -
How to save an n-ary tree of nodes to and from an xml file
Hello,
I am trying to represent a n-ary tree of nodes in xml.
More accurately, I am trying to save/instantiate a
tree of nodes to-from an xml file.
How do I represent the parent-child relationships?
Java: (simplified)
class Node {
Arraylist childNodes;
Node parent;
XML:
From what I have been learning about XML,
DTD:
<?xml version="1.0" ?>
<!DOCTYPE acd
<!ELEMENT Node (childNodes, parent)>
<!ATTLIST Node id ID #REQUIRED>
<!ELEMENT childNodes (Node*)>
<!ELEMENT parent (Node?)>
]>
Qs:
1) How do I represent the relationships? What would
normally be a reference in Java, how do I represent in
XML?
2) Do I use ID, IDREF? I have been trying to find some
examples to learn how. i.e. Does the IDREF, ID
automatically become an in-memory reference (or pointer)?
3) Is it preferable to use XML schema?
thanks,
Anil Philip
Olathe, KS
for good news go to
http://members.tripod.com/goodnewsforyou/goodnews.htmlI downloaded XML Spy and used it to correct my earlier schema.
Qs:
In the instance document xml file;
1) How would one display the parent node?
2) If a child has a reference to a parent node as in the schema below, how can one know that the references are the same?
i.e. when the parent node is first declared and when it is referred to by the child.
Perhaps this raises a larger question - how does XML handle recursive references?
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://juwo.com/acd" xmlns="http://juwo.com/acd" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:annotation>
<xs:documentation>ACD nodes. juwo LLC 2005</xs:documentation>
</xs:annotation>
<xs:complexType name="Node">
<xs:sequence>
<xs:element name="parent" type="Node" minOccurs="0"/>
<!-- Node[] childNodes -->
<xs:element name="childNodes" type="ListOfNodes"/>
<!-- String data -->
<xs:element name="data" type="xs:string"/>
</xs:sequence>
<!-- Node parent -->
</xs:complexType>
<xs:complexType name="ListOfNodes">
<xs:sequence>
<xs:element name="i" type="Node" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:schema> -
How to delete the child record from the database
how to delete a parent and child record from the database can we do it in the servlet and my database is oracle
I'm not sure I understand the question but you could certainly use the JDBC API from within your servlet to access and modify a DB. You could also use an EJB layer to access your DB and accomplish the same tasks.
-
Error in Reading data from a xml file in ESB
Hi,
i created a inbound file adapter service which reads data from a xml file and passes it to the routing service and from there updates to the database.....
(everything created in jdeveloper)
But i am getting error....it is not getting updated to the database...when i check the database(select * from table) its showing one row selected but i couldnt find the data....
Transformation mapping also i did...
i think may be some error in reading the data from the xml file but not so sure.....
please reply to this mail as soon as possible its very urgentMichael R wrote:
The target table will be created when you execute the interface, if you set the option on the flow tab as instructed in step #6 of the "Setting up ODI Constraint on CLIENT Datastore" Section.
Option Value
CREATE_TARG_TABLE trueHi Michel,
This was not my required answer.I am sorry that I was unable to clarify my question.Actually
+This project executed successfully with some warning.Target Table is automatically created in database and also populated with data.But when I right-click Target Datastore(in >Mapping Tab of the Interface), and then select Data to View Data that needs to be inserted in the target table.I get some error like this:-...+This above line is the result of my project my problem is
when I right-click Target Datastore(in Mapping Tab of the Interface), and then select Data to View Data that already inserted in the target table.Is not shown by the view data operation.
I meant to say I am facing this error
At the10(1010 written) step of
Creating a New ODI Interface to Perform XML File to RDBMS Table Transformation
wehre it says
Open the Interface tab. Select Mapping tab, right-click Target Datastore - CLIENT, and then select Data. View Data inserted in the target table. Close Data Editor. Close the tabs...
In my case when I use my sqldeveloper I can see data successfully inserted in my target table and also in error table (data that can't satisfy the constraint) .But I was unable to check this by following the above mentioned 10 th step and got this error.
Thanks -
Sliding Flash Interface - Using Links from an XML file Problem
Hi All,
Working on a new site for the company i've recently started
working for... fairly new to flash but wanted to try this sliding
interface for the graphic banner at the top of the page...
have a look here at an early version of the site - sliding
graphic interface at the top with coloured rollover buttons (a lot
of work still to do! feel free to post constructive criticism)
(am I allowed to post links??)
here is the unfinished version with no links in the flash bit
http://www.westfieldhealth.com/website/index.asp
The Problem:
I am pulling in a 'heading' 'text' and 'image' into the
sliding graphic interface from the following xml file... (there are
4 different xml files for 4 different slides)
<?xml version="1.0" encoding="iso-8859-1"?>
<content>
<dialogue>
<heading>Interested in selling our health
plans?</heading>
<text>Click here to learn more...</text>
<img>home_window/intSmall.jpg</img>
</dialogue>
</content>
I want to add a link to the xml that would be specific to
each instance of the window...
eg
<link>contact-us/index.asp</link>
But my limited knowledge of flash means I have no idea how to
pull the link through from the xml file to use in the flash...
Perhaps I need link text to pull as well
eg
<link-text>click here to contact us</link-text>
Here is the function that pulls in the img, heading and txt
public function onComplete(event:Event):void {
var loader:URLLoader = event.target as URLLoader;
if (loader != null) {
externalXML = new XML(loader.data);
mover_mc.heading_txt.htmlText =
externalXML.dialogue[0].heading;
mover_mc.myText_txt.htmlText = externalXML.dialogue[0].text;
var url:URLRequest = new
URLRequest(externalXML.dialogue[0].img);
myLoader.load(url);
} else {
trace("loader is not a URLLoader!");
Can anyone help me on how to pull in the link from the xml
and use it to navigate to a different page on the site
Thanks very much
Hans
link to
my unfinished flash file...What is the exact error you get (what db version also), could you post a simplified version of the SQL which fails also? I have splitter based maps that successfully read from file via the XMLType(bfilename....) style code and insert into multiple targets, I did this on 11g though.
Cheers
David -
Is it possible to extract the xpath for fields from a XML file
Hi,
After all we do the recording to capture the xpath of the fields, so i thought of extracting xpath from a XML file will be a good idea.
Is there a way to do this?
Please suggest
regards
SureshYes, there is. Go to the Tools menu -> Generate XPaths and load in your xml file. Select the element you are interested in and you will get the XPath to utilise.
Regards,
Jamie -
Splitting of a CSV File with Multiple Records into Multiple XML File
Dear All,
<b> I am doing a Scenario of CSV to XML Files. I am using BPM for the same. My incoming CSV File has got multiple records. I want to break this Multiple records into Multiple XML Files having one record each.</b>
Can someone suggest how can I break this rather Split this into Multiple XML Files.
Is Multimapping absoltely necesaary for this. Can't we do this without Multimapping. Can we have some workaround in the FCC parameters that we use in the Integration Directory.
Kindly reply ASAP. Thanks a lot to all in anticipation.
Pls Help.
Best Regards
Chakra and SomnathDear All,
I am trying to do the Multimapping, and have 0....unbounded also. Someways it is not working.
<b>
Smitha please tell me one thing...Assigning the Recordsets per Message to 1, does it mean that it will write multiple XML Files as I want.</b>
Also I am usinf Set to Read only. So once the File is read it becomes RA from A. Then will it write the other Records.
I have to use a BPM because there are certain dependencies that are there for the entire Process Flow. I cannot do without a BPM.
Awaiting a reply. Thanks a lot in anticipation.
Best Regards
Chakra and Somnath -
Creation of a shipping notification for a PO in EBP from a XML file via XI.
Hi everybody.
We are trying to create a shipping notification for a Purchase Order in Enterprise Buyer from a XML file via XI.
For to do it, we are using DespatchedDeliveryNotification_In message interface (transaction SPROXY).
But when we execute it, the system show us next message:
"An error occured within an XI interface: An exception with the type CX_GDT_CONVERSION occurred, but was neither handled locally, nor declared in a RAISING clause Programm: SAPLBBP_BD_MAPPING_SAPXML1; Include: LBBP_BD_MAPPING_SAPXML1F5B; Line: 4"
No more information is available.
Is there any additional transaction to see more information about the error message?
Is there any documentation about this XML file, mandatory fields, examples ?
We populated some fields in our XML file, but we do not know if the problem is with mandatory fields, data, program error
I will thank for any information
Thanks in advance.
Raúl Moncada.Raúl,
This is because of the inbound UOM.
The include LBBP_BD_MAPPING_SAPXML1F5B is in charge of mapping the item Unit Of Mesure (UOM) sent in the ASN XML file (it should be an ISO code).
You can test FM UNIT_OF_MEASURE_ISO_TO_SAP with this inbound ISO code.
PS: you should create an OSS message so the mapping sends back an error message instead of generating an uncatched exception (that generates a dump).
Rgds
Christophe
PS: please reward points for helpfull answers -
Crystal Report that reads from an XML file Datetime or Date
I have a Crystal Report 2008 that reads from an XML file, the source File XML Date data looks like this: 2008-03-10
But the Crystal Report interpreted by datatime, I need the Crystal Report to look like this: 2008/03/10 (date) not 2008-03-10T00:00:00-05:00 (datatime)
Look at an example (source file xml, report, and parameter file to execute report) at url: http://www.5websoft.com/sample.zip
Import the file in the design and will to verify that interpret incorrectly the fields of type date as datetime
not mapped currently for fields..
Help.....
Thanks!You could always reformat the field to only display the date portion:
Format Field > Date and Time tab; choose the date style you need here.
Or create a formula to extract just the date and use this field in your report:
date({table.field}) -
How to read some records from a text file into java(not all records)
hello,
how to read text files into java. i need only few records from the text file not all records at a time.
If any one knows plz reply me
my id is [email protected]this snipet reads a text file line by line from line 1 to 3
try {
FileReader fr = new FileReader(directory);
BufferedReader br = new BufferedReader(fr);
int counter = 0;
while ((dbconn = br.readLine()) != null) {
switch(counter){
case 0:
status = dbconn;
break;
case 1:
userName = dbconn;
break;
case 2:
apword = dbconn;
break;
counter++;
br.close();
}catch(IOException e){
}
Maybe you are looking for
-
I'm the assistant editor on a feature thats being cut on FCP HD Studio and I've hit a problem with the EDL. The film was transferred from 35mm to BETA and then to DVCAM and I logged everything with 24fps capture settings and have been editing on a 24
-
I need to convert a pdf file to its binary contents so I can send it as a message to an IBM MQ Series. How can i convert pdf to its binary contents in java? Is there other alternatives besides converting pdf to binary representation? String? Array of
-
hi, I'm trying to simulate a solar system and I have those two problems - I can't add a sattelite to a planet (the moon to the earth) - I can't make a planet turn on itself (only the central one: the sun) Here is my source. Thanks for helping. Sorry
-
I've had this problem befoer and am almost ready to go another route with having clients review my footage because this I can't trust CS Review to work. I opened Premiere and in my CS Review window the "sign in" button is greyed out and below it say
-
I'm trying ti send my apps from iPad to iPod any help