How do i get this stored procedure to work with an XML file?

icerabbit Source

Trying to insert some data into two tables from an xml file (generated by pega / java) by using a stored procedure . Not sure how i am supposed to define the variables , or define the cursor since most tutorials out there only show you how to write stored procedures writing to tables from other tables within the database... The parts where i am stuck are marked. An option is that the JAVA developer call my stored procedures with the parameters provided in my stored procedure and push data in that way. If that is the case, how do i define where the cursor is pulling data from? (Thanks in advance!)

Create or Replace Procedure Cascade_Load (
a Number,
b Number,
c Number,
d Varchar2,
e Varchar2,
f Number,
g Varchar2,
h Varchar2,
i Timestamp,
j Number,
k Varchar2,
l Date,
m Number,
n Date,
o Number,
p Date,
q Date
)
AS
BEGIN
  IF b is not null
  THEN
  INSERT INTO Value(Value_Id, Product_Id, Data_Source_Id, Unit_CD,         Value_TX, UTC_OFFSET, DATA_DATE, HR_UTC, HR, HR_NUM, DATA_CODE, CREATE_DT, CREATE_USER_ID, MODIFY_DT, MODIFY_USER_ID, EFFECTIVE_DT, INACTIVE_DT)
    VALUES(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q);
  INSERT INTO XML_Load_STAGING(Code, Product_Name, Product_number, Product_Version, Technical_Contact)
    VALUES(a, b, c, d, e);
COMMIT;
   END IF;
END;
/

DECLARE
a Number,
b Number,
c Number,
d Varchar2,
e Varchar2,
f Number,
g Varchar2,
h Varchar2,
i Timestamp,
j Number,
k Varchar2,
l Date,
m Number,
n Date,
o Number,
p Date,
q Date
    CURSOR cXmlHoursLoadCursor IS (SELECT **WHAT DO I SELECT since Im calling from a xml file rather than from a table?**);
BEGIN
  For v in cXmlHoursLoadCursor LOOP
    Cascade_Load(v.a, v.b, v.c, v.d, v.e, v.f, v.g, v.h, v.i, v.j, v.k, v.l, v.m, v.n, v.o, v.p, v.q);
    COMMIT;
  END LOOP;
END;
/
javasqloracleplsqlproc

Answers

answered 6 months ago Sev09 #1

Try bulk loading the XML file as a CTE:

    --query the XML Blob using a CTE (pulling from the XML file each time)
    WITH XmlFile (Contents) AS (
    SELECT CONVERT (XML, BulkColumn) 
    FROM OPENROWSET (BULK 'C:\Books.xml', SINGLE_BLOB) AS XmlData
    )
    SELECT *
    FROM XmlFile
    GO

This will show you what the data looks like, along with column names. From there, you can query the "XmlFile" CTE table just like any other table or view.

comments powered by Disqus