XML Type - ExtractValue for Nested Tables
Hi all,
PROCEDURE TESTING
IS
v_xml CLOB := '<EMPLOYEE><RECORD><EMPID>12</EMPID><EMPNAME>ROCK</EMPNAME></RECORD><RECORD><EMPID>13</EMPID>13<EMPNAME>PETER</EMPNAME></RECORD><RECORD><EMPID>14</EMPID><EMPNAME>JOHN</EMPNAME></RECORD></EMPLOYEE>';
BEGIN
FOR i IN
(SELECT EXTRACTVALUE (indv_xml, 'RECORD/EMPID') eid,EXTRACTVALUE (indv_xml, 'RECORD/EMPNAME') ename
FROM (SELECT VALUE (v) indv_xml
FROM (SELECT XMLTYPE (v_xml) main_xml
FROM DUAL),
TABLE
(XMLSEQUENCE
(EXTRACT
(main_xml,
'EMPLOYEE/RECORD'
) v))
LOOP
insert into employee values(eid,ename);
END LOOP;
END;
Now i have the xml like this:-
'<EMPLOYEE>
<EMPTYPE>
<TYPEID>121</TYPEID>
<ROW><EMPID>12</EMPID><EMPNAME>ROCK</EMPNAME></ROW>
<ROW><EMPID>13</EMPID>13<EMPNAME>PETER</EMPNAME></ROW>
</EMPTYPE>
<EMPTYPE>
<TYPEID>122</TYPEID>
<ROW><EMPID>14</EMPID><EMPNAME>JOHN</EMPNAME></ROW>
</EMPTYPE>
</EMPLOYEE>'
In this case, I have populate into two tables first EMP_TYPE (typeid - PK) and EMPLOYEE(EID,ENAME,TYPEID -FK)...
Pls provide me some sample code.
Thanks
Simbhu
Hi,
I have a similar requirement, where i need to extract a particular segment from an xml doc, but am getting errors:
The XML Doc is :
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<Code39Response> <Code39Result>iVBORw0KGgoAAAANSUhEUgAAAC0AAAAeCAYAAAC49JeZAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAO1JREFUWEftlgkOhTAIRPX+h3ZLaxCBMnWt0uQnml/Ikw5T+mFaXWtrhm5tda0BL8rQoCfFwN9jxXjzefaJZDnQk4B+Gbpfqoonx3+g52rkn1Rp67+8vybHGsuPiB8P8s5haaz2nCx3xbBynAZtadoL7c0hQtMj4888sVcCVA5Hc6jQaEcjx+6x15IcNz5dshrNBmugLbBLoHPjvEYe8BX4UAB+Vz8EumniFzDACFFpuGSVAd+qNB9oqE9Tu5P8W7pNpQGJe7w2RO3mI+uW0uACOlXNmnWi0nQWLukzNB2NaDRVyONT8qgcC24JGwGQIbYsvaAvwQAAAABJRU5ErkJggg==</Code39Result>
</Code39Response>
</soap:Body>
</soap:Envelope>
select XMLTYPE('<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<Code39Response> <Code39Result>iVBORw0KGgoAAAANSUhEUgAAAC0AAAAeCAYAAAC49JeZAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAO1JREFUWEftlgkOhTAIRPX+h3ZLaxCBMnWt0uQnml/Ikw5T+mFaXWtrhm5tda0BL8rQoCfFwN9jxXjzefaJZDnQk4B+Gbpfqoonx3+g52rkn1Rp67+8vybHGsuPiB8P8s5haaz2nCx3xbBynAZtadoL7c0hQtMj4888sVcCVA5Hc6jQaEcjx+6x15IcNz5dshrNBmugLbBLoHPjvEYe8BX4UAB+Vz8EumniFzDACFFpuGSVAd+qNB9oqE9Tu5P8W7pNpQGJe7w2RO3mI+uW0uACOlXNmnWi0nQWLukzNB2NaDRVyONT8qgcC24JGwGQIbYsvaAvwQAAAABJRU5ErkJggg==</Code39Result>
</Code39Response>
</soap:Body>
</soap:Envelope>') from dual
does NOT give any error. BUT
SELECT VALUE(v) xml_data
FROM (select XMLTYPE('<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<Code39Response>
<Code39Result>iVBORw0KGgoAAAANSUhEUgAAAC0AAAAeCAYAAAC49JeZAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAO1JREFUWEftlgkOhTAIRPX+h3ZLaxCBMnWt0uQnml/Ikw5T+mFaXWtrhm5tda0BL8rQoCfFwN9jxXjzefaJZDnQk4B+Gbpfqoonx3+g52rkn1Rp67+8vybHGsuPiB8P8s5haaz2nCx3xbBynAZtadoL7c0hQtMj4888sVcCVA5Hc6jQaEcjx+6x15IcNz5dshrNBmugLbBLoHPjvEYe8BX4UAB+Vz8EumniFzDACFFpuGSVAd+qNB9oqE9Tu5P8W7pNpQGJe7w2RO3mI+uW0uACOlXNmnWi0nQWLukzNB2NaDRVyONT8qgcC24JGwGQIbYsvaAvwQAAAABJRU5ErkJggg==</Code39Result>
</Code39Response>
</soap:Body>
</soap:Envelope>') main_xml from dual), TABLE(xmlsequence(extract(main_xml,'soap:Envelope/soap:Body/child::node()'))) v
Gives me the error below:
ORA-31011: XML Parsing Failed
ORA-19202: Error occured in XML Parsing
LPX-00601: Invalid token in '<soap:Envelope/soap:Body'
31011.00000 - "XML Parsing Failed"
Am i doing something wrong?
Thanks
Ashish
Similar Messages
-
Trigger how to get new and old value for nested table column?
Hi,
I have created a nested table based on the following details:
CREATE TYPE typ_item AS OBJECT --create object
(prodid NUMBER(5),
price NUMBER(7,2) )
CREATE TYPE typ_item_nst -- define nested table type
AS TABLE OF typ_item
CREATE TABLE pOrder ( -- create database table
ordid NUMBER(5),
supplier NUMBER(5),
requester NUMBER(4),
ordered DATE,
items typ_item_nst)
NESTED TABLE items STORE AS item_stor_tab
INSERT INTO pOrder
VALUES (800, 80, 8000, sysdate,
typ_item_nst (typ_item (88, 888)));
Now I would like to create a trigger on table pOrder for after insert or update or delete
and I would like to track the new and old value for the columns inside nested table.
Can anybody direct me how to do it?
I would like to know the sytax for it like:
declare
x number;
begin
x := :new.nestedtablecolumn;--how to get the new and old value from nested table columns
end;
Hope my question is clear.
Thanks,
LavanHi,
Try like this:
CREATE OR REPLACE TRIGGER PORDER_I
BEFORE INSERT
ON PORDER
REFERENCING OLD AS old NEW AS new
FOR EACH ROW
DECLARE
items_new typ_item_nst;
ordid_NEW NUMBER;
BEGIN
FOR i IN :new.items.FIRST .. :new.items.LAST LOOP -- For first to last element
DBMS_OUTPUT.PUT_LINE(':new.items(' || I || ').prodid: ' || :new.items(I).prodid );
DBMS_OUTPUT.PUT_LINE(':new.items(' || I || ').price: ' || :new.items(I).price );
END LOOP;
END;Regards,
Peter -
HOw to improve insert/update/select for nested table.
Hi All,
I think this is my second thread for nested table.
i just want to know what are the different ways available to improve the insert/update/select operation on Nested table.
Thanks in advance.By not using a nested table for data storage in the first place...
http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:8135488196597
Perhaps Parallel Query/DML might give some relief. -
MetaData for nested table type
in a nested table a column is of datatype "TYPE"
so how can i get metadata for this column..
if "OPTIONS" is a column of datatype "TYPE"
and it has 2 columns option_id and option_value
then when i'am trying to get
array.getBaseTypeName
m gettin TAB_TY_OPTION_DETAILS
like this only..
how can i get metadata for this datatype.
Thanks in advance.check out ResultSetMetaData
-
XML Query Performance on Nested Tables
I am running an Xpath query on an XMLTYPE column extracting rows from a nested table which is two levels down from the root element:
e.g.
select extractValue(x.xmldata,'/rootElement/VersionNumber') VerNumber
, etc...
, etc.
, extractValue(value(m),'/Member/Name/Ttl') Member_title
, to_char(extractValue(value(e),'/Event/EventDate'),'yyyy-mm-dd') Event_Date
, extractValue(value(e),'/Event/Type') Event_type
from xml_table x,
table(XMLSequence(extract(x.xmldata,'/rootElement/Member'))) m
,table(XMLSequence(extract(value(m),'/Member/Event'))) e
The query is taking around 7 minutes to process 2000 XML docs and the result returns 61,000 rows.
Statspack reports indicate that the main resource used is the LOBSEGMENT which supports the SYS_XDBPD$ column (system generated) in the Member nested table - result was over 100 million Logical Reads and Consistent Gets.
Is there any way to influence the Schema Registration/XML Table creation to result in the XDBPD$ column being stored as a Table or VARRAY - the underlying data type for XDBPD$ is:
XDB.XDB$RAW_LIST_T VARRAY(1000) OF RAW(2000)
OR
Should I spend time tuning access to the LOBSEGMENT?
Anyone tuned this area of XDB before??
Thanks
DaveDo you need DOM Fidelity at all. DOM Fidelity is typically only needed in a document orientated application or where items like processing instructions and comments are present and need to be maintaned.
Here are some notes from some training ppt slides that may help you decide
Dom Fidelity requires that XML DB track document level meta data
It creates overhead when inserting and retrieving XML due to processing as well as adding additional storage requirements. Dom Fidelity can be turned on and off at the 'Type' Level Each SQL Type corresponding to a complexType where DOM is enabled includes a System Binary attribute called SYS_XDBPD$. The SYS_XDBPD$ attribute is referred to as the Positional Descriptor (PD)
The PD is used to manage the instance level meta data. The format of the PD is not documented The PD is stored as a (in-line) LOB.
The PD is used to track
Comments and Processing Instructions
Location and Prefixes in Namespace declarations
Empty Vs Missing Nodes
Presence of Default Values
Use of Substitutable elements
Ordering of elements in all and choice models
XMLSchemaInstance attributes
xsi:nil, xsi:Type
Mixed content
Text() nodes that are interspaced with elements
Disabling DOM Fidelity improves performance
Reduces storage requirements
Reduces elapsed time for insert and retrieval operations
DOM Fidelity is disabled on a Type by Type basis
Use annotation xdb:maintainDOM="false on complexType definition
Specifying xdb:maintainDOM="false
Removes the PD attribute from the SQLType.
Causes the information managed in the PD to be discarded when shredding the XML document
In general you can disable DOM Fidelity when
All information is represented as simple content
Elements with text() node children and or attribute values
XML does not make use Mixed Text
No Comments or Processing Instructions
Applications do not need to differentiate between empty and missing elements
Applications do not differentiate between default Vs missing values
Order of elements in repeating Sequence, All and Choice models is not meaningful
Typically Data-Centric XML does not require DOM Fidelity while Document Centric XML does. With DOM Fidelity disabled retrieved documents will still be valid per the XML Schema
Order is preserved when repetition is specified at element or complexType level
Use annotation xdb:maintainOrder=false for slight performance improvement in this case that order is not required in these cases.
Order is not preserved when repetition is specified at the model level, eg on a Choice, Sequence or All containing multiple child elements.
Take the following document
<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XMLSPY v2004 rel. 4 U (http://www.xmlspy.com)-->
<dft:root xmlns:dft="domFidelityTest"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="domFidelityTest domFidelityExample">
<?SomePI SomeValue?>
<xxx:choice xmlns:xxx="domFidelityTest">
<!--SomeComment-->
<xxx:A>String</xxx:A>
<xxx:B>String</xxx:B>
<?Another PI SomeOtherValue?>
<xxx:C>String</xxx:C>
<xxx:A>String</xxx:A>
<!--Another Comment-->
<xxx:B>String</xxx:B>
<xxx:C xsi:nil="true"/>
</xxx:choice>
</dft:root>
With DOM Fidelity disabled it would come back as
<?xml version="1.0" encoding="WINDOWS-1252"?>
<!--Sample XML file generated by XMLSPY v2004 rel. 4 U (http://www.xmlspy.com)-->
<dft:root xmlns:dft="domFidelityTest testAttr="NotInOriginal">
<dft:choice>
<dft:A>String</dft:A>
<dft:A>String</dft:A>
<dft:B>String</dft:B>
<dft:B>String</dft:B>
<dft:C>String</dft:C>
<dft:C/>
</dft:choice>
</dft:root>
In general you can disable DOM Fidelity and see reduced storage requirements and increased throughout...
Hope this helps... -
Error while create trigger on for nested table
I want to insert a record into a nested table.For this, I created a view for the table, which includes the nested table.It told me ORA-25015 cannot perform DML on this nested table view column.So I created a trigger for the nested table.However, it told me that ORA-25010 Invalid nested table column name in nested table clause.I think my nested table is valid, i don't konw why did it appear this kind of problem?
My table is
CREATE TABLE ENT
ID NUMBER(7) NOT NULL,
CREATE_DATE VARCHAR2(11 BYTE),
UPDATE_DATE VARCHAR2(11 BYTE),
DEPTS VARRAY_DEPT_SEQ
CREATE OR REPLACE
TYPE DEPT AS OBJECT
ID NUMBER(8),
ANCHOR VARCHAR2(20),
CREATE OR REPLACE
TYPE " VARRAY_DEPT_SEQ" as varray(930) of DEPT
CREATE OR REPLACE VIEW ENT_NESTED_VIEW
(ID, CREATE_DATE, UPDATE_DATE, DEPTS)
AS
select e.ID,cast(multiset(select r.id,r.anchor from ent z, table(z.depts) r where z.ID=e.ID )as varray_dept_seq)
FROM ENT e
Then when I created trigger;
CREATE OR REPLACE TRIGGER EMP.ENT_NESTED_TRI
INSTEAD OF INSERT
ON NESTED TABLE DEPTS OF EMP.ENT_NESTED_VIEW
REFERENCING NEW AS New OLD AS Old PARENT AS Parent
FOR EACH ROW
BEGIN
END ;
I met the problem: ORA-25010 Invalid nested table column name in nested table clause
Could you please tell me the reason
Thank you!
My insert SQL is:
insert into table(select depts from ent_nested_view where id=1856) values(varray_dept_seq(dept(255687,'AF58743')))
Message was edited by:
user589751Hi,TongucY
Compared with the "Referencing Clause with Nested Tables" part of this reference -
http://psoug.org/reference/instead_of_trigger.html, I found the answer of this
quesion. That is "CREATE OR REPLACE TYPE " VARRAY_DEPT_SEQ" as[b] varray(930) of
DEPT". It turns to be a varying array, not a nested table. It should be "CREATE OR
REPLACE TYPE " VARRAY_DEPT_SEQ" as table of DEPT". That is OK. Thank you very
much!
While there is an another question, if I create a varying array like" CREATE OR
REPLACE TYPE " VARRAY_DEPT_SEQ" as[b] varray(930) of DEPT " and I want to insert
a record into the varying array, which the record has been existed.The method that
create a view and a trigger seems not to be effective.
For instance,
There is a record in the table
ID:1020
CREATE_DATE:2005-10-20
UPDATE_DATE:2007-2-11
DETPS: ((10225,AMY))
I want to ask this record to be
ID:1020
CREATE_DATE:2005-10-20
UPDATE_DATE:2007-2-11
DETPS: ((10225,AMY),(10558,TOM))
How should I do?
Could you please help me?
Best regards.
Message was edited by:
user589751 -
Public Synonyms for Nested Tables - Insertion Problem
Hi,
we are facing a problem during implementation. Our DB set up
is , we will be having two schema named OWNR and COPY.
In the schema, OWNR we have to create all the tables,
types,procedures, packages and obj.....This schema will have
both DDL and DML privileges.
In the schema, COPY we are not supposed to create any tables,
objects. We have to create public synonyms for all the tables,
types, procedures... in OWNR and grant ALL privilege to the
schema COPY.The schema, COPY will have only DML privileges.
The problem is we have some nested tables in our application.
When I try to insert into the synonym which is created for the
nested table, it is not allowing me to insert..The whole
implementation is stucked..Please help.The scripts are given
below.......
We have a type name SITA_ADDRESS_TY which is used by the nested
table SITA_ADDRESSES_NT.Script used for creating the Type,Nested
table,Table, Public Synonym and granting all privilege to these
types and tables are
CREATE OR REPLACE TYPE SITA_ADDRESS_TY AS OBJECT (
SITA_ADDRESS VARCHAR2(10),
REMARKS VARCHAR2(100)) ;
PROMPT SITA_ADDRESSS_NT...
CREATE OR REPLACE TYPE SITA_ADDRESSES_NT AS TABLE OF
SITA_ADDRESS_TY ;
Using this nested table we have created the table,
UMS_SITA_ADDRESS
CREATE TABLE UMS_SITA_ADDRESS (
COMPANY_CODE VARCHAR2 (6) NOT NULL,
AIRLINE_CODE VARCHAR2 (6) NOT NULL,
DESTINATION VARCHAR2 (6) NOT NULL,
SITA_ADDRESS SITA_ADDRESSES_NT)
TABLESPACE EKUMDAT
PCTFREE 5
PCTUSED 40
INITRANS 1
MAXTRANS 255
STORAGE (
INITIAL 64K
NEXT 64K
PCTINCREASE 0
MINEXTENTS 1
MAXEXTENTS 505
FREELISTS 1 FREELIST GROUPS 1 )
NOCACHE
NESTED TABLE SITA_ADDRESS STORE AS UMSNT_SITA_ADDRESS ;
PROMPT SYNONYM SITA_ADDRESS_TY...
CREATE PUBLIC SYNONYM SITA_ADDRESS_TY FOR SITA_ADDRESS_TY
PROMPT SYNONYM SITA_ADDRESSES_NT...
CREATE PUBLIC SYNONYM SITA_ADDRESSES_NT FOR SITA_ADDRESSES_NT
PROMPT UMS_SITA_ADDRESS...
CREATE PUBLIC SYNONYM UMS_SITA_ADDRESS FOR UMS_SITA_ADDRESS
Granting Privileges
PROMPT SITA_ADDRESS_TY...
GRANT EXECUTE ON SITA_ADDRESS_TY TO COPY
PROMPT SITA_ADDRESSS_NT...
GRANT EXECUTE ON SITA_ADDRESSES_NT TO COPY
PROMPT UMS_SITA_ADDRESS...
GRANT ALL ON UMS_SITA_ADDRESS TO COPY
When I connect to copy and desc UMS_SITA_ADDRESS, the structure
is
SQL> desc ums_sita_address
Name Null? Type
COMPANY_CODE NOT NULL VARCHAR2(6)
AIRLINE_CODE NOT NULL VARCHAR2(6)
DESTINATION NOT NULL VARCHAR2(6)
SITA_ADDRESS
OWNR.SITA_ADDRESSES_NT
Why is it so??. Even though I have a synonym for
SITA_ADDRESSES_NT, it is not referencing the synonym but instead
refer the OWNR.SITA_ADDRESSES_NT
Because of this when I try to insert into ums_sita_address(in
schema COPY), it is giving the following error,
SQL> insert into ums_sita_address values
('EK','EK','DXB',SITA_ADDRESSES_NT());
insert into ums_sita_address values
('EK','EK','DXB',SITA_ADDRESSES_NT())
ERROR at line 1:
ORA-00932: inconsistent datatypes
But when the same connect to OWNR and try to insert with the
same stmt, it is inserting...
Our middle tier can connect only to COPY schema alone..Is there
anything to be done in the DBA side to achieve this??.
Please help from your valuabe experience...Or can you ask your
collegues if they have got a soln to this probs..Our
implementation team is stucked with this...
Thanks
PriyaHi
I am not sure but maybe you need to use this command:
SQL> insert into ums_sita_address values
('EK','EK','DXB',SITA_ADDRESSES_TY());
SITA_ADDRESSES_TY() instead SITA_ADDRESSES_NT
Regards -
Public Synonyms for Nested Tables - Insertion Problem - Please Help!!!!!
Hi,
we are facing a problem during implementation. Our DB set up
is , we will be having two schema named OWNR and COPY.
In the schema, OWNR we have to create all the tables,
types,procedures, packages and obj.....This schema will have
both DDL and DML privileges.
In the schema, COPY we are not supposed to create any tables,
objects. We have to create public synonyms for all the tables,
types, procedures... in OWNR and grant ALL privilege to the
schema COPY.The schema, COPY will have only DML privileges.
The problem is we have some nested tables in our application.
When I try to insert into the synonym which is created for the
nested table, it is not allowing me to insert..The whole
implementation is stucked..Please help.The scripts are given
below.......
We have a type name SITA_ADDRESS_TY which is used by the nested
table SITA_ADDRESSES_NT.Script used for creating the Type,Nested
table,Table, Public Synonym and granting all privilege to these
types and tables are
CREATE OR REPLACE TYPE SITA_ADDRESS_TY AS OBJECT (
SITA_ADDRESS VARCHAR2(10),
REMARKS VARCHAR2(100)) ;
PROMPT SITA_ADDRESSS_NT...
CREATE OR REPLACE TYPE SITA_ADDRESSES_NT AS TABLE OF
SITA_ADDRESS_TY ;
Using this nested table we have created the table,
UMS_SITA_ADDRESS
CREATE TABLE UMS_SITA_ADDRESS (
COMPANY_CODE VARCHAR2 (6) NOT NULL,
AIRLINE_CODE VARCHAR2 (6) NOT NULL,
DESTINATION VARCHAR2 (6) NOT NULL,
SITA_ADDRESS SITA_ADDRESSES_NT)
TABLESPACE EKUMDAT
PCTFREE 5
PCTUSED 40
INITRANS 1
MAXTRANS 255
STORAGE (
INITIAL 64K
NEXT 64K
PCTINCREASE 0
MINEXTENTS 1
MAXEXTENTS 505
FREELISTS 1 FREELIST GROUPS 1 )
NOCACHE
NESTED TABLE SITA_ADDRESS STORE AS UMSNT_SITA_ADDRESS ;
PROMPT SYNONYM SITA_ADDRESS_TY...
CREATE PUBLIC SYNONYM SITA_ADDRESS_TY FOR SITA_ADDRESS_TY
PROMPT SYNONYM SITA_ADDRESSES_NT...
CREATE PUBLIC SYNONYM SITA_ADDRESSES_NT FOR SITA_ADDRESSES_NT
PROMPT UMS_SITA_ADDRESS...
CREATE PUBLIC SYNONYM UMS_SITA_ADDRESS FOR UMS_SITA_ADDRESS
Granting Privileges
PROMPT SITA_ADDRESS_TY...
GRANT EXECUTE ON SITA_ADDRESS_TY TO COPY
PROMPT SITA_ADDRESSS_NT...
GRANT EXECUTE ON SITA_ADDRESSES_NT TO COPY
PROMPT UMS_SITA_ADDRESS...
GRANT ALL ON UMS_SITA_ADDRESS TO COPY
When I connect to copy and desc UMS_SITA_ADDRESS, the structure
is
SQL> desc ums_sita_address
Name Null? Type
COMPANY_CODE NOT NULL VARCHAR2(6)
AIRLINE_CODE NOT NULL VARCHAR2(6)
DESTINATION NOT NULL VARCHAR2(6)
SITA_ADDRESS
OWNR.SITA_ADDRESSES_NT
Why is it so??. Even though I have a synonym for
SITA_ADDRESSES_NT, it is not referencing the synonym but instead
refer the OWNR.SITA_ADDRESSES_NT
Because of this when I try to insert into ums_sita_address(in
schema COPY), it is giving the following error,
SQL> insert into ums_sita_address values
('EK','EK','DXB',SITA_ADDRESSES_NT());
insert into ums_sita_address values
('EK','EK','DXB',SITA_ADDRESSES_NT())
ERROR at line 1:
ORA-00932: inconsistent datatypes
But when the same connect to OWNR and try to insert with the
same stmt, it is inserting...
Our middle tier can connect only to COPY schema alone..Is there
anything to be done in the DBA side to achieve this??.
Please help from your valuabe experience...Or can you ask your
collegues if they have got a soln to this probs..We are stucked
with this...
Thanks
PriyaHi
I am not sure but maybe you need to use this command:
SQL> insert into ums_sita_address values
('EK','EK','DXB',SITA_ADDRESSES_TY());
SITA_ADDRESSES_TY() instead SITA_ADDRESSES_NT
Regards -
ROWNUM equivalent for Nested Tables?
Is there an equivalent to the ROWNUM pseudocolumn for a nested table such that something like this...
WITH driver_data AS
(SELECT 1 AS id, sys.dbms_debug_vc2coll('a','b','c') AS val FROM dual
UNION ALL
SELECT 2 AS id, sys.dbms_debug_vc2coll('x','y','z') AS val FROM dual)
SELECT t1.id,
--t2.rownum as pos,
t2.column_value AS val
FROM driver_data t1,
TABLE(t1.val) t2 ;
ID VAL
1 a
1 b
1 c
2 x
2 y
2 z...would return something like this...
ID VAL POS
1 a 1
1 b 2
1 c 3
2 x 1
2 y 2
2 z 3ABB wrote:
But the OP now has two collections per row of data, not one, as he showed above, so it becomes more complicated.Yes, it does. But still solvable:
with t1 as (
select t1.*,
rownum rn_main
from driver_data t1
t2 as (
select id,
val1,
rn_main,
row_number() over(partition by rn_main order by rn_nested) pos
from (
select id,
column_value val1,
rn_main,
rownum rn_nested
from t1,
table(val1)
t3 as (
select id,
val2,
rn_main,
row_number() over(partition by rn_main order by rn_nested) pos
from (
select id,
column_value val2,
rn_main,
rownum rn_nested
from t1,
table(val2)
select nvl(t2.id,t3.id) id,
val1,
val2,
nvl(t2.pos,t3.pos) pos
from t2 full outer join t3 on t2.rn_main = t3.rn_main and t2.pos = t3.pos
order by nvl(t2.rn_main,t3.rn_main),
nvl(t2.pos,t3.pos)
SQL> create table driver_data(
2 id number,
3 val1 sys.dbms_debug_vc2coll,
4 val2 sys.dbms_debug_vc2coll
5 )
6 nested table val1 store as val1_tbl,
7 nested table val2 store as val2_tbl
8 /
Table created.
SQL> insert
2 into driver_data
3 SELECT 1 id,
4 sys.dbms_debug_vc2coll('c','b','a') val1,
5 sys.dbms_debug_vc2coll('k','u') val2
6 FROM dual
7 UNION ALL
8 SELECT 2 id,
9 sys.dbms_debug_vc2coll('z','y','x') val1,
10 sys.dbms_debug_vc2coll('n','e','j','t') val2
11 FROM dual
12 UNION ALL
13 SELECT 1 id,
14 sys.dbms_debug_vc2coll('c','b','a') val1,
15 sys.dbms_debug_vc2coll('k','u') val2
16 FROM dual
17 UNION ALL
18 SELECT 2 id,
19 sys.dbms_debug_vc2coll('z','y','x') val1,
20 sys.dbms_debug_vc2coll('n','e','j','t') val2
21 FROM dual
22 /
4 rows created.
SQL> commit
2 /
Commit complete.
SQL> column val1 format a10
SQL> column val2 format a10
SQL> with t1 as (
2 select t1.*,
3 rownum rn_main
4 from driver_data t1
5 ),
6 t2 as (
7 select id,
8 val1,
9 rn_main,
10 row_number() over(partition by rn_main order by rn_nested) pos
11 from (
12 select id,
13 column_value val1,
14 rn_main,
15 rownum rn_nested
16 from t1,
17 table(val1)
18 )
19 ),
20 t3 as (
21 select id,
22 val2,
23 rn_main,
24 row_number() over(partition by rn_main order by rn_nested) pos
25 from (
26 select id,
27 column_value val2,
28 rn_main,
29 rownum rn_nested
30 from t1,
31 table(val2)
32 )
33 )
34 select nvl(t2.id,t3.id) id,
35 val1,
36 val2,
37 nvl(t2.pos,t3.pos) pos
38 from t2 full outer join t3 on t2.rn_main = t3.rn_main and t2.pos = t3.pos
39 order by nvl(t2.rn_main,t3.rn_main),
40 nvl(t2.pos,t3.pos)
41 /
ID VAL1 VAL2 POS
1 c k 1
1 b u 2
1 a 3
2 z n 1
2 y e 2
2 x j 3
2 t 4
1 c k 1
1 b u 2
1 a 3
2 z n 1
ID VAL1 VAL2 POS
2 y e 2
2 x j 3
2 t 4
14 rows selected.
SQL> SY. -
Hi ,
I have a function which returns nested table as result .The nested table can sometimes be null.So when i reference the first and last value for a loop, when table is null , then i am getting numeric value error .So i added a check on the nested table as below
if n_table is empty then
exit;
end if;
for i in n_table.first ..n_table.last
loop
select count(1) into_count
from x where rate=n_table(i);
end loop;
Now iam getting a message as" DANGLING NOT NULL OF".Though it gets compiled .iam getting everytime when i first compile it .Please let me know what should i add to prevent thisNull and empty are two different things. Also please post the complete error message.
Notice the difference between
DECLARE
v_tab INTEGER_TT;
BEGIN
IF v_tab IS NOT NULL THEN
FOR i IN v_tab.FIRST..v_tab.LAST LOOP
DBMS_OUTPUT.PUT_LINE('Loop iteration ' || i);
END LOOP;
END IF;
END;and
DECLARE
v_tab INTEGER_TT := INTEGER_TT();
BEGIN
IF v_tab IS NOT EMPTY THEN
FOR i IN v_tab.FIRST..v_tab.LAST LOOP
DBMS_OUTPUT.PUT_LINE('Loop iteration ' || i);
END LOOP;
END IF;
END; -
Creating a type having a nested table of that type !!!!!
Hi all, my question may look ambigious, but it's better understood by this example: How can i do this??
CREATE TYPE MaterialType AS OBJECT (
MaterialID NUMBER,
MaterialName varchar2(20),
CompatibleMaterials MaterialsNT
CREATE TYPE MaterialsNT AS TABLE OF REF MaterialType;
In other words, how can i create 'MaterialType', having as attribute 'CompatibleMaterials', which is a nested table of 'MaterialType'why don't you try nested tables?
prem -
Message split for nested tables
Hi all,
within PI 7.1 I want to split a message into multiple messages. But unfortunately using functions "UseOneAsMany" or "Concat" alone do not help me at all.
I think I need to combine this some how...
My source message has simplified following structure (including cardinality in brackets):
<OrderIn (1..1)>
<OrderData (1..n)>
<OrderDetails (1..1)>
<OrderNumber (1..1)></OrderNumber>
<Customer (1..1)></Customer>
</OrderDetails>
<DistirbutionRules (1..n)>
<Rule (1..1)></Rule>
<Description (1..1)></Description>
</DistirbutionRules>
</OrderData>
<TargetSystem (1..1)>
<SystemID (1..n)></SystemID>
</TargetSystem>
</OrderIn>
My target message has simplified following structure (including cardinality in brackets):
<OrderOut (1..n)>
<OrderData (1..n)>
<TargetSystem (1..1)></TargetSystem>
<OrderDetails (1..1)>
<OrderNumber (1..1)></OrderNumber>
<Customer (1..1)></Customer>
</OrderDetails>
<DistirbutionRules (1..n)>
<Rule (1..1)></Rule>
<Description (1..1)></Description>
</DistirbutionRules>
</OrderData>
</OrderOut>
So as incomming message I can have multiple orders and multiple target systems.
As result of the mapping I need one message per target system including all orders in the message.
As long as I have only one Order (OrderData) within the message and only one DistributionRule I can work with function UseOneAsMany as described.
But as soon as more than one Order or DistributionRule is defined I get a conversion error "Too many values in the first queue in function useOneAsMany".
Here the UseOneAsMany mapping (as Text Preview):
/ns0:Messages/ns0:Message1/ns1:RJ_SalesOrderOut/OrderData=SplitByValue(useOneAsMany(/ns0:Messages/ns0:Message1/ns1:RJ_SalesOrderIn/OrderData, /ns0:Messages/ns0:Message1/ns1:RJ_SalesOrderIn/TargetSystem/SystemID, /ns0:Messages/ns0:Message1/ns1:RJ_SalesOrderIn/TargetSystem/SystemID, result), type=0)
When I use only the Concat function I get no error even if I have multiple OrderData but only the first OrderData or DistributionRule is mapped to the target structure.
Here the Concat mapping (as Text Preview):
/ns0:Messages/ns0:Message1/ns1:OrderOut/OrderData=SplitByValue(concat(/ns0:Messages/ns0:Message1/ns1:OrderIn/OrderData, ifWithoutElse(exists(/ns0:Messages/ns0:Message1/ns1:OrderIn/TargetSystem/SystemID), const(value=), keepss=false), delimeter=), type=0)
regards
RenéHi Damian,
have a look at the hierarchy. Within the Source Structure "TargetSystem" and "OrderData" are independent from each other. To get the target messages I want to copy the whole "OrderData" table as many times as I have target systems. Like:
<OrderIn>
<OrderData>
<OrderDetails>
<OrderNumber>1</OrderNumber>
<Customer>Cust1</Customer>
</OrderDetails>
<DistirbutionRules>
<Rule>Rule1</Rule>
<Description>Desc1</Description>
</DistirbutionRules>
</OrderData>
<OrderData>
<OrderDetails>
<OrderNumber>2</OrderNumber>
<Customer>Cust2</Customer>
</OrderDetails>
<DistirbutionRules>
<Rule>Rule2</Rule>
<Description>Desc2</Description>
</DistirbutionRules>
</OrderData>
<TargetSystem>
<SystemID>A</SystemID>
<SystemID>B</SystemID>
</TargetSystem>
</OrderIn>
After mapping and splitting I want to get:
<OrderOut>
<OrderData>
<TargetSystem>A</TargetSystem>
<OrderDetails>
<OrderNumber>1</OrderNumber>
<Customer>Cust1</Customer>
</OrderDetails>
<DistirbutionRules>
<Rule>Rule1</Rule>
<Description>Desc1</Description>
</DistirbutionRules>
</OrderData>
<OrderData>
<TargetSystem>A</TargetSystem>
<OrderDetails>
<OrderNumber>2</OrderNumber>
<Customer>Cust2</Customer>
</OrderDetails>
<DistirbutionRules>
<Rule>Rule2</Rule>
<Description>Desc2</Description>
</DistirbutionRules>
</OrderData>
</OrderOut>
<OrderOut>
<OrderData>
<TargetSystem>B</TargetSystem>
<OrderDetails>
<OrderNumber>1</OrderNumber>
<Customer>Cust1</Customer>
</OrderDetails>
<DistirbutionRules>
<Rule>Rule1</Rule>
<Description>Desc1</Description>
</DistirbutionRules>
</OrderData>
<OrderData>
<TargetSystem>B</TargetSystem>
<OrderDetails>
<OrderNumber>2</OrderNumber>
<Customer>Cust2</Customer>
</OrderDetails>
<DistirbutionRules>
<Rule>Rule2</Rule>
<Description>Desc2</Description>
</DistirbutionRules>
</OrderData>
</OrderOut>
regards
René -
OCI doc says Cursor and Nested table have the same bind type SQLT_RSET but they don't
5 Binding and Defining in OCI
PL/SQL REF CURSORs and Nested Tables in OCI
says SQLT_RSET is passed for the dty parameter.
If I use SQLT_RSET for the return value of a function that returns a table and pass a statement handle's address for the OCI parameter data pointer, I expected that the statement handle will be instantiated as a result of executing the function on which I can further perform fetch, similar to a cursor. But it throws exception PLS-00382: expression is of wrong type ORA-06550: line 2, column 3. Is the above documentation wrong?
From the OCI header file I see that for varray and nested table it mentions to use SQLT_NCO. I could find no example in the OCI documentation on how to pass or receive as return value a nested value when using SQLT_NCO.
Please help before I shoot myself.So the Nested table I quoted in the doc is not actually used to mean a table type below?
create type t_resultsetdata as object (
i int, d decimal, c varchar(10)
create type t_nested_resultsetdata as table of t_resultsetdata;
create function Blah return t_nested_resultsetdata is . . .
For this you are saying to use SQL_NTY and not SQL_NCO. Can you tell where this usage is documented, because ocidfn.h says
#define SQLT_NTY 108
/* named object type */
#define SQLT_NCO 122
/* named collection type (varray or nested table) */
Another question - Because of the original document I said I followed, I thought I could treat cursor and nested table similarly in the calling application, i.e. I could repeatedly do a fetch on the OCIStmt* which will be bound for nested table. Now from what you say I understand I can't really bind a OCIStmt* for nested table but have an object type. That means it will get all the data of that collection in one go, right? LIke I said, lack of examples is making this tough. I don't want to look into OCI source code, as that will be too much. -
Type attribute with Object type or Nested table?
I have been creating lot many threads around the same problem, however i thought i knew but realized I do not know or else do not know how to..
I have created object type with an attribute READINGVALUE NUMBER(21,6)...How can i use type attribute on this object while declaring variable.....can we use type attribute on NESTED TABLES, similar to the db tables?
example
CREATE TYPE READING AS OBJECT(READINGVALUE NUMBER(21,6));
CREATE TABLE INTERVALREADINGS OF TYPE READING;meghavee wrote:
Thanks Solomon, however this approach does not preserve precision/scale of number data type.....What you can do is create placeholder tables:
SQL> create table reading_type_placeholder of reading
2 /
Table created.
SQL> desc reading_type_placeholder
Name Null? Type
READINGVALUE NUMBER(21,6)
SQL> declare
2 v_var reading_type_placeholder.readingvalue%type;
3 begin
4 v_var := 123456789012345;
5 end;
6 /
PL/SQL procedure successfully completed.
SQL> declare
2 v_var reading_type_placeholder.readingvalue%type;
3 begin
4 v_var := 1234567890123456;
5 end;
6 /
declare
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: number precision too large
ORA-06512: at line 4
SQL>And if you modify type attribute:
SQL> alter type reading modify attribute readingvalue number(26,6) cascade;
Type altered.
SQL> desc reading_type_placeholder
Name Null? Type
READINGVALUE NUMBER(26,6)
SQL>SY. -
Hello, I'm trying to insert to nested table xml clob using DBMS_XMLSave.insertXML.
But xsu inserts to nested table for each row the same data !
Are there any limitation to use DBMS_XMLSave.insertXML for nested table ?
This is the xml I'm trying to insert, table dept have the same structure as xml with nested table emplist.
(xml is generated with DBMS_XMLQuery ...,)
| <ROWSET>
| <ROW num="1">
| <DEPTNO>1</DEPTNO>
| <EMPLIST>
| <EMPLIST_ITEM>
| <EMPNO>1</EMPNO>
| <ENAME>pkdahle</ENAME>
| <SALARY>10</SALARY>
| <EMPADDR>
| <STREET>u</STREET>
| <CITY>c</CITY>
| <STATE>s </STATE>
| <ZIP>z</ZIP>
| </EMPADDR>
| </EMPLIST_ITEM>
| <EMPLIST_ITEM>
| <EMPNO>2</EMPNO>
| <ENAME>pkahle2</ENAME>
| <SALARY>101</SALARY>
| <EMPADDR>
| <STREET>us</STREET>
| <CITY>cc</CITY>
| <STATE>sc</STATE>
| <ZIP>zc</ZIP>
| </EMPADDR>
| </EMPLIST_ITEM>
| </EMPLIST>
| </ROW>
| <ROW num="2">
| <DEPTNO>2</DEPTNO>
| <EMPLIST>
| <EMPLIST_ITEM>
| <EMPNO>1</EMPNO>
| <ENAME>pkdahle</ENAME> -- this won't be saved in emplist (ename form previous row num=1 will be saved)
| <SALARY>10</SALARY>
| <EMPADDR>
| <STREET>u</STREET>
| <CITY>c</CITY>
| <STATE>s </STATE>
| <ZIP>z</ZIP>
| </EMPADDR>
| </EMPLIST_ITEM>
| <EMPLIST_ITEM>
| <EMPNO>2</EMPNO>
| <ENAME>pkahle2</ENAME>
| <SALARY>101</SALARY>
| <EMPADDR>
| <STREET>us</STREET>
| <CITY>cc</CITY>
| <STATE>sc</STATE>
| <ZIP>zc</ZIP>
| </EMPADDR>
| </EMPLIST_ITEM>
| </EMPLIST>
| </ROW>
| </ROWSET>
Thank'sI've created a simple example :
1.Create types and table.
2.Fill table with sample data
3.Run queryCtx := DBMS_XMLQuery.newContext('select * from TestTable'); to generate XML
4.delete testtable
5.Run rows := DBMS_XMLSave.insertXML(insCtx,xmlDoc); with the generated xml.
6.The table testtable will have 2 rows with the same 1 row collection xlist !!!
CREATE OR REPLACE TYPE Test_Type
AS OBJECT (
x number
create or replace type Test_List_Type as table of Test_Type
create table TestTable (
XX number,
XLIst Test_List_Type
nested table XLIst store as TestTable_XLIst_NEST
insert into
testtable
(xx,xlist)
values
(1,Test_List_Type (test_type(10)))
insert into
testtable
(xx,xlist)
values
(1,Test_List_Type (test_type(10)))
insert into
testtable
(xx,xlist)
values
(2,Test_List_Type (test_type(20),test_type(21),test_type(22),test_type(23)))
script to insert xml
declare
insCtx DBMS_XMLSave.ctxType;
rows number;
xmldoc clob;
-- xxslt clob;
begin
select cclob into xmldoc from cc.ka_clob; -- (I've stored xml in this table)
insCtx := DBMS_XMLSave.newContext('testtable'); -- get the context handle
DBMS_XMLSave.Setignorecase(insctx,1);
rows := DBMS_XMLSave.insertXML(insCtx,xmlDoc); -- this inserts the document
DBMS_XMLSave.closeContext(insCtx); -- this closes the handle
commit;
end;
Maybe you are looking for
-
Message coming up saying calendar can't find server
I keep getting this error message. It says the calendar might be pretending. What should I do?
-
Takes a long time when waiting for plsq: package_name. while editing
Hallo, in APPS-Environment we have over 30.000 Packages. When editing plsql code an trying to write a package.function call , sql-developer tries to display the available functions and procedures for the given package after typing the "DOT" and displ
-
Qualified Table (Bank Details) Import Question
I am using MDM 5.5 SP6 I am using the Standard SAP delivered Vendor Master Repository and trying to load the Qualified Bank Details table. Bank Details qualified table we have 9 non-qualified fields and 6 qualified fields. Do we need to load the non-
-
I have a select list on Page 0 (so it shows on all my pages). When the users makes a selection from the list, I want to re-display the current page, passing the selected value (used in my fetch condition). I see there are several options for select l
-
Problem installing FlexBuilder Plugin for Eclipse
I'm trying to install the latest Flex Builder plugin under Eclipse 3.4 under Mac OSX. I installed the plugin per the Adobe instructions, added the folder to the "List of Available Software" in the Eclipse dialog for managing plugins, then tried to in