gpt4 book ai didi

java - 如何使用hibernate native sql查询将对象列表传递给oracle中的存储过程

转载 作者:行者123 更新时间:2023-12-01 11:25:14 26 4
gpt4 key购买 nike

我正在使用 hibernate 连接到 Oracle 数据库。

我需要调用一个以对象类型作为输入参数的存储过程。

CREATE OR REPLACE TYPE FIN_GM_WALK_MAN_ADJ_TYPE AS OBJECT
(
ROW_NUM NUMBER,
IMPACT_TYPE_CD VARCHAR2(20 BYTE),
IMPACT_TYPE_NAME VARCHAR2(30 BYTE),
PRODUCT_ID VARCHAR2(30 BYTE),
PRODUCT_FAMILY_ID VARCHAR2(30 BYTE),
INTERNAL_BE VARCHAR2(100 BYTE),
INTERNAL_BSE VARCHAR2(100 BYTE),
EXTERNAL_BE VARCHAR2(100 BYTE),
EXTERNAL_BSE VARCHAR2(100 BYTE),
FIN_SALES_THEATER_NAME VARCHAR2(50 BYTE),
AS_OF_FISCAL_QTR_NUM_INT NUMBER,
CURRENT_FISCAL_QTR_NUM_INT NUMBER,
COGS_REV_CURRENT_QTR_AMT NUMBER,
COGS_REV_PREV_QTR_AMT NUMBER,
COGS_REV_PREV_YEAR_AMT NUMBER,
COGS_REV_QOQ_IMPACT_AMT NUMBER,
COGS_REV_YOY_IMPACT_AMT NUMBER,
SERVICE_FLG CHAR(1 BYTE),
GM_SM_CD VARCHAR2(10 BYTE),
UPLOAD_USER VARCHAR2(20 BYTE),
PURPOSE_OF_PLUG VARCHAR2(50 BYTE)
)

CREATE OR REPLACE TYPE FIN_GM_WALK_MAN_ADJ_LIST AS TABLE OF FIN_GM_WALK_MAN_ADJ_TYPE;

PROCEDURE FIN_GM_WALK_FILE_UPLOAD (
I_GM_WALK_MAN_ADJ_LIST IN FIN_GM_WALK_MAN_ADJ_LIST)
IS
V_ERRMSG VARCHAR2 (500);
BEGIN
DELETE FROM FIN_GM_WALK_MANUAL_ADJ_TEMP;

COMMIT;

FORALL i IN 1 .. I_GM_WALK_MAN_ADJ_LIST.COUNT
INSERT INTO FIN_GM_WALK_MANUAL_ADJ_TEMP
VALUES (I_GM_WALK_MAN_ADJ_LIST (i).ROW_NUM,
I_GM_WALK_MAN_ADJ_LIST (i).IMPACT_TYPE_CD,
I_GM_WALK_MAN_ADJ_LIST (i).IMPACT_TYPE_NAME,
I_GM_WALK_MAN_ADJ_LIST (i).PRODUCT_ID,
I_GM_WALK_MAN_ADJ_LIST (i).PRODUCT_FAMILY_ID,
I_GM_WALK_MAN_ADJ_LIST (i).INTERNAL_BE,
I_GM_WALK_MAN_ADJ_LIST (i).INTERNAL_BSE,
I_GM_WALK_MAN_ADJ_LIST (i).EXTERNAL_BE,
I_GM_WALK_MAN_ADJ_LIST (i).EXTERNAL_BSE,
I_GM_WALK_MAN_ADJ_LIST (i).FIN_SALES_THEATER_NAME,
I_GM_WALK_MAN_ADJ_LIST (i).AS_OF_FISCAL_QTR_NUM_INT,
I_GM_WALK_MAN_ADJ_LIST (i).CURRENT_FISCAL_QTR_NUM_INT,
I_GM_WALK_MAN_ADJ_LIST (i).COGS_REV_CURRENT_QTR_AMT,
I_GM_WALK_MAN_ADJ_LIST (i).COGS_REV_PREV_QTR_AMT,
I_GM_WALK_MAN_ADJ_LIST (i).COGS_REV_PREV_YEAR_AMT,
I_GM_WALK_MAN_ADJ_LIST (i).COGS_REV_QOQ_IMPACT_AMT,
I_GM_WALK_MAN_ADJ_LIST (i).COGS_REV_YOY_IMPACT_AMT,
I_GM_WALK_MAN_ADJ_LIST (i).SERVICE_FLG,
I_GM_WALK_MAN_ADJ_LIST (i).GM_SM_CD,
I_GM_WALK_MAN_ADJ_LIST (i).UPLOAD_USER,
I_GM_WALK_MAN_ADJ_LIST (i).PURPOSE_OF_PLUG);

COMMIT;
END FIN_GM_WALK_FILE_UPLOAD;

我的 Java 代码是

Query q = session.createSQLQuery(" { call FIN_GM_WALK_FILE_UPLOAD(:recList) }");
q.setParameter("recList",recordList);

其中 recordList 是已定义对象的 ArrayList

它抛出以下异常。

Caused by: java.sql.SQLException: ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'FIN_GM_WALK_FILE_UPLOAD'

有人可以帮我解决这个问题吗?

最佳答案

你需要这样做

q.setParameterList("recList",recordList);

关于java - 如何使用hibernate native sql查询将对象列表传递给oracle中的存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30868664/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com