|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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; |
|
#3
|
|||
|
|||
|
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? |
|
#4
|
|||
|
|||
|
Nevermind, I got it workin.
|
![]() |
| Viewing: Dev Shed Forums > Databases > Oracle Development > Insertint pipelined data into a table |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|