[英]How do i get this stored procedure to work with an XML file?
Trying to insert some data into two tables from an xml file (generated by pega / java) by using a stored procedure . 尝试使用存储过程从xml文件(由pega / java生成)将一些数据插入到两个表中。 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.
一个选择是JAVA开发人员使用存储过程中提供的参数调用存储过程,并以这种方式推送数据。 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;
/
Try bulk loading the XML file as a CTE: 尝试将XML文件作为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.
从那里,您可以像查询其他任何表或视图一样查询“ XmlFile” CTE表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.