Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old July 7th, 2004, 01:58 PM
thordiddy thordiddy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 40 thordiddy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 17 m 12 sec
Reputation Power: 5
Cool Insertint pipelined data into a table

I have the following function which extracts data out of an xml type and pipelines it into a table. Below is the code:

/*******DEFINE FUNCTION***************************/

CREATE OR REPLACE FUNCTION convert_xml(xml IN XMLType) return out_table
PIPELINED IS

out_rec table_row;
i number;
xml_line XMLType;
xml_text XMLType;

BEGIN
i := 1;

--initialize record with its datatype:
out_rec := table_row('','','','','','','','','','','','','','','','','','','','','');
--done initializing

--DBMS_OUTPUT.PUT_LINE('okay. the function has been called successfully.');
LOOP

--this part takes out the i'th entry. it works fine.
xml_line := xml.extract('//Payfields[' || i || ']');

EXIT WHEN xml_line IS NULL;

--then extract each entry from xml_line into xml_text,
--then checks IF value is null. IF it is not null, it is assigned to the record.

xml_text := xml_line.extract('/Payfields/claim_no/text()');
IF xml_text IS NOT NULL THEN
out_rec.claim_no := xml_text.getStringVal();
END IF;

xml_text := xml_line.extract('/Payfields/cert_no/text()');
IF xml_text IS NOT NULL THEN
out_rec.cert_no := xml_text.getStringVal();
END IF;

xml_text := xml_line.extract('/Payfields/rec_code/text()');
IF xml_text IS NOT NULL THEN
out_rec.rec_code := xml_text.getStringVal();
END IF;

xml_text := xml_line.extract('/Payfields/seq_no/text()');
IF xml_text IS NOT NULL THEN
out_rec.seq_no := xml_text.getNumberVal();
END IF;

xml_text := xml_line.extract('/Payfields/from_date/text()');
IF xml_text IS NOT NULL THEN
out_rec.from_date := TO_DATE(xml_text.getStringVal(), 'MM/DD/YY');
END IF;

xml_text := xml_line.extract('/Payfields/to_date/text()');
IF xml_text IS NOT NULL THEN
out_rec.to_date := TO_DATE(xml_text.getStringVal(),'MM/DD/YY');
END IF;

xml_text := xml_line.extract('/Payfields/service_place/text()');
IF xml_text IS NOT NULL THEN
out_rec.service_place := xml_text.getStringVal();
END IF;

xml_text := xml_line.extract('/Payfields/service_code/text()');
IF xml_text IS NOT NULL THEN
out_rec.service_code := xml_text.getStringVal();
END IF;

xml_text := xml_line.extract('/Payfields/ghi_service_place/text()');
IF xml_text IS NOT NULL THEN
out_rec.ghi_service_place := xml_text.getStringVal();
END IF;

xml_text := xml_line.extract('/Payfields/ghi_service_code/text()');
IF xml_text IS NOT NULL THEN
out_rec.ghi_service_code := xml_text.getStringVal();
END IF;

xml_text := xml_line.extract('/Payfields/procedure_code/text()');
IF xml_text IS NOT NULL THEN
out_rec.procedure_code := xml_text.getStringVal();
END IF;

xml_text := xml_line.extract('/Payfields/procedure_mod/text()');
IF xml_text IS NOT NULL THEN
out_rec.procedure_mod := xml_text.getStringVal();
END IF;

xml_text := xml_line.extract('/Payfields/ghi_procedure_code/text()');
IF xml_text IS NOT NULL THEN
out_rec.ghi_procedure_code := xml_text.getStringVal();
END IF;

xml_text := xml_line.extract('/Payfields/ghi_procedure_lpv/text()');
IF xml_text IS NOT NULL THEN
out_rec.ghi_procedure_lpv := xml_text.getStringVal();
END IF;

xml_text := xml_line.extract('/Payfields/diagnosis_code/text()');
IF xml_text IS NOT NULL THEN
out_rec.diagnosis_code := xml_text.getStringVal();
END IF;

xml_text := xml_line.extract('/Payfields/charge/text()');
IF xml_text IS NOT NULL THEN
out_rec.charge := xml_text.getNumberVal();
END IF;

xml_text := xml_line.extract('/Payfields/day_unit/text()');
IF xml_text IS NOT NULL THEN
out_rec.day_unit := xml_text.getNumberVal();
END IF;

xml_text := xml_line.extract('/Payfields/epsdt/text()');
IF xml_text IS NOT NULL THEN
out_rec.epsdt := xml_text.getStringVal();
END IF;

xml_text := xml_line.extract('/Payfields/em3/text()');
IF xml_text IS NOT NULL THEN
out_rec.em3 := xml_text.getStringVal();
END IF;

xml_text := xml_line.extract('/Payfields/cob/text()');
IF xml_text IS NOT NULL THEN
out_rec.cob := xml_text.getStringVal();
END IF;

xml_text := xml_line.extract('/Payfields/insert_date/text()');
IF xml_text IS NOT NULL THEN
out_rec.insert_date := TO_DATE(xml_text.getStringVal(),'MM/DD/YY');
END IF;

--now send information into table:
PIPE ROW(out_rec);
i := i + 1;
END LOOP;

return;
END convert_xml;

/**********END OF FUNCTION**********/

What I want to do now is to be able to take the information that has been collected and insert it into another separate table which is already defined. Say the table's name is test_table. How could I do this within the function?

Thanks

Reply With Quote
  #2  
Old July 7th, 2004, 03:03 PM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,307 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 4 h 28 m 57 sec
Reputation Power: 48
Code:

INSERT INTO TEST_TABLE
( fld1,
  fld2,
  fld3)
values
(out_rec.to_date,
 out_rec.from_date,
 out_rec.to_date );  

Obviously I'm only writing a few values.
Put the insert statement right before the end loop
Code:
INSERT...............;
END LOOP;

Reply With Quote
  #3  
Old July 8th, 2004, 08:10 AM
thordiddy thordiddy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 40 thordiddy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 17 m 12 sec
Reputation Power: 5
Thumbs up

ok, say I wanted to take data from a function that was called like this:

SELECT *
from TABLE(
convert_xml(
sys.XMLType.createXML(
xmldoc
)));

And insert all of it into a table called cpr.buf_claim_service_line. How could I do that?

Reply With Quote
  #4  
Old July 8th, 2004, 11:19 AM
thordiddy thordiddy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 40 thordiddy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 17 m 12 sec
Reputation Power: 5
Nevermind, I got it workin.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Insertint pipelined data into a table


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway