View on XmlType
I am trying to create a view that flattens certain parts of a chunk of XML in Oracle 9i r2, e.g.
create view cdp ("PNO") as
select xmltype.extract(
datapoint,
'/*/data:PNO/text()',
'xmlns:data="urn:acq-osd-mil:damir:data"').
getstringval() from incomingdatapoint
This works fine, except when attempting to use a group by on the "PNO" column of the view I get an ORA-22806.
Interestingly, querying the original table and grouping by the whole xmltype.extract expression works fine, so I don't see why it shouldn't work through a view as well.
Is there any way to get around this limitation? Any information would be appreciated. Thanks.
You added a targetNamespace to the XML Schema, changing the namespace for the elements. You need to define a namespace prefix mapping in each operator that uses a path expression... eg
SELECT X.id_exemp_req id_exemp_req
, extractValue(value(t),'/ExemptionRequest/ExemptionRequestInfo/ExemptionRequestNbr','xmlns="http://www.rsvz-inasti.fgov.be/schemas/B2B/Exchanges") ExemptionRequestNbr_RInf
, extractValue(value(t),'/ExemptionRequest/ExemptionRequestInfo/SIFCode','xmlns="http://www.rsvz-inasti.fgov.be/schemas/B2B/Exchanges",'xmlns="http://www.rsvz-inasti.fgov.be/schemas/B2B/Exchanges") SIFCode_RInf
, extractValue(value(t),'/ExemptionRequest/ExemptionRequestInfo/DateRegistration','xmlns="http://www.rsvz-inasti.fgov.be/schemas/B2B/Exchanges") DateRegistration_RInf
, extractValue(value(t),'/ExemptionRequest/ExemptionRequestInfo/DateRegistered','xmlns="http://www.rsvz-inasti.fgov.be/schemas/B2B/Exchanges") DateRegistered_RInf
, extractValue(value(t),'/ExemptionRequest/ExemptionRequestInfo/RelationCode','xmlns="http://www.rsvz-inasti.fgov.be/schemas/B2B/Exchanges") RelationCode_RInf
FROM XML_EXEMPTION_REQUESTS_ALL X,
TABLE (xmlsequence(extract(XMLTYPE.createXML(X.xmlval),'/ExemptionRequest','xmlns="http://www.rsvz-inasti.fgov.be/schemas/B2B/Exchanges"))) tThe reason for this is that in the case of a schema based XMLType table or column, if there is no namespace:prefix mappings supplied we assume that the default namespace is the targetNamespace, avoiding the need to supply a namespace prefix mapping for the targetNamespace . This was probably a mistake, but it is quite useful.
In the case of a non schema based xmltype (which this is since it has been constructed from a CLOB we cannot make the assumption.
In general I would recommend that you change both views and provide an explicit namespace:prefix mapping to all the operators.
Which database release are you working with
Similar Messages
-
How to create view for xmltype table in oracle
hi:
Can some one help me how to create view for xmltype table in oracle?
XMLType do not have column
SemThank you !!
I read it and become very hard to implement what I want to do.
Can you give me example please?
My main goal to create view for xmltype table is to XQuery the XML data?
Do you have any other suggestion?
Please help
Ali_2 -
Oracle Materialized view with xmltype data type
this the table having in db1 i need to create materialized view db2 for this table i have followed below steps..
create table WORKSHEETMASTER
METHODID NUMBER(10),
WORKSHEETCODE VARCHAR2(50 BYTE) not null,
WORKSHEET SYS.XMLTYPE);
create materialized view log on db1.WORKSHEETMASTER;
db2
CREATE MATERIALIZED VIEW WORKSHEETMASTER
REFRESH FAST ON DEMAND
AS
SELECT METHODID,
WORKSHEETCODE,
worksheet FROM db1.WORKSHEETMASTER@DBLINK;
when i was create materialized view above script in db2 iam getting error
ORA-22992:cannot use LOB locators selected from remote tables
like this when remove the worksheet column created succesfully may know how achieve this problem
my database version 11g iam searched some sceniour not full filled
need for help
thanksthis the table having with in DB1
create table WORKSHEETMASTER
METHODID NUMBER(10),
WORKSHEETCODE VARCHAR2(50 BYTE) not null,
WORKSHEET SYS.XMLTYPE,
WORKSHEETID NUMBER primary key,
CREATEDDATE DATE,
CREATEDBY VARCHAR2(50 BYTE),
WORKSHEETNAME VARCHAR2(50 BYTE),
UPDATEDDATE DATE,
UPDATEDBY VARCHAR2(50 BYTE),
NOOFROWS NUMBER(3),
NOOFCOLUMNS NUMBER(3),
WORKSHEETTYPE CHAR(1 BYTE),
SUBSTRATEUSED VARCHAR2(50 BYTE),
STATUS NUMBER(1),
APPROVEDBY VARCHAR2(50 BYTE),
APPROVED CHAR(1 BYTE) default 'N',
APPROVALREMARKS VARCHAR2(100 BYTE),
LNG_WORKSHEETNAME VARCHAR2(50)
iam trying to create materailzed view in db2
create materialized view WORKSHEETMASTER
refresh fast on demand
as
SELECT METHODID,
WORKSHEETCODE,
WORKSHEETID,
worksheet,
CREATEDDATE,
CREATEDBY,
WORKSHEETNAME,
UPDATEDDATE,
UPDATEDBY,
NOOFROWS,
NOOFCOLUMNS ,
WORKSHEETTYPE,
SUBSTRATEUSED,
STATUS,
APPROVEDBY,
APPROVED,
APPROVALREMARKS,
LNG_WORKSHEETNAME FROM db1.WORKSHEETMASTER@DBLINK; --remote database
iam creating above scriprt in db2 getting error this my total script -
Materialized view with xmltype data type
Hello to all,
I have a challenge with my 10g r2 database. I need to make a materialized view from a table in this format:
Name Null? Type
RECID NOT NULL VARCHAR2(200)
XMLRECORD XMLTYPE
,my problem is that (as i read from docs) i cant make the view refreshable on commit and also i cant refresh the mv in fast mode ( i dont need to refresh mv complete - takes too long).
Do you have a hint for this?
Thank you in advance.
Danielhi,
I cant upgrade to 11g.Also i cant change the table structure.
Here is a sample of xmltype field content:
RECID XMLRECORD
D00009999 <row id='D100009999'><c2>10000</c2><c3>xxxxx</c3><c5>xxxx..
And i need to extract in the mv the data from c2, c3 and so on.
Still waiting for a hint.
Thank you. -
Hi,
I had an xmlschema that looked as follows:
<xs:schema xmlns:ora="http://xmlns.oracle.com/xdb" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="http://helios:8081/home/CVB/xsd/Elements.xsd"/>
And I read the following xml in the database:
<ExemptionRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.rsvz-inasti.fgov.be/schemas/B2B/Exchanges http://helios:8081/home/CVB/xsd/B303_Exemption.xsd">
<ExemptionRequestInfo>
<ExemptionRequestNbr>C061251532341</ExemptionRequestNbr>
<SIFCode>016</SIFCode>
This xml-file was read into an clob column and on this clob column I made a relational view as follows:
SELECT X.id_exemp_req id_exemp_req
, extractValue(value(t),'/ExemptionRequest/ExemptionRequestInfo/ExemptionRequestNbr') ExemptionRequestNbr_RInf
, extractValue(value(t),'/ExemptionRequest/ExemptionRequestInfo/SIFCode') SIFCode_RInf
, extractValue(value(t),'/ExemptionRequest/ExemptionRequestInfo/DateRegistration') DateRegistration_RInf
, extractValue(value(t),'/ExemptionRequest/ExemptionRequestInfo/DateRegistered') DateRegistered_RInf
, extractValue(value(t),'/ExemptionRequest/ExemptionRequestInfo/RelationCode') RelationCode_RInf
FROM XML_EXEMPTION_REQUESTS_ALL X,
TABLE (xmlsequence(extract(XMLTYPE.createXML(X.xmlval),'/ExemptionRequest'))) t
And this worked very well.
Now however, I have changed the schema as follows:
<xs:schema xmlns="http://www.rsvz-inasti.fgov.be/schemas/B2B/Exchanges" xmlns:ora="http://xmlns.oracle.com/xdb" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.rsvz-inasti.fgov.be/schemas/B2B/Exchanges" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="http://helios:8081/home/CVB/xsd/Elements.xsd"/>
The xml then looks as follows:
<ExemptionRequest xmlns="http://www.rsvz-inasti.fgov.be/schemas/B2B/Exchanges" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.rsvz-inasti.fgov.be/schemas/B2B/Exchanges http://helios:8081/home/CVB/xsd/B303_Exemption.xsd">
But now my view doesn't work anymore. The relational columns are all empty.
But I only changed the header of the schema and not the structure/content of it.
I have another view which works directly on the XMLTYPE TABLE (and that has the same structure) and this still works fine:
SELECT extractValue(value(u),'/ExemptionRequestInfo/ExemptionRequestNbr') ExemptionRequestNbr_RInf
, extractValue(value(u),'/ExemptionRequestInfo/SIFCode') SIFCode_RInf
, extractValue(value(u),'/ExemptionRequestInfo/DateRegistration') DateRegistration_RInf
, extractValue(value(u),'/ExemptionRequestInfo/DateRegistered') DateRegistered_RInf
, extractValue(value(u),'/ExemptionRequestInfo/RelationCode') RelationCode_RInf
, extractValue(value(v),'/ExemptionSelfEmployed/INSS') INSS_SE
FROM XML_EXEMPTION_REQUESTS X,
TABLE (xmlsequence(extract(value(X),'/ExemptionRequest'))) t,
TABLE (xmlsequence(extract(value(t),'/ExemptionRequest/ExemptionRequestInfo'))) u,
TABLE (xmlsequence(extract(value(t),'/ExemptionRequest/ExemptionSelfEmployed'))) v,
TABLE (xmlsequence(extract(value(v),'/ExemptionSelfEmployed/LegalInfo'))) w
Does anybody know why this happens?
Thanks in advance,
GeertYou added a targetNamespace to the XML Schema, changing the namespace for the elements. You need to define a namespace prefix mapping in each operator that uses a path expression... eg
SELECT X.id_exemp_req id_exemp_req
, extractValue(value(t),'/ExemptionRequest/ExemptionRequestInfo/ExemptionRequestNbr','xmlns="http://www.rsvz-inasti.fgov.be/schemas/B2B/Exchanges") ExemptionRequestNbr_RInf
, extractValue(value(t),'/ExemptionRequest/ExemptionRequestInfo/SIFCode','xmlns="http://www.rsvz-inasti.fgov.be/schemas/B2B/Exchanges",'xmlns="http://www.rsvz-inasti.fgov.be/schemas/B2B/Exchanges") SIFCode_RInf
, extractValue(value(t),'/ExemptionRequest/ExemptionRequestInfo/DateRegistration','xmlns="http://www.rsvz-inasti.fgov.be/schemas/B2B/Exchanges") DateRegistration_RInf
, extractValue(value(t),'/ExemptionRequest/ExemptionRequestInfo/DateRegistered','xmlns="http://www.rsvz-inasti.fgov.be/schemas/B2B/Exchanges") DateRegistered_RInf
, extractValue(value(t),'/ExemptionRequest/ExemptionRequestInfo/RelationCode','xmlns="http://www.rsvz-inasti.fgov.be/schemas/B2B/Exchanges") RelationCode_RInf
FROM XML_EXEMPTION_REQUESTS_ALL X,
TABLE (xmlsequence(extract(XMLTYPE.createXML(X.xmlval),'/ExemptionRequest','xmlns="http://www.rsvz-inasti.fgov.be/schemas/B2B/Exchanges"))) tThe reason for this is that in the case of a schema based XMLType table or column, if there is no namespace:prefix mappings supplied we assume that the default namespace is the targetNamespace, avoiding the need to supply a namespace prefix mapping for the targetNamespace . This was probably a mistake, but it is quite useful.
In the case of a non schema based xmltype (which this is since it has been constructed from a CLOB we cannot make the assumption.
In general I would recommend that you change both views and provide an explicit namespace:prefix mapping to all the operators.
Which database release are you working with -
Read-only view for XMLType data
HI Gentlemen,
When I execute my SQL statement:
select extract(object_value,'/keytabs/keytab/@SN') SN from keytabs
against a schema-based XMLType table from SQL*Plus I get normal response:
EXTRACT(OBJECT_VALUE,'/KEYTABS/KEYTAB/@SN')
S_KBV_GESCHLECHT
S_VDX_KONTENART
However, when I create a Fusion application with business components, and a custom view in the Model project with the SQL statement above,
it yields:
oracle.sql.OPAQUE@1623820.
Attribute type is String, and query column is VARCHAR(255). There is no entity because the view is read-only.
Can anyone help me how to directly query XMLType to display the contents?
Thanks, regards
Miklos HERBOLYCan you try:
select cast(extract(object_value, '/keytabs/keytab/@SN') as varchar2(255)) SN
from keytabsJohn -
How to install an external editor in version 2.1.1.64 for viewing XMLType
I have a question about viewing XMLType in version 2.1.1.64
If you want to view the content of an XMLType column in a data-tab, you can double click on the particular XMLType field and the edit button appears at the end. Push this edit button and an "Edit Dialog" popup appears with the data presented as one line.
Push the External Editor button and you get a dialog that informs you about the not supported mime type of the selected object. You can find the complete list of supported mime types in Tools->Preferences->External Editor panel. I like to use an external XML editor for viewing an xmltype column, can anyone put me on the right track? Change the Editor Location for the .xml file extension didn`t work.
Kind regards,
Erwin SnippertThis is the case:
SQL Developer version 2.1.1.64
Oracle client 11gR2
Oracle Database 9.2.0.6.
Under the table tree, on the left side of the screen, a table is selected with 3 columns. One of them is a XMLType column.
Click on the data tab on the right side of the screen and a part of the xml-data is visible of that XMLType column.
Perhaps my expectations are too high, i want to see the all XML data in a structured and readable way.
I have tried to accomplish this by double clicking on the particular data in the XMLType column. This results in an pencil icon on the right side of the data.
Click on this icon and a popup window appears with the 'Edit Value' titel. This windows shows the xml data as one string, not very readable.
I have the oppurtunity to click on an 'External Editor' button. It seems to me that i can use this button to see/edit the data with an external editor.
If you click on this button, a dialog appears with the following message : 'The Mime Type of selected object is currently not supported. Please see the complete list of supported Mime Type and extension in Tools>Preferences>External Editor panel.'
I have 2 questions, perhaps you can put me in the right direction :
- Why can't SQL developer standard display XML in a structured/readable way?
- How must SQL Developer be configured to use an external editor for displaying XML data from XMLType columns?
Kind Regards, Erwin -
I created a view for XMLType table. When I insert rows into table they are not reflected in view.
CREATE TABLE EMPLOYEE OF XMLType
XMLTYPE store AS OBJECT RELATIONAL
XMLSCHEMA "EMPLOYEE.XSD" ELEMENT "root";
CREATE OR REPLACE VIEW
employee_master_view(empid, empname, empproj, emporg)
AS SELECT extractValue(OBJECT_VALUE, '/EMPLOYEE/empid'),
extractValue(OBJECT_VALUE, '/EMPLOYEE/empname'),
extractValue(OBJECT_VALUE, '/EMPLOYEE/empproj'),
extractValue(OBJECT_VALUE, '/EMPLOYEE/emporg')
FROM EMPLOYEE;
INSERT INTO EMPLOYEE VALUES (XMLType(bfilename('XML_DIR', 'EMPLOYEE.XML'),
nls_charset_id('AL32UTF8')));
SELECT object_value from employee;
OBJECT_VALUE
SYS.XMLTYPE
SELECT extract (object_value, '/') from employee;
EXTRACT(OBJECT_VALUE,'/')
<root><empid>1</empid><empname>Gates</empname><empproj>EIS</empproj><emporg>Tata Cosultancy Services</emporg></root>
1 rows selected
desc employee_master_view;
Name
Null
Type
EMPID
VARCHAR2()
EMPNAME
VARCHAR2()
EMPPROJ
VARCHAR2()
EMPORG
VARCHAR2()
4 rows selected
select empid, empname, empproj, emporg from employee_master_view;
EMPID EMPNAME EMPPROJ EMPORG
1 rows selected
This returns empty rows. It should be printing the values of the xml tags in the columns.
Please help.extractValue(OBJECT_VALUE, '/EMPLOYEE/empid'),
I don't see any "EMPLOYEE" element in your sample XML document. Do you?
Try this XPath instead : /root/empid
And be aware extractValue and alike are deprecated starting from 11.2. -
Hi ,
When I am using the Xml with many attributes for the tags creation it displays the output as xml type only. Is there a different way to read this output or there is any characters limitation for display because when I pass few attributes the output is as expected. The attributes passed are the table columns read from the underlying table.
Please help me in understanding the output of XML and how its output can be displayed to read as many attributes possible.
Thanks for your help.What tool/version are you using to view the XMLType content?
-
I'm trying to generate XML files on a client machine. I'm using SQL*Plus Instant Client v 10.1.0.4.0 connected to DB version 10.1.0.3.0. I've created a view of XMLType and am able to select XML from this view. I've been unable to figure out a way to generate well-formed XML via a Spool command and Select statement as Sqlplus returns the XML as one row and has problems with line wrapping, embedded spaces, and also including the SQL command in the spooled output. I've tried many different permutations of Set commands to no avail.
Is there a way to generate a valid XML file from Sqlplus on a client machine using the Spool command? If not Sqlplus, any other suggestions?
Thanks,
GlennI would be inclined to write a pipelined function to take a clob, and break it up into pieces (perhaps after a '>').
Here's an example of a pipelined function, which you can modify to suit your needs, such as working with CLOBs. You may also want to add more intelligence to it, such as checking for when the chunk is longer than 2000 characters.
CREATE TYPE tvc2000 AS TABLE OF VARCHAR2(2000)
CREATE OR REPLACE
FUNCTION chopper
p_string IN VARCHAR2
RETURN tvc2000
PIPELINED
IS
l_len NUMBER := LENGTH(p_string);
l_out NUMBER := 0;
l_pos NUMBER;
BEGIN
l_pos := INSTR(p_string, '>', l_out+1);
WHILE l_pos > 0 LOOP
PIPE ROW(SUBSTR(p_string, l_out+1, l_pos - l_out));
l_out := l_pos;
l_pos := INSTR(p_string, '>', l_out+1);
END LOOP;
IF l_out < l_len THEN
PIPE ROW(SUBSTR(p_string, l_out+1, l_len - l_out));
END IF;
RETURN;
END;
SELECT *
FROM TABLE(chopper('abc>def>'))
COLUMN_VALUE
abc>
def>Tak -
DBMS_XMLDOM Package Sample
Hello everyone
I need to generate XML output through PL/SQL. Though I had been successful in using DBMS_XMLGEN package, I need to us DBMS_XMLDOM, as I need create hierarchical xml document (ie., Department .....Department Attributes; Employee ....employee attributes....Employee and its attributes within Department node). I was searching for any samples but could not find any. Any help would be appreciated. Also, if I need to approach it in a different way, please let me know about it.
Thank you in advance
VV.There are some examples of using DBMS_XMLDOM in the online documentation ...
http://download-west.oracle.com/docs/cd/B14117_01/appdev.101/b10790/xdb10pls.htm#sthref1069
Some other options would be to use XMLType Views, the XMLType functions or schema object types and the object based XMLType constructor ...
http://download-west.oracle.com/docs/cd/B14117_01/appdev.101/b10790/xdb14vie.htm#CJIDAFJI
http://download-west.oracle.com/docs/cd/B14117_01/appdev.101/b10790/xdb14vie.htm#i1025417
http://download-west.oracle.com/docs/cd/B14117_01/appdev.101/b10802/t_xml.htm#1009843
http://download-west.oracle.com/docs/cd/B14117_01/appdev.101/b10790/xdb13gen.htm#sthref1166 -
Approach to parse large number of XML files into the relational table.
We are exploring the option of XML DB for processing a large number of files coming same day.
The objective is to parse the XML file and store in multiple relational tables. Once in relational table we do not care about the XML file.
The file can not be stored on the file server and need to be stored in a table before parsing due to security issues. A third party system will send the file and will store it in the XML DB.
File size can be between 1MB to 50MB and high performance is very much expected other wise the solution will be tossed.
Although we do not have XSD, the XML file is well structured. We are on 11g Release 2.
Based on the reading this is what my approach.
1. CREATE TABLE XML_DATA
(xml_col XMLTYPE)
XMLTYPE xml_col STORE AS SECUREFILE BINARY XML;
2. Third party will store the data in XML_DATA table.
3. Create XMLINDEX on the unique XML element
4. Create views on XMLTYPE
CREATE OR REPLACE FORCE VIEW V_XML_DATA(
Stype,
Mtype,
MNAME,
OIDT
AS
SELECT x."Stype",
x."Mtype",
x."Mname",
x."OIDT"
FROM data_table t,
XMLTABLE (
'/SectionMain'
PASSING t.data
COLUMNS Stype VARCHAR2 (30) PATH 'Stype',
Mtype VARCHAR2 (3) PATH 'Mtype',
MNAME VARCHAR2 (30) PATH 'MNAME',
OIDT VARCHAR2 (30) PATH 'OID') x;
5. Bulk load the parse data in the staging table based on the index column.
Please comment on the above approach any suggestion that can improve the performance.
Thanks
AnuragTThanks for your response. It givies more confidence.
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
TNS for Linux: Version 11.2.0.3.0 - Production
Example XML
<SectionMain>
<SectionState>Closed</SectionState>
<FunctionalState>CP FINISHED</FunctionalState>
<CreatedTime>2012-08</CreatedTime>
<Number>106</Number>
<SectionType>Reel</SectionType>
<MachineType>CP</MachineType>
<MachineName>CP_225</MachineName>
<OID>99dd48cf-fd1b-46cf-9983-0026c04963d2</OID>
</SectionMain>
<SectionEvent>
<SectionOID>99dd48cf-2</SectionOID>
<EventName>CP.CP_225.Shredder</EventName>
<OID>b3dd48cf-532d-4126-92d2</OID>
</SectionEvent>
<SectionAddData>
<SectionOID>99dd48cf2</SectionOID>
<AttributeName>ReelVersion</AttributeName>
<AttributeValue>4</AttributeValue>
<OID>b3dd48cf</OID>
</SectionAddData>
- <SectionAddData>
<SectionOID>99dd48cf-fd1b-46cf-9983</SectionOID>
<AttributeName>ReelNr</AttributeName>
<AttributeValue>38</AttributeValue>
<OID>b3dd48cf</OID>
<BNCounter>
<SectionID>99dd48cf-fd1b-46cf-9983-0026c04963d2</SectionID>
<Run>CPFirstRun</Run>
<SortingClass>84</SortingClass>
<OutputStacker>D2</OutputStacker>
<BNCounter>54605</BNCounter>
</BNCounter>
I was not aware of Virtual column but looks like we can use it and avoid creating views by just inserting directly into
the staging table using virtual column.
Suppose OID id is the unique identifier of each XML FILE and I created virtual column
CREATE TABLE po_Virtual OF XMLTYPE
XMLTYPE STORE AS BINARY XML
VIRTUAL COLUMNS
(OID_1 AS (XMLCAST(XMLQUERY('/SectionMain/OID'
PASSING OBJECT_VALUE RETURNING CONTENT)
AS VARCHAR2(30))));
1. My question is how then I will write this query by NOT USING COLMUN XML_COL
SELECT x."SECTIONTYPE",
x."MACHINETYPE",
x."MACHINENAME",
x."OIDT"
FROM po_Virtual t,
XMLTABLE (
'/SectionMain'
PASSING t.xml_col <--WHAT WILL PASSING HERE SINCE NO XML_COL
COLUMNS SectionType VARCHAR2 (30) PATH 'SectionType',
MachineType VARCHAR2 (3) PATH 'MachineType',
MachineName VARCHAR2 (30) PATH 'MachineName',
OIDT VARCHAR2 (30) PATH 'OID') x;
2. Insetead of creating the view then Can I do
insert into STAGING_table_yyy ( col1 ,col2,col3,col4,
SELECT x."SECTIONTYPE",
x."MACHINETYPE",
x."MACHINENAME",
x."OIDT"
FROM xml_data t,
XMLTABLE (
'/SectionMain'
PASSING t.xml_col <--WHAT WILL PASSING HERE SINCE NO XML_COL
COLUMNS SectionType VARCHAR2 (30) PATH 'SectionType',
MachineType VARCHAR2 (3) PATH 'MachineType',
MachineName VARCHAR2 (30) PATH 'MachineName',
OIDT VARCHAR2 (30) PATH 'OID') x
where oid_1 = '99dd48cf-fd1b-46cf-9983';<--VIRTUAL COLUMN
insert into STAGING_table_yyy ( col1 ,col2,col3
SELECT x."SectionOID",
x."EventName",
x."OIDT"
FROM xml_data t,
XMLTABLE (
'/SectionMain'
PASSING t.xml_col <--WHAT WILL PASSING HERE SINCE NO XML_COL
COLUMNS SectionOID PATH 'SectionOID',
EventName VARCHAR2 (30) PATH 'EventName',
OID VARCHAR2 (30) PATH 'OID',
) x
where oid_1 = '99dd48cf-fd1b-46cf-9983';<--VIRTUAL COLUMN
Same insert for other tables usind the OID_1 virtual coulmn
3. Finaly Once done how can I delete the XML document from XML.
If I am using virtual column then I beleive it will be easy
DELETE table po_Virtual where oid_1 = '99dd48cf-fd1b-46cf-9983';
But in case we can not use the Virtual column how we can delete the data
Thanks in advance
AnuragT -
Error when a try to update a xmltype view thru a trigger instead of update
<PERSON>
<ID>4</ID>
<FIRSTNAME>Frédéric</FIRSTNAME>
<LASTNAME>Philippekin</LASTNAME>
<SEX>M</SEX>
<WEIGHT>75</WEIGHT>
<HEIGHT>175</HEIGHT>
</PERSON>
CREATE OR REPLACE VIEW personne_oracle OF XMLType
XMLSCHEMA "personOracle.xsd" ELEMENT "PERSON"
WITH OBJECT ID (EXTRACT(sys_nc_rowinfo$, '/PERSON/ID').getNumberVal())
AS SELECT XMLELEMENT("PERSON",
XMLFOREST( Id,
FirstName,
LastName,
Sex,
Weight,
Height)
) AS Valeur
FROM Person;
CREATE OR REPLACE TRIGGER u_personne_oracle_tr
INSTEAD OF UPDATE on personne_oracle
BEGIN
UPDATE Person SET
Person.FirstName = extractvalue(:new.sys_nc_rowinfo$,'/PERSON/FIRSTNAME/text()'),
Person.LastName = extractvalue(:new.sys_nc_rowinfo$,'/PERSON/LASTNAME/text()'),
Person.Weight = extractvalue(:new.sys_nc_rowinfo$,'/PERSON/WEIGHT/text()'),
Person.Height = extractvalue(:new.sys_nc_rowinfo$,'/PERSON/HEIGHT/text()')
WHERE Person.Id = extractvalue(:new.sys_nc_rowinfo$,'/PERSON/ID');
END;
UPDATE personne_oracle x
SET value(x) = updateXML(value(x), '/PERSON/FIRSTNAME/text()','Fred')
WHERE extractValue(value(x), '/PERSON/ID') = 4;
ORA-24358: OCIBindObject not invoked for a Object type or Reference
please help me !What happens if you move the view to the remote db?
and create a synonym for the view on the local?it doesn't work !
>
alternatively,
what happens if you modify from person@oraclelink in
the create or replace view personne_oracle?it doesn't work !
The problem is the dblink ! Without it it's work !
thx for your answer. -
How to create a relational view base on an xmltype table which included sev
Hi,
I am using oracle 11.2.0.1.0.
how to create a relational view base on an xmltype table which content several different .xml files?
Thanks.
for examle:
SQL> SELECT OBJECT_VALUE FROM document;
Edited by: Cow on Jan 6, 2011 7:57 PMFor example I already have these three xml files inserted into the document xmltype table.
These xml files have same schemas. I have attached below.
I want to show all elements/attribute values in xml files to relational view.
Is this possible to create one big relational view to show everything
or I have to create three separate relation views then use UNION to put together? Thanks a lot. Cow
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet href="http://www.accessdata.fda.gov/spl/stylesheet/spl.xsl" type="text/xsl"?>
<document xmlns="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:hl7-org:v3 http://localhost:8080/home/DEV/xsd/spl.xsd">
<id root="5ca4e3cb-7298-4948-8cc2-58e71ad32694"/>
</component>
</document>
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet href="http://www.accessdata.fda.gov/spl/stylesheet/spl.xsl" type="text/xsl"?>
<document xmlns="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:hl7-org:v3 http://localhost:8080/home/DEV/xsd/spl.xsd">
</component>
</document>
Edited by: Cow on Jan 4, 2011 9:51 AM -
I have created an XMLType view with an INSTEAD OF trigger to insert data into the underlying tables. I used your example on XMLType view of Relational Content
It works great if I have no attributes defined in the root element of the XML document (i.e. xmlns, schemaLocation, etc.). However, if my document contains any of those attributes, it will not load. I have tried creating the view with and without the xml attributes, as well as making sure that the schemaLocation is identical to the one in the document (copied and pasted just to make sure).
Is there anything that you can point to right away that I'm missing?
If needed, I can post code for you.
Thanks!Here is the code I used to generate the tables, view, and triggers:
drop table p_student_demographics;
create table p_student_demographics -- a
wiser_id varchar2(8),
first_name varchar2(15),
middle_name varchar2(15),
last_name varchar2(25),
birthdate date,
school_id varchar2(7),
special_ed_teacher varchar2(50)
drop table p_scorer_info;
create table p_scorer_info -- b
test_record_id number,
scorer_number number,
name varchar2(80),
email varchar2(50)
drop table p_test_record;
create table p_test_record -- c
wiser_id varchar2(8),
test_record_id number,
grade_tested varchar2(2),
first_scorer_completed varchar2(3),
second_scorer_completed varchar2(3)
drop table p_psw_test_results;
create table p_psw_test_results -- d
test_record_id number,
subject varchar2(7),
entry_number number,
complexity varchar2(1),
performance varchar2(1),
independence varchar2(1),
generalization varchar2(1),
non_scorable varchar2(4)
drop table p_spe_test_results;
create table p_spe_test_results -- e
test_record_id number,
subject varchar2(7),
entry_number number,
item_number number,
response varchar2(1)
drop table p_total_scores;
create table p_total_scores -- f
test_record_id number,
subject varchar2(7),
psw_total_raw_score varchar2(2),
spe_total_raw_score varchar2(2),
tas_score varchar2(2),
tas_portfolio_score varchar2(2),
tas_spe_score varchar2(2),
overall_total_raw_score varchar2(2),
overall_performance_level varchar2(1)
drop table p_school_info;
create table p_school_info
district_id varchar2(7),
district_name varchar2(80),
school_id varchar2(7),
school_name varchar2(80)
create or replace view paws_alt_test_results
of xmltype
xmlschema "http://www.k12.wy.us/public/paws-alt-results-v1.xsd" element "PawsAltResults"
with object id
(to_number(extractValue(object_value,'/PawsAltResults/Students/TestRecord/TestRecordId')))
as
select xmlelement
"PawsAltResults",
xmlelement
"Students",
xmlelement
"StudentInfo",
xmlelement
"StudentDemographics",
xmlelement("WiserId", a.wiser_id),
xmlelement("FirstName", a.first_name),
xmlelement("MiddleName", a.middle_name),
xmlelement("LastName", a.last_name),
xmlelement("BirthDate", a.birthdate)
xmlelement("SchoolId", a.school_id),
xmlelement("SpecialEdTeacher", a.special_ed_teacher),
xmlelement
"DocumentCompletedBy",
xmlelement("FirstScorer", c.first_scorer_completed),
xmlelement("SecondScorer", c.second_scorer_completed)
xmlelement
"FirstScorerInfo",
xmlelement("Name", b1.name),
xmlelement("Email", b1.email)
xmlelement
"SecondScorerInfo",
xmlelement("Name", b2.name),
xmlelement("Email", b2.email)
xmlelement
"TestRecord",
xmlelement("TestRecordId", c.test_record_id),
xmlelement("GradeTested", c.grade_tested),
xmlelement
"Subjects",
select xmlagg
xmlelement
"Subject",
xmlelement("SubjectName", f.subject),
xmlelement
"Psw",
xmlelement
"Entries",
select xmlagg
xmlelement
"Entry",
xmlelement("EntryNumber", x.entry_number),
xmlelement("Complexity", x.complexity),
xmlelement("Performance", x.performance),
xmlelement("Independence", x.independence),
xmlelement("Generalization", x.generalization),
xmlelement("NonScorable", x.non_scorable)
from p_psw_test_results x
where f.test_record_id = x.test_record_id
and f.subject = x.subject
xmlelement("TotalRawScore", f.psw_total_raw_score)
xmlelement
"Spe",
xmlelement
"Entries",
select xmlagg
xmlelement
"Entry",
xmlelement("EntryNumber", x.entry_number),
xmlelement
"Items",
select xmlagg
xmlelement
"Item",
xmlelement("ItemNumber", y.item_number),
xmlelement("Response", y.response)
from p_spe_test_results y
where x.test_record_id = y.test_record_id
and x.subject = y.subject
and x.entry_number = y.entry_number
from (select distinct
test_record_id,
subject,
entry_number
from p_spe_test_results) x
where f.test_record_id = x.test_record_id
and f.subject = x.subject
xmlelement("TotalRawScore", f.spe_total_raw_score)
xmlelement("TasScore", f.tas_score),
xmlelement("TasPortfolioScore", f.tas_portfolio_score),
xmlelement("TasSpeScore", f.tas_spe_score),
xmlelement("OverallTotalRawScore", f.overall_total_raw_score),
xmlelement("OverallPerformanceLevel", f.overall_performance_level)
from p_total_scores f
where c.test_record_id = f.test_record_id
xmlelement
"Districts",
select xmlagg
xmlelement
"DistrictInfo",
xmlelement("DistrictId", district_id),
xmlelement("DistrictName", district_name)
from (select distinct
district_id,
district_name
from p_school_info)
xmlelement
"Schools",
select xmlagg
xmlelement
"SchoolInfo",
xmlelement("DistrictId", district_id),
xmlelement("SchoolId", school_id),
xmlelement("SchoolName", school_name)
from p_school_info
from p_student_demographics a,
p_scorer_info b1,
p_scorer_info b2,
p_test_record c
where a.wiser_id = c.wiser_id
and b1.test_record_id = b2.test_record_id
and b1.test_record_id = c.test_record_id
and b1.scorer_number = 1
and b2.scorer_number = 2;
create or replace trigger io_ins_paws_alt_results
instead of insert on paws_alt_test_results
begin
insert all
into p_student_demographics
(wiser_id, first_name, middle_name, last_name, birthdate, school_id,
special_ed_teacher)
values
(wiser_id, first_name, middle_name, last_name, birthdate, school_id,
special_ed_teacher)
into p_scorer_info
(test_record_id, scorer_number, name, email)
values
(test_record_id, 1, name1, email1)
into p_scorer_info
(test_record_id, scorer_number, name, email)
values
(test_record_id, 2, name2, email2)
into p_test_record
(wiser_id, test_record_id, grade_tested, first_scorer_completed,
second_scorer_completed)
values
(wiser_id, test_record_id, grade_tested, first_scorer_completed,
second_scorer_completed)
select a.*
from xmltable
'/PawsAltResults'
passing :new.object_value
columns
wiser_id varchar2(8) path 'Students/StudentInfo/StudentDemographics/WiserId',
first_name varchar2(15) path 'Students/StudentInfo/StudentDemographics/FirstName',
middle_name varchar2(15) path 'Students/StudentInfo/StudentDemographics/MiddleName',
last_name varchar2(25) path 'Students/StudentInfo/StudentDemographics/LastName',
birthdate date path 'Students/StudentInfo/StudentDemographics/Birthdate',
school_id varchar2(7) path 'Students/StudentInfo/SchoolId',
special_ed_teacher varchar2(50) path 'Students/StudentInfo/SpecialEdTeacher',
test_record_id number path 'Students/StudentInfo/TestRecord/TestRecordId',
name1 varchar2(80) path 'Students/StudentInfo/FirstScorerInfo/Name',
email1 varchar2(50) path 'Students/StudentInfo/FirstScorerInfo/Email',
name2 varchar2(80) path 'Students/StudentInfo/SecondScorerInfo/Name',
email2 varchar2(50) path 'Students/StudentInfo/SecondScorerInfo/Email',
grade_tested varchar2(2) path 'Students/StudentInfo/TestRecord/GradeTested',
first_scorer_completed varchar2(3) path 'Students/StudentInfo/DocumentCompletedBy/FirstScorer',
second_scorer_completed varchar2(3) path 'Students/StudentInfo/DocumentCompletedBy/SecondScorer'
) a;
insert all
into p_psw_test_results
(test_record_id, subject, entry_number, complexity, performance,
independence, generalization, non_scorable)
values
(test_record_id, subject, entry_number, complexity, performance,
independence, generalization, non_scorable)
into p_total_scores
(test_record_id, subject, psw_total_raw_score, spe_total_raw_score,
tas_score, tas_portfolio_score, tas_spe_score,
overall_total_raw_score, overall_performance_level)
values
(test_record_id, subject, psw_total_raw_score, spe_total_raw_score,
tas_score, tas_portfolio_score, tas_spe_score,
overall_total_raw_score, overall_performance_level)
select a.test_record_id,
b.subject,
b.psw_total_raw_score,
b.spe_total_raw_score,
b.tas_score,
b.tas_portfolio_score,
b.tas_spe_score,
b.overall_total_raw_score,
b.overall_performance_level,
c.*
from xmltable
'/PawsAltResults/Students/StudentInfo/TestRecord'
passing :new.object_value
columns
test_record_id number path 'TestRecordId',
subjects xmltype path 'Subjects/Subject'
) a,
xmltable
'/Subject'
passing a.subjects
columns
subject varchar2(7) path 'SubjectName',
psw_total_raw_score varchar2(2) path 'Psw/Entries/TotalRawScore',
spe_total_raw_score varchar2(2) path 'Spe/TotalRawScore',
tas_score varchar2(2) path 'TasScore',
tas_portfolio_score varchar2(2) path 'TasPortfolioScore',
tas_spe_score varchar2(2) path 'TasSpeScore',
overall_total_raw_score varchar2(2) path 'OverallTotalRawScore',
overall_performance_level varchar2(1) path 'OverallPerformanceLevel',
entries xmltype path 'Psw/Entries/Entry'
) b,
xmltable
'/Entry'
passing b.entries
columns
entry_number number path 'EntryNumber',
complexity varchar2(1) path 'Complexity',
performance varchar2(1) path 'Performance',
independence varchar2(1) path 'Independence',
generalization varchar2(1) path 'Generalization',
non_scorable varchar2(4) path 'NonScorable'
) c;
insert
into p_spe_test_results
(test_record_id, subject, entry_number, item_number, response)
select a.test_record_id,
b.subject,
c.entry_number,
d.*
from xmltable
'/PawsAltResults/Students/StudentInfo/TestRecord'
passing :new.object_value
columns
test_record_id number path 'TestRecordId',
subjects xmltype path 'Subjects/Subject'
) a,
xmltable
'/Subject'
passing a.subjects
columns
subject varchar2(7) path 'SubjectName',
entries xmltype path 'Spe/Entries/Entry'
) b,
xmltable
'/Entry'
passing b.entries
columns
entry_number number path 'EntryNumber',
items xmltype path 'Items/Item'
) c,
xmltable
'/Item'
passing c.items
columns
item_number number path 'ItemNumber',
response varchar2(1) path 'Response'
) d;
insert
into p_school_info
(district_id, district_name, school_id, school_name)
select a.district_id,
a.district_name,
b.school_id,
b.school_name
from xmltable
'PawsAltResults/Districts/DistrictInfo'
passing :new.object_value
columns
district_id varchar2(7) path 'DistrictId',
district_name varchar2(80) path 'DistrictName'
) a,
xmltable
'PawsAltResults/Schools/SchoolInfo'
passing :new.object_value
columns
district_id varchar2(7) path 'DistrictId',
school_id varchar2(7) path 'SchoolId',
school_name varchar2(80) path 'SchoolName'
) b
where a.district_id = b.district_id;
end io_ins_paws_alt_results;
XML document:
<?xml version="1.0" encoding="UTF-8"?>
<PawsAltResults xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2001/XMLSchema http://www.k12.wy.us/public/paws-alt-results-v1.xsd" xmlns="http://www.w3.org/2001/XMLSchema">
<Students>
<StudentInfo>
<StudentDemographics>
<WiserId>12345678</WiserId>
<FirstName>TestFirst</FirstName>
<MiddleName>M</MiddleName>
<LastName>TestLast</LastName>
<BirthDate>2000-02-02</BirthDate>
</StudentDemographics>
<SchoolId>2222222</SchoolId>
<SpecialEdTeacher>Test Special Ed Teacher</SpecialEdTeacher>
<DocumentCompletedBy>
<FirstScorer>Yes</FirstScorer>
<SecondScorer>No</SecondScorer>
</DocumentCompletedBy>
<FirstScorerInfo>
<Name>Test First Scorer</Name>
<Email>[email protected]</Email>
</FirstScorerInfo>
<SecondScorerInfo>
<Name>Test Second Scorer</Name>
<Email>[email protected]</Email>
</SecondScorerInfo>
<TestRecord>
<TestRecordId>1</TestRecordId>
<GradeTested>08</GradeTested>
<Subjects>
<Subject>
<SubjectName>Reading</SubjectName>
<Psw>
<Entries>
<Entry>
<EntryNumber>1</EntryNumber>
<Complexity>1</Complexity>
<Performance>2</Performance>
<Independence>3</Independence>
<Generalization>B</Generalization>
</Entry>
</Entries>
<TotalRawScore>20</TotalRawScore>
</Psw>
<Spe>
<Entries>
<Entry>
<EntryNumber>1</EntryNumber>
<Items>
<Item>
<ItemNumber>1</ItemNumber>
<Response>1</Response>
</Item>
<Item>
<ItemNumber>2</ItemNumber>
<Response>2</Response>
</Item>
</Items>
</Entry>
</Entries>
<TotalRawScore>30</TotalRawScore>
</Spe>
<TasScore>10</TasScore>
<TasPortfolioScore>20</TasPortfolioScore>
<TasSpeScore>15</TasSpeScore>
<OverallTotalRawScore>50</OverallTotalRawScore>
<OverallPerformanceLevel>3</OverallPerformanceLevel>
</Subject>
</Subjects>
</TestRecord>
</StudentInfo>
</Students>
<Districts>
<DistrictInfo>
<DistrictId>1111111</DistrictId>
<DistrictName>Test District Name</DistrictName>
</DistrictInfo>
</Districts>
<Schools>
<SchoolInfo>
<DistrictId>1111111</DistrictId>
<SchoolId>2222222</SchoolId>
<SchoolName>Test School Name</SchoolName>
</SchoolInfo>
</Schools>
</PawsAltResults>
Insert statement:
insert into paws_alt_test_results values (xmltype(bfilename('XMLDIR','test-paws-alt.xml'),nls_charset_id('AL32UTF8')));
There are no errors shown on the insert statement. It tells me that one row was inserted, but there is no data when looking at the tables (unless I remove the attributes from the root element of the XML file).
I'm using version 10.2.0.3
Thanks for your help!
Maybe you are looking for
-
Is there a way that to make text look like it is being written on the screen?
I once saw a tiltle (using the font edwardian script) that looked like it was being written on the screen. I tried using the linear wipe transition, but this does not make the full effect i want.. for instance, when you make a letter "t" in cursive,
-
Clearing of text messages history
for some reason my blackberry curve just started clearing all my text message history??? i've no idea why or how? in fact, i checked the history option and i have it set to keeping it for 6 months, before it was 3 months, but i never had the proble
-
Hi, I am working on BPC 10 NW and i have a doubt about the BPF functionality cause i have created a BPF template with several steps and every step has some hyperlinks. My doubt is: I supose the BPF should block the hyperlinks inside a step after it i
-
Deleting large amounts of data
All, I have several tables that have about 1 million plus rows of historical data that is no longer needed and I am considering deleting the data. I have heard that deleting the data will actually slow down performance as it will mess up the indexing
-
Iphone 5 connection to itunes. How do I get mac os x 10.6.8?
I have just got an iphone 5 and I tried to connect it to my itunes to sync it but it says I need version 10.6.8 I have tried to upgrade but it won't let me and my laptop is a macbook 2008 aluminium currently running on 10.5.8 Please help!