Oracle 存储过程 实现 JAVA中的LIST输入参数
今天周末没事做便想来试试JAVA与ORACLE的结合程度,结果反映这两件利器结合起来真的很厉害,前无古人,后无来者。嘿嘿~~
因为上周末帮JAVA组的同事实现了一个输入数值->update记录->返回游标的存储过程,这些过程很简单。但当时就考虑到了一个问题,因为有在JAVA代码中调用这个存储过程之前先要从一个XLS文件中读取数据然后用INSERT插入ORACLE数据库表中。但发现在JAVA代码实现的方式是一条条记录地INSERT进ORACLE,当时就提出了这个问题,想在JAVA那些传个数组对象进ORACLE存储过程中,然后在ORACLE存储过程代码中分解这个数组的数据,再执行其他的操作。因此就有了下面的JAVA+ORACLE实践日记了,嘿嘿,好久没搞JAVA了,ArrayList都不会用了。不多说,看代码:
首先创建两个ORACLE数据类型,目的就是为了存储结果集数据(数组等):
CREATE OR REPLACE TYPE CDW_OBJECT AS OBJECT(
FISCAL_MONTH VARCHAR2(10),
CUSTOMER_NUMBER VARCHAR2(10),
CUSTOMER_NAME VARCHAR2(50)
);
CREATE OR REPLACE TYPE CDW_TABLE AS TABLE OF CDW_OBJECT;
表结果及数据:
SQL> DESC CDW_AR_SA_EXPOSURE_T;
Name Type Nullable Default Comments
--------------- ------------ -------- ------- --------
FISCAL_MONTH VARCHAR2(10) Y
CUSTOMER_NUMBER VARCHAR2(10) Y
CUSTOMER_NAME VARCHAR2(50) Y
SQL> DESC CDW_AR_SA_EXPOSURE_FACT;
Name Type Nullable Default Comments
--------------- ------------ -------- ------- --------
FISCAL_MONTH VARCHAR2(10) Y
CUSTOMER_NUMBER VARCHAR2(10) Y
CUSTOMER_NAME VARCHAR2(50) Y
SQL>
表结构及测试数据代码:
CREATE TABLE CDW_AR_SA_EXPOSURE_FACT (FISCAL_MONTH VARCHAR2(10),CUSTOMER_NUMBER VARCHAR2(10),CUSTOMER_NAME VARCHAR2(50));
INSERT INTO CDW_AR_SA_EXPOSURE_FACT VALUES('200708','1001','XIEFENG');
INSERT INTO CDW_AR_SA_EXPOSURE_FACT VALUES('200705','1002','MANTISXF');
INSERT INTO CDW_AR_SA_EXPOSURE_FACT VALUES('200706','2001','CHENGUOZHENG');
INSERT INTO CDW_AR_SA_EXPOSURE_FACT VALUES('200808','3001','XIAOFANG');
INSERT INTO CDW_AR_SA_EXPOSURE_FACT VALUES('200809','1056','ZIMING');
INSERT INTO CDW_AR_SA_EXPOSURE_FACT VALUES('200810','7701','BOSHI');
INSERT INTO CDW_AR_SA_EXPOSURE_FACT VALUES('200811','1821','BOGE');
INSERT INTO CDW_AR_SA_EXPOSURE_FACT VALUES('200903','2431','FEIZAI');
INSERT INTO CDW_AR_SA_EXPOSURE_T VALUES('200811','3301','BOSHI_HAOREN');
INSERT INTO CDW_AR_SA_EXPOSURE_T VALUES('200812','1921','BOGE_HAOREN');
INSERT INTO CDW_AR_SA_EXPOSURE_T VALUES('200905','6666','FEIZAI_HAOREN');
COMMIT;
存储过程代码:
CREATE OR REPLACE PROCEDURE SP_CARC_UPLOAD_FILE_TEST(OUT_CURSO