Inserting nested records from XML to DB
Hi,
I am facing a problem with inserting nested records in XML to DB. For example, I have this XML:
<?xml version="1.0" encoding="utf-8" ?>
<ns0:CutLOTUpdate xmlns:ns0="http://LayoutTracking/v1.0">
<C>1</C>
<COMMENTS>Main1</COMMENTS>
<CUT_DATA>
<CUT>
<D>1</D>
<COMMENTS>2Main1</COMMENTS>
<IT>
<E>11</E>
<COMMENTS>3Det1</COMMENTS>
</IT>
<IT>
<E>12</E>
<COMMENTS>3Det2</COMMENTS>
</IT>
</CUT>
<CUT>
<D>2</D>
<COMMENTS>2Main2</COMMENTS>
<IT>
<E>21</E>
<COMMENTS>3Det1</COMMENTS>
</IT>
<IT>
<E>22</E>
<COMMENTS>3Det2</COMMENTS>
</IT>
</CUT>
</CUT_DATA>
</ns0:CutLOTUpdate>
I would like to insert these data into the following table in a denormalized form:
CREATE TABLE A (
C NUMBER,
D NUMBER,
E NUMBER,
C_COMMENTS VARCHAR2(50),
D_COMMENTS VARCHAR2(50),
E_COMMENTS VARCHAR2(50))
I have tried using this procedure:
CREATE OR REPLACE PROCEDURE insc (Cut_Clob CLOB) AS
Cut XMLType;
BEGIN
/*Converts Cut_Clob parameter into XML */
Cut := sys.xmltype.createXML(Cut_Clob);
/*Inserts data from XML to table*/
INSERT INTO a
( C ,
C_COMMENTS ,
D ,
D_COMMENTS ,
E ,
E_COMMENTS )
SELECT DISTINCT
ExtractVALUE(CUT, '/ns0:CutLOTUpdate/C' , 'xmlns:ns0="http://LayoutTracking/v1.0') C,
ExtractValue(CUT, '/ns0:CutLOTUpdate/COMMENTS', 'xmlns:ns0="http://LayoutTracking/v1.0') C_COMMENTS,
ExtractVALUE(value(ct), '/CUT/D') D,
ExtractValue(value(ct), '/CUT/D_COMMENTS') D_COMMENTS,
ExtractVALUE(value(it), '/IT/E') E,
ExtractValue(value(it), '/IT/E_COMMENTS') E_COMMENTS
FROM TABLE (xmlsequence(extract(CUT,'/ns0:CutLOTUpdate/CUT_DATA/CUT','xmlns:ns0="http://LayoutTracking/v1.0'))) ct,
TABLE (xmlsequence(extract(CUT,'/ns0:CutLOTUpdate/CUT_DATA/CUT/IT','xmlns:ns0="http://LayoutTracking/v1.0'))) it;
COMMIT;
END;
However, this resulted into a cartesian product.
Is it possible for me to insert this XML into such table? If yes, can anyone show me how?
I apologize if this seems trivial to you and I appreciate your time for helping me.
Thank you,
Kaye
Hi,
I have tried:
FROM TABLE (xmlsequence(extract(CUT,'/ns0:CutLOTUpdate/CUT_DATA/CUT','xmlns:ns0="http://LayoutTracking/v1.0'))) ct,
TABLE (xmlsequence(extract(CUT,'/ns0:CutLOTUpdate/CUT_DATA/CUT/IT','xmlns:ns0="http://LayoutTracking/v1.0'))) it;
This did not work - resulting in Cartesian product.
I am working with Oracle 10g DB 10.2.0.1.
If it's not too much, I am hoping that someone could show me a script to parse this XML and actually place it in a denormalized form.
If you think this is not possible, can you please just point me to an example where the same XML (with nested information) can be inserted into 3 different tables (relational)?
I have tried searching on different sources, to no avail. I am a beginner on this... I apologize for any inconveniece caused.
Similar Messages
-
Insert the record from XML file to Tables.
Hi guys,
I ill be getting the XML file from FRONT-END.It ill be stored one permanent location(Directory).I need to Insert the data to the corresponding table.Anybody knows Pls give some suggestion for this.......
Regards....
GKMUsing the Oracle XML DB Webdav are is one method as it acts like a file system, but essentially get's the documents directly into the database so they can be queried through the resouce_view.
Other methods involve reading the file as if it's a CLOB and then using XMLTYPE constructor to change that CLOB to an XMLTYPE which can then be stored as that datatype in the database or processed as you need.
The best place to look is over in the XML DB forum, which has it's own FAQ detailing various best practices for all sort of XML stuff, including reading XML files and shredding them into relational tables etc.
{thread:id=410714}
Edited by: BluShadow on 18-Jan-2012 08:53
corrected link -
How to insert the data from XML to a table
Hi,
I'm using Oracle 10g Express Edition
I need help in How to insert the data from XML file into the table.
Below is the example i'm working on..
I have create ridb user with below mentioned privileges:
Account Status Locked Unlocked
Default Tablespace: USERS
Temporary Tablespace: TEMP
User Privileges :
Roles:
CONNECT
RESOURCE
Direct Grant System Privileges:
CREATE DATABASE LINK
CREATE MATERIALIZED VIEW
CREATE PROCEDURE
CREATE PUBLIC SYNONYM
CREATE ROLE
CREATE SEQUENCE
CREATE SYNONYM
CREATE TABLE
CREATE TRIGGER
CREATE TYPE
CREATE VIEW
& table is created TRIALZIPCODES below mentioned is the DDL:
CREATE TABLE TRIALZIPCODES
STATE_ABBR VARCHAR2(20) NOT NULL
, ZIP_CODE NUMBER(10, 0) NOT NULL
, ZIP_CODE_EXT VARCHAR2(20)
Below is the XML FILE: which is stored in C:\OracleProject Folder
File name: trial.xml
<?xml version="1.0" ?>
<metadata>
- <Zipcodes>
- <mappings Record="4">
<STATE_ABBREVIATION>CA</STATE_ABBREVIATION>
<ZIPCODE>94301</ZIPCODE>
</mappings>
- <mappings Record="5">
<STATE_ABBREVIATION>CO</STATE_ABBREVIATION>
<ZIPCODE>80323</ZIPCODE>
<ZIP_CODE_EXTN>9277</ZIP_CODE_EXTN>
</mappings>
</Zipcodes>
</metadata>
PL/SQL Procedure:which i'm trying to execute from SQLDeveloper
create or replace
PROCEDURE TRIAL AS
BEGIN
DECLARE
-- declare attributes
charString varchar2(80);
finalStr varchar2(4000) := null;
rowsp integer;
v_FileHandle UTL_FILE.FILE_TYPE;
l_context_handle dbms_xmlgen.ctxHandle;
insCtx DBMS_XMLStore.ctxType;
begin
-- DBMS_XMLGEN.setRowTag ( ctx IN ctxHandle, rowTag IN VARCHAR2);
-- DBMS_XMLGEN.setRowSetTag ( ctx IN ctxHandle, rowSetTag IN VARCHAR2);
-- the name of the table as specified in our DTD
DBMS_XMLGEN.SETROWSETTAG(l_context_handle,'zipcodes');
-- the name of the data set as specified in our DTD
DBMS_xmlgen.setRowTag(l_context_handle,'mappings');
-- for getting the output on the screen
dbms_output.enable(1000000);
-- open the XML document in read only mode
v_FileHandle := utl_file.fopen('c:/OracleProject','trial.xml', 'r');
loop
BEGIN
utl_file.get_line(v_FileHandle, charString);
exception
when no_data_found then
utl_file.fclose(v_FileHandle);
exit;
END;
dbms_output.put_line(charString);
if finalStr is not null then
finalStr := finalStr || charString;
else
finalStr := charString;
end if;
end loop;
-- for inserting the XML data into the table
insCtx := DBMS_XMLSTORE.NEWCONTEXT('RIDB.TRIALZIPCODES');
insCtx := DBMS_XMLSTORE.INSERTXML(insCtx, finalStr);
dbms_output.put_line('INSERT DONE '||TO_CHAR(rowsp));
DBMS_XMLStore.closeContext(insCtx);
END;
END TRIAL;
For the first time when i complied i got the errors as :
Procedure RIDB.PROCEDURE1@RIDB
Error(16,14): PLS-00201: identifier 'UTL_FILE' must be declared
Error(16,14): PL/SQL: Item ignored
Error(29,1): PLS-00320: the declaration of the type of this expression is incomplete or malformed
Error(29,1): PL/SQL: Statement ignored
Error(33,1): PL/SQL: Statement ignored
Error(33,19): PLS-00320: the declaration of the type of this expression is incomplete or malformed
Error(36,1): PL/SQL: Statement ignored
Error(36,17): PLS-00320: the declaration of the type of this expression is incomplete or malformed
So i logged in as sys & grant the permission to execute on UTL_FILE to ridb (user):
SQL Statement:
grant execute on utl_file to ridb
So, it got compiled successfully but when i execute it gives me error as:
Source does not have a runnable target.
What does this mean?
So I browse through forum & i got to know that i need to initial the UTL_FILE_DIR ="C:/OracleProject" in init.ora
So can i edit the init.ora with notepad.When i tried to do that it says permission denied
In my system it shows the init.ora file in path C:\oraclexe\app\oracle\product\10.2.0\server\config\scripts
but there is also other file initXETemp in the same path do i need to do the changes in it.
I have tried even editing the SPFILE as mentioned below:
C:\oraclexe\app\oracle\product\10.2.0\server\dbs\SPFILEEXE - I had edit this file using notepad & set the value of UTL_FILE_DIR ="C:/OracleProject". So next time when i restarted i'm unable to log on to the database.
So i had reinstall the software again.
Could you please let me know how to proceed..hi,
I have created the directory from sys database
CREATE or replace DIRECTORY XML_DIR2 AS 'C:\OracleProject';
& grant read,write access to the user
grant read,write on directory XML_DIR2 to RIDB;
& i had change the tag name in the xml file as shown below:
<?xml version = '1.0'?>
<metadata>
<Zipcodes>
<mappings Record="4">
<STABBRE>CA</STABBRE>
<ZIPCODE>94301</ZIPCODE>
</mappings>
<mappings Record="5">
<STABBRE>CO</STABBRE>
<ZIPCODE>80323</ZIPCODE>
<ZIPCODEEXT>9277</ZIPCODEEXT>
</mappings>
</Zipcodes>
</metadata>
TRIALZIPCODE table as shown below:
CREATE TABLE "RIDB"."TRIALZIPCODE"
( "STABBRE" VARCHAR2(20 BYTE),
"ZIPCODE" NUMBER(*,6) NOT NULL ENABLE,
"ZIPCODEEXT" NUMBER
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ;
I have tried two methods as shown below:
Procedure 1:
create or replace
PROCEDURE TRIAL_V2 AS
BEGIN
DECLARE
-- declare attributes
charString varchar2(80);
finalStr varchar2(4000) := null;
rowsp integer;
v_FileHandle UTL_FILE.FILE_TYPE;
l_context_handle dbms_xmlgen.ctxHandle;
insCtx DBMS_XMLStore.ctxType;
cnt NUMBER;
xmldoc xmltype := xmltype( bfilename('XML_DIR2','trialxml.xml'), nls_charset_id('AL32UTF8') );
--XML_DIR VARCHAR2(40) := 'C:\\OracleProject';
BEGIN
insCtx := DBMS_XMLStore.newContext('DEV.TRIALZIPCODES');
DBMS_XMLStore.setUpdateColumn(insCtx, 'STABBRE');
DBMS_XMLStore.setUpdateColumn(insCtx, 'ZIPCODE');
DBMS_XMLStore.setUpdatecolumn(insCtx, 'ZIPCODEEXT');
DBMS_XMLStore.setRowTag(insCtx, 'mappings');
cnt := DBMS_XMLStore.insertXML(insCtx, xmldoc);
DBMS_XMLStore.closeContext(insCtx);
END;
Procedure 1 was compiled with out errors but when i execute i got the error as :
Source does not have a runnable target.
Procedure 2_
CREATE OR REPLACE PROCEDURE TRIAL_V3 AS
BEGIN
DECLARE
-- declare attributes
charString varchar2(80);
finalStr varchar2(4000) := null;
rowsp integer;
v_FileHandle UTL_FILE.FILE_TYPE;
l_context_handle dbms_xmlgen.ctxHandle;
insCtx DBMS_XMLStore.ctxType;
cnt NUMBER;
xmldoc xmltype := xmltype( bfilename('XML_DIR2','trialxml.xml'), nls_charset_id('AL32UTF8') );
--XML_DIR VARCHAR2(40) := 'C:\\OracleProject';
BEGIN
INSERT INTO trialzipcode (STABBRE, ZIPCODE, ZIPCODEEXT)
SELECT extractvalue(x.column_value, 'mappings/STABBRE'),
extractvalue(x.column_value, 'mappings/ZIPCODE'),
extractvalue(x.column_value, 'mappings/ZIPCODEEXT')
FROM TABLE(
XMLSequence(
EXTRACT(
xmltype( bfilename('XML_DIR2','trialxml.xml'), nls_charset_id('AL32UTF8') ),
'metadata/Zipcodes/mappings'
) x
END;
END TRIAL_V3;
Procedure 2 was complied without errors but when i execute i got the error as:
Connecting to the database RIDB.
ORA-22288: file or LOB operation FILEOPEN failed
The system cannot find the file specified.
ORA-06512: at "SYS.DBMS_LOB", line 523
ORA-06512: at "SYS.XMLTYPE", line 287
ORA-06512: at "RIDB.TRIAL_V3", line 12
ORA-06512: at line 2
Process exited.
Disconnecting from the database RIDB.
Could you please let me know how to proceed... -
Insert multiple records from web dynpro
Hi,
How to insert multiple records from web dynpro applications to SAP backend system ?
Thanks,
sowmyaHi soumya..
if want to multiple row selected then save into the Sap back End..
value node--table.
Backend value node=table_bapi_input;
back end internal table --tableback.
int size=wdcontext.nodeTable().size();
int lead=wdcontext.nodeTable().getLeadSelection();
table_bapi_input in=new table_bapi_input();
wdcontext.nodetable_bapi_input().bind(in);
for(int i=size-1;i>0;i--){
tableback set=new tableback()
if(lead==i || wdcontext.nodeTable().ismultiSelection(i)){
set.setName(wdContext.nodeTable().getTableElementAt(i).getName();
in.addZc_input(set);
wdContext.currenttable_bapi_inputElement().modelobject().excute();
wdContext.nodeOutput().invalidate();
thanks
jati -
How to parse and retrieve records from xml files into columns in Table
Hi
I attached the thing what i tried.
Table to hold the XML COntent:
create table xmlfile(xml_con sys.xmltype);
Inserting Xml file content into the Above table:
insert into xmlfile values(sys.xmltype.CreateXml('<Root><name>RAM</name><age>23</age></Root>'))
SQL> select * from xmlfile;
XML_CON
<Root>
<name>RAM</name>
<age>23</age>
</Root>
SQL> select extractValue(xml_con, '/Root/name') content from xmlfile;
CONTENT
RAM
This one works fine
But if the file content is as below( contains MUltiple Records)
insert into xmlfile values(sys.xmltype.CreateXml('<Root><Record><name>RAM</name><age>23</age></Record><Record><name>SAM</name><age>23</age></Record></Root>'))
SQL> select extractValue(xml_con, '/Root/Record/name') content from xmlfile;
ERROR at line 1:
ORA-19025: EXTRACTVALUE returns value of only one node
Can anyone help me 4 this issue-How to extract multiple records from the XML file inthis manner(from PL/SQL without using JAVA)
OR
If there is anyother way to do this please tell me?SQL> SELECT EXTRACTVALUE (COLUMN_VALUE, '//name') NAME,
EXTRACTVALUE (COLUMN_VALUE, '//age') age
FROM TABLE
(XMLSEQUENCE
(EXTRACT
(XMLTYPE
('<Root>
<Record>
<name>RAM</name>
<age>23</age>
</Record>
<Record>
<name>SAM</name>
<age>23</age>
</Record>
</Root>'
'/Root/Record'
NAME AGE
RAM 23
SAM 23
2 rows selected. -
Performance issue loading 4000 records from XML
Hello, Im' trying to upload in a table with the following sqlstatement records from an XML having content of this type
<?xml version="1.0" encoding="UTF-8"?>
<custom-objects xmlns="http://www.mysite.com/xml/impex/customobject/2006-10-31">
<custom-object type-id="NEWSLETTER_SUBSCRIBER" object-id="[email protected]">
<object-attribute attribute-id="customer-no"><value>BLY00000001</value></object-attribute>
<object-attribute attribute-id="customer_type"><value>registered</value></object-attribute>
<object-attribute attribute-id="title"><value>Mr.</value></object-attribute>
<object-attribute attribute-id="first_name"><value>Jean paul</value></object-attribute>
<object-attribute attribute-id="is_subscribed"><value>true</value></object-attribute>
<object-attribute attribute-id="last_name"><value>Pennati Swiss</value></object-attribute>
<object-attribute attribute-id="address_line_1"><value>newsletter ADDRESS LINE 1 data</value></object-attribute>
<object-attribute attribute-id="address_line_2"><value>newsletter ADDRESS LINE 2 data</value></object-attribute>
<object-attribute attribute-id="address_line_3"><value>newsletter ADDRESS LINE 3 data</value></object-attribute>
<object-attribute attribute-id="housenumber"><value>newsletter HOUSENUMBER data</value></object-attribute>
<object-attribute attribute-id="city"><value>newsletter DD</value></object-attribute>
<object-attribute attribute-id="post_code"><value>6987</value></object-attribute>
<object-attribute attribute-id="state"><value>ASD</value></object-attribute>
<object-attribute attribute-id="country"><value>ES</value></object-attribute>
<object-attribute attribute-id="phone_home"><value>0044 1234567 newsletter phone_home</value></object-attribute>
<object-attribute attribute-id="preferred_locale"><value>fr_CH</value></object-attribute>
<object-attribute attribute-id="exported"><value>true</value></object-attribute>
<object-attribute attribute-id="profiling"><value>true</value></object-attribute>
<object-attribute attribute-id="promotions"><value>true</value></object-attribute>
<object-attribute attribute-id="source"><value>https://www.mysite.com</value></object-attribute>
<object-attribute attribute-id="source_ip"><value>10.10.1.1</value></object-attribute>
<object-attribute attribute-id="pr_product_serial_number"><value>000123345678 product serial no.</value></object-attribute>
<object-attribute attribute-id="pr_purchased_from"><value>Store where product to be registered was purchased</value></object-attribute>
<object-attribute attribute-id="pr_date_of_purchase"><value></value></object-attribute>
<object-attribute attribute-id="locale"><value>fr_CH</value></object-attribute>
</custom-object>
<custom-object type-id="NEWSLETTER_SUBSCRIBER" object-id="[email protected]">
<object-attribute attribute-id="customer-no"><value></value></object-attribute>
<object-attribute attribute-id="customer_type"><value>unregistered</value></object-attribute>
<object-attribute attribute-id="title"><value>Mr.</value></object-attribute>
<object-attribute attribute-id="first_name"><value>Jean paul</value></object-attribute>
<object-attribute attribute-id="is_subscribed"><value>true</value></object-attribute>
<object-attribute attribute-id="last_name"><value>Pennati Swiss</value></object-attribute>
<object-attribute attribute-id="address_line_1"><value>newsletter ADDRESS LINE 1 data</value></object-attribute>
<object-attribute attribute-id="address_line_2"><value>newsletter ADDRESS LINE 2 data</value></object-attribute>
<object-attribute attribute-id="address_line_3"><value>newsletter ADDRESS LINE 3 data</value></object-attribute>
<object-attribute attribute-id="housenumber"><value>newsletter HOUSENUMBER data</value></object-attribute>
<object-attribute attribute-id="city"><value>newsletter CASLANO</value></object-attribute>
<object-attribute attribute-id="post_code"><value>6987</value></object-attribute>
<object-attribute attribute-id="state"><value>TICINO</value></object-attribute>
<object-attribute attribute-id="country"><value>CH</value></object-attribute>
<object-attribute attribute-id="phone_home"><value>0044 1234567 newsletter phone_home</value></object-attribute>
<object-attribute attribute-id="preferred_locale"><value>fr_CH</value></object-attribute>
<object-attribute attribute-id="exported"><value>true</value></object-attribute>
<object-attribute attribute-id="profiling"><value>true</value></object-attribute>
<object-attribute attribute-id="promotions"><value>true</value></object-attribute>
<object-attribute attribute-id="source"><value>https://www.mysite.com</value></object-attribute>
<object-attribute attribute-id="source_ip"><value>85.219.17.170</value></object-attribute>
<object-attribute attribute-id="pr_product_serial_number"><value>000123345678 product serial no.</value></object-attribute>
<object-attribute attribute-id="pr_purchased_from"><value>Store where product to be registered was purchased</value></object-attribute>
<object-attribute attribute-id="pr_date_of_purchase"><value></value></object-attribute>
<object-attribute attribute-id="locale"><value>fr_CH</value></object-attribute>
</custom-object>
</custom-objects>
I use the following sequence of queries below to do the insert (XML_FILE is passed to the procedure as XMLType)
INSERT INTO DW_CUSTOMER.NEWSLETTERS (
BRANDID,
CUSTOMER_EMAIL,
DW_WEBSITE_TAG
Select
p_brandid as BRANDID,
CUSTOMER_EMAIL,
p_website
FROM
(select XML_FILE from dual) p,
XMLTable(
xmlnamespaces(default 'http://www.mysite.com/xml/impex/customobject/2006-10-31'),
'/custom-objects/custom-object' PASSING p.XML_FILE
COLUMNS
customer_email PATH '@object-id'
) CUSTOMER_LEVEL1;
INSERT INTO DW_CUSTOMER.NEWSLETTERS_C_ATT (
BRANDID,
CUSTOMER_EMAIL,
CUSTOMER_NO,
CUSTOMER_TYPE,
TITLE,
FIRST_NAME,
LAST_NAME,
PHONE_HOME,
BIRTHDAY,
ADDRESS1,
ADDRESS2,
ADDRESS3,
HOUSENUMBER,
CITY,
POSTAL_CODE,
STATE,
COUNTRY,
IS_SUBSCRIBED,
PREFERRED_LOCALE,
PROFILING,
PROMOTIONS,
EXPORTED,
SOURCE,
SOURCE_IP,
PR_PRODUCT_SERIAL_NO,
PR_PURCHASED_FROM,
PR_PURCHASE_DATE,
LOCALE,
DW_WEBSITE_TAG)
with mainq as
SELECT
CUST_LEVEL1.customer_email as CUSTOMER_EMAIL,
CUST_LEVEL2.*
FROM
(select XML_FILE from dual) p,
XMLTable(
xmlnamespaces(default 'http://www.mysite.com/xml/impex/customobject/2006-10-31'),
'/custom-objects/custom-object' PASSING p.XML_FILE
COLUMNS
customer_email PATH '@object-id',
NEWSLETTERS_C_ATT XMLType PATH 'object-attribute'
) CUST_LEVEL1,
XMLTable(
xmlnamespaces(default 'http://www.mysite.com/xml/impex/customobject/2006-10-31'),
'/object-attribute' PASSING CUST_LEVEL1.NEWSLETTERS_C_ATT
COLUMNS
attribute_id PATH '@attribute-id',
thevalue PATH 'value'
) CUST_LEVEL2
select
p_brandid
,customer_email
,nvl(max(decode(attribute_id,'customer_no',thevalue)),SET_NEWSL_CUST_ID) customer_no
,max(decode(attribute_id,'customer_type',thevalue)) customer_type
,max(decode(attribute_id,'title',thevalue)) title
,substr(max(decode(attribute_id,'first_name',thevalue)) ,1,64)first_name
,substr(max(decode(attribute_id,'last_name',thevalue)) ,1,64) last_name
,substr(max(decode(attribute_id,'phone_hone',thevalue)) ,1,64) phone_hone
,max(decode(attribute_id,'birthday',thevalue)) birthday
,substr(max(decode(attribute_id,'address_line1',thevalue)) ,1,100) address_line1
,substr(max(decode(attribute_id,'address_line2',thevalue)) ,1,100) address_line2
,substr(max(decode(attribute_id,'address_line3',thevalue)) ,1,100) address_line3
,substr(max(decode(attribute_id,'housenumber',thevalue)) ,1,64) housenumber
,substr(max(decode(attribute_id,'city',thevalue)) ,1,128) city
,substr(max(decode(attribute_id,'post_code',thevalue)) ,1,64) postal_code
,substr(max(decode(attribute_id,'state',thevalue)),1,256) state
,substr(max(decode(attribute_id,'country',thevalue)),1,32) country
,max(decode(attribute_id,'is_subscribed',thevalue)) is_subscribed
,max(decode(attribute_id,'preferred_locale',thevalue)) preferred_locale
,max(decode(attribute_id,'profiling',thevalue)) profiling
,max(decode(attribute_id,'promotions',thevalue)) promotions
,max(decode(attribute_id,'exported',thevalue)) exported
,substr(max(decode(attribute_id,'source',thevalue)),1,256) source
,max(decode(attribute_id,'source_ip',thevalue)) source_ip
,substr(max(decode(attribute_id,'pr_product_serial_number',thevalue)),1,64) pr_product_serial_number
,substr(max(decode(attribute_id,'pr_purchased_from',thevalue)),1,64) pr_purchased_from
,substr(max(decode(attribute_id,'pr_date_of_purchase',thevalue)),1,32) pr_date_of_purchase
,max(decode(attribute_id,'locale',thevalue)) locale
,p_website
from
mainq
group by customer_email, p_website
I CANNOT MANAGE TO INSERT 4000 records in less than 30 minutes!
Can you help or advise how to reduce this to reasonable timings?
ThanksSimplified example on a few attributes :
-- INSERT INTO tmp_xml VALUES ( xml_file );
INSERT ALL
INTO newsletters (brandid, customer_email, dw_website_tag)
VALUES (p_brandid, customer_email, p_website)
INTO newsletters_c_att (brandid, customer_email, customer_no, customer_type, title, first_name, last_name)
VALUES (p_brandid, customer_email, customer_no, customer_type, title, first_name, last_name)
SELECT o.*
FROM tmp_xml t
, XMLTable(
xmlnamespaces(default 'http://www.mysite.com/xml/impex/customobject/2006-10-31')
, '/custom-objects/custom-object'
passing t.object_value
columns customer_email varchar2(256) path '@object-id'
, customer_no varchar2(256) path 'object-attribute[@attribute-id="customer-no"]/value'
, customer_type varchar2(256) path 'object-attribute[@attribute-id="customer_type"]/value'
, title varchar2(256) path 'object-attribute[@attribute-id="title"]/value'
, first_name varchar2(64) path 'object-attribute[@attribute-id="first_name"]/value'
, last_name varchar2(64) path 'object-attribute[@attribute-id="last_name"]/value'
) o -
Inserting a record through XML into the tbale
Hi,
When i insert a record into a table through XML data which is through CLOB,
the data gets inserted and when i commit the ransaaction and check in my table, the data gets inserted for only few feilds and the remaining feilds will be blank , though the value in the field is inserted through XML.
please get back to me at the earliest.are you sure you can see the hole content?
increase the maximum width for displaying CLOB:
SQL> desc test
Name Null? Typ
DATA CLOB
SQL> insert into test values ('<EMPS><EMPLOYEE_ID>200</EMPLOYEE_ID>
2 <FIRST_NAME>Jennifer</FIRST_NAME>
3 <LAST_NAME>Whalen</LAST_NAME>
4 <EMAIL>JWHALEN</EMAIL>
5 <PHONE_NUMBER>515.123.4444</PHONE_NUMBER>
6 <HIRE_DATE>17-SEP-87</HIRE_DATE>
7 <JOB_ID>AD_ASST</JOB_ID>
8 <SALARY>4400</SALARY>
9 <MANAGER_ID>101</MANAGER_ID>
10 <DEPARTMENT_ID>10</DEPARTMENT_ID></EMPS');
1 row created
SQL> select * from test;
DATA
<EMPS><EMPLOYEE_ID>200</EMPLOYEE_ID>
<FIRST_NAME
SQL> set long 500
SQL> select * from test;
DATA
<EMPS><EMPLOYEE_ID>200</EMPLOYEE_ID>
<FIRST_NAME>Jennifer</FIRST_NAME>
<LAST_NAME>Whalen</LAST_NAME>
<EMAIL>JWHALEN</EMAIL>
<PHONE_NUMBER>515.123.4444</PHONE_NUMBER>
<HIRE_DATE>17-SEP-87</HIRE_DATE>
<JOB_ID>AD_ASST</JOB_ID>
<SALARY>4400</SALARY>
<MANAGER_ID>101</MANAGER_ID>
<DEPARTMENT_ID>10</DEPARTMENT_ID></EMPS
SQL> -
Insertion of records from view into a table
hello Friends,
I have a view LGR is build on 12 table,this view has over 1 millon records, now when i run reports based on this view are so much slower, for speeding up reports i create a table LGRT and base all the reports on it, but the problem is that after any chage to the data of the LGR view , I delete all records from LGRT table and reinsert all records from LGR view
delete from lgrt;
insert into lgrt
select *
from lgr
friends its a very long procedure what can i do to minimaze the human work.....
i mean that it should be done automatically.Hello,
It sounds like you could use a materialised view here to speed things up, also it will save you the hassle of deleting records from the temporary table etc as they offer quite a few synchronisation options. Have a look at the documentation here:
http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_63a.htm#SQLRF01302
There a quite a few examples toward the bottom of the page.
HTH -
Question about insert date value from xml file
I want insert value into table from xml file. Every time I inserted value of date type into the table, I got the unpasable error message as following:
oracle.xml.sql.OracleXMLSQLException: Exception 'java.text.ParseException:Unpars
eable date: "2000-04-19 00:00:00.0"' encountered during processing ROW element
Thanks for anyone that can fix my problem or give me any suggestion.
email: [email protected]<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by matmnwx:
I want insert value into table from xml file. Every time I inserted value of date type into the table, I got the unpasable error message as following:
oracle.xml.sql.OracleXMLSQLException: Exception 'java.text.ParseException:Unpars
eable date: "2000-04-19 00:00:00.0"' encountered during processing ROW element
Thanks for anyone that can fix my problem or give me any suggestion.
email: [email protected]<HR></BLOCKQUOTE>
Use:
OracleXMLSave sav = new OracleXMLSave(conn,tabName);
sav.setDateFormat(<hier the date format in the XML-File>); -
Sqlldr is loading only 1st record from xml document
Hi,
I am trying to load XML doc with multiple records using sql*loader.
I have registered my XSD perfectly.
This is my control file
LOAD DATA
INFILE *
INTO TABLE Orders APPEND
XMLType(xmldata)
FIELDS(
xmldata LOBFILE (CONSTANT FULDTL_2.xml)
TERMINATED BY '???')
BEGINDATA
FULDTL_2.xml
-- Here, what I have to give for TERMINATED BY '???'
My xml doc
<Order ID="146120486" Status="CL" Comments="Shipped On 08/05/2008"/>
<Order ID="143417590" Status="CL" Comments="Handset/Device has been received at NRC" ShipDate=""/>
sqlldr is loading only 1st record from the file.
How can I make it to load all the records from my xml doc.
Thanks in advance.thanks for both the replies above - essentially the same correct solution.
something worth noting now that I've written and tested both a SAX solution and a DOM solution is that there is a significant (4 x) time penalty using SAX.
I considering dividing the vector I am storing/recovering into chunks and saving each chunk separately using DOM to speed things up...
any thoughts on this approach? -
Need to insert selected records from PROD into TEST
I am trying to insert all records (for a specific region only) from production to test.
I'm a little confused about how the pl/sql would look for this.
Note that as I insert into the table in test, I also have a key field that is auto incremented by 1 each time.
The problem that I am having is I need to link two tables in PROD together to determine the region:
So in test, I want to do something like:
INSERT INTO ACCOUNT_PRICE
(select * from ACCOUNT_PRICE@PROD, MARKETER_ACCOUNT@PROD
where substr(MARKETER_ACCT_NO,1,1) = '3'
and MARKETER_ACCOUNT_NO = PRICE_ACCOUNT_NO);
However, i'm not sure if this is correct or if I should be using a BULK insert.
Note that I cannot just load the whole table as I need to restrict it to only one region of data.
Any help would be appreciated.
SeanDirect load (BULK) is irrelevant to what you are asking. I would strongly suggest that you read the docs about this feature before considering it for any purpose.
As to your question what you are asking is unclear and, for reasons known only to you, you did not include a version number.
So given that I get to invent your version number I have decided you have 10g and therefore you have DataPump so my recommendation is to use
DataPump to extract and export the records you wish to move.
http://www.morganslibrary.org/reference/dbms_datapump.html -
How to show records from xml file
HI All
I have created one region its actually search region
which having 5 items and result table region
I want to search records based on that 5 items and want to show output in table
I have table name as hr_api_transactions which contains lot of columns
and that table also contain one column
name as TRANSACTION_DOCUMENT of type CLOB()
that columns xml files for each record
I want to extract data from that xml file and want to display.I have created one region on seeded page
in that region I have created one table for output
that region is search region
which having 5 items of textfield and 2 items of type submit button
GO and Clear
I want to search based on that 5 items
I want to display records in table that I have created on that region
I have one seeded table
that contain one column
that column contain xml file for each individual records
that xaml file contains values what I want to display
MY problems are
how can I extract data from xml file?
how can I show all values for each records on that table?
how can I search based on that 5 items?
now I am able to find out single value from that XML file
by using SQL command
select xmltype(transaction_document).extract('//IrcPostingContentsVlEORow/CreationDate/text()').getStringVal() CreationDate
from hr_api_transactions
where transaction_ref_table = 'PER_ALL_VACANCIES'
and transaction_ref_id = 4693;how can I extract more than one records from that XML file -
Help needed badly Insert text data from xml files into tables
Hi all, I have asked to do insertion of text from a xml file into tables upon receiving using pro*c. i've done quite an amount of research on xml parser in c but there wasn't much information for mi to use for implementation...
Guys don't mind helping me to clarify few doubts of mine...
1. Where can i get the oracle xml parser libs? Is it included when i installed oracle 8i?
2. Is there any tutorials or help files for xml parser libs where i can read up?
I need the xml parser to recognise the tags, followed by recognising the text after the tags.
eg. xml format
<studentID> 0012 </studentID>
<student> john </student>
<studentID> 0013 </studentID>
<student> mary </student>
text willl be inserted into tables like this:
studentID | student
0012 | john
0013 | mary
by the way i'm using oracle 8i on HP-UX. Thanks in advance.I can answer one of of your questions at least
1. Where can i get the oracle xml parser libs? Is it included when i installed oracle 8i?You need the XML XDK. You can use http://www.oracle.com/technology/tech/xml/xdkhome.html as your starting point. I believe the 9i version works for 8i.
I have no pro*c experience so I can't offer any other suggestions regarding how to do this in pro*c. -
Some Times Table is inserting Partial record from a view Why?
The query consists of a simple insert statement where the data is inserted from a view. The issue is that some times only the first retreived record from the select statement are inserted into the table from a view and the rest are ignored when we scheduled in the batch job of EM console. Some times it inserted correctly.
For Ex.
INSERT INTO Table_COLL(COL_A, COL_B, COL_C)
SELECT COL_A, COL_B, COL_C
FROM COLL_VIEW
WHERE DATE=TRUNC(SYSDATE);
COMMIT;
The select statement retreives 200 records and the insert statement works perfectly as expected when executed in SQL* plus.
However the issue happens where only one record is inserted when the same query is scheduled in the batch job of the EM console or a procedure is created for the query and the same is scheduled in the EM console as a batch job and Some times it inserted correctly in EM Console.
Can anyone explain as why this is hapenning? (DB is Oracle 10g& size is 100gb )I doubt that there is a bug. I suspect the query runs when you schedule it at a point of time where TRUNC(SYSDATE) gives less rows...
You could store the COUNT(*) and execution time before you run the INSERT in a LOG table. Any transaction based on two times (runtime and systime) can lead to unexpected results.
What about something like this:
INSERT INTO Table_COLL(COL_A, COL_B, COL_C)
SELECT COL_A, COL_B, COL_C
FROM COLL_VIEW a
LEFT JOIN Table_COLL B
ON ( a.COL_A = b.COL_A
AND a.COL_B = b.COL_B
AND a.COL_C = b.COL_C)
WHERE a.DATE>=TRUNC(SYSDATE)-1
AND b.COL_A IS NULL;
COMMIT; -
Deleting records from XML file--just a little problem
Hi!
My xml file has a simple form like this:
<?xml version="1.0" encoding="UTF-8"?>
<AdressBook>
<Name>Suzy</Name>
<Lastname>Love</Lastname>
<Adress>You street 22</Adress>
<Phone>911</Phone>
<Email>[email protected]</Email>
</Record>
<Record>
<Name>Judy</Name>
<Lastname>Goblin</Lastname>
<Adress>Milkyway</Adress>
<Phone>911</Phone>
<Email>[email protected]</Email>
</Record>
</AdressBook>Now, whenever I delete a record from that file it leaves a remaining tag <Record /> on the loction were previous record was. How do I delete that remaining tag or better yet, how do I delete Record element in whole. I am using jdom.
Here is the code I use to delete records:
public void deleteRecordFromFile(Record r)
Element root=doc.getRootElement();
List records=root.getChildren();
Iterator listIt=records.iterator();
while(listIt.hasNext())
Element rec=(Element)listIt.next();
Record p=new Record("","","","","");
List recChildren=rec.getChildren();
Element e=null;
for( int i=0;i<recChildren.size();i++)
e=(Element)recChildren.get(i);
switch (i)
case 0: p.setName(e.getText()); break;
case 1: p.setLastName(e.getText());break;
case 2: p.setAddress(e.getText());break;
case 3: p.setPhone(e.getText());break;
case 4: p.setEmail(e.getText());break;
default: ;
if(p.equals(r))
rec.removeContent();
System.out.println("Record deleted!");
writeToFile(filename);
}Like you see above I use the method removeContent(), should I use some other method? I need to get rid of that remaining tags in order to make my editing of the records stored in there easier. I guess I could make a seperate routine that would clean my file of those tags, but I think that is just too much time consuming...or not?
Please help me out here.:)
Message was edited by:
byteministerYou cannot remove the elements of a List while iterating over them without the risk of throwing a ConcurrentModificationException, whatever method you would use. So you can only delete the records in two steps: collect them all, and delete them afterwards.
public void deleteRecordFromFile(Record r)
Element root=doc.getRootElement();
List records=root.getChildren();
Iterator listIt=records.iterator();
// Create a container for storing references to the records that will be deleted.
ArrayList<Element> deleteList = new ArrayList<Element>();
while(listIt.hasNext())
Element rec=(Element)listIt.next();
Record p=new Record("","","","","");
List recChildren=rec.getChildren();
Element e=null;
for( int i=0;i<recChildren.size();i++)
e=(Element)recChildren.get(i);
switch (i)
case 0: p.setName(e.getText()); break;
case 1: p.setLastName(e.getText());break;
case 2: p.setAddress(e.getText());break;
case 3: p.setPhone(e.getText());break;
case 4: p.setEmail(e.getText());break;
default: ;
if(p.equals(r))
// This record will be deleted.
deleteList.add(rec);
// Delete all the records in deleteList.
records.removeAll(deleteList);
writeToFile(filename);
}
Maybe you are looking for
-
How to find import and local purchase order for report
Dear Friends, Please help me in coding this report, =below is the functional requirement. 1. To find the list of Import or Local Purchase Orders(purchase orders to be procured from another country). 2.Once the import purchase order is s
-
My HP L7780 all-in-one officejet pro will not print when inserting an original on the screen.
When I insert an original document on the copy screen, an error msg appears "original loaded" please re-load and try again. The printer functions properly from the auto feed and from computer commands. How do I remove "Original Loaded" from the prin
-
Cannot drop undo tablespace with Active extents but no active sessions
Hi all, I am running on 10gr2 oracle database in a Linux 32 bit environment. I have a corrupted undo datafile. I've been able to recover the datafile but still the alert logs is still showing that it is corrupted. Now what I'm trying to do is to drop
-
Hi Due to BOM strucutre change, the BOM was maintain with ECN and now BOM was recursive, due to SAP recursiveness check did not consider BOM effectivity date (note 42891), and now CS11 will stop at the recursive BOM and will not exploide down further
-
Dear Experts, I am trying to send an EWA locally from my ECC6.0 Quality system. I have already configured Satellite sytem and Service desk in my solution manager. Procedure I am following: In my Quality system I went to Tcode SDCCN. Then I have activ