Oracle创建临时表、存储过程,Java调用存储过程

创建临时表

create global temporary table TEMP_JOURNAL_TEST (
   ROWNUMBER NUMBER,
   TRANS_DAY VARCHAR2(64),     
   ID VARCHAR2(64),  -- ID
   TRANS_NUM VARCHAR2(64),
   SUBJECT VARCHAR2(64), 
   VOUCHER_ID VARCHAR2(64), 
   CONTENT VARCHAR2(64),
   SETTLEMENT_NUM VARCHAR2(64), 
   SUMMARY VARCHAR2(64), 
   CURRENCY_TYPE VARCHAR2(64), 
   DEBIT_AMOUNT NUMBER(15,2),  
   CREDIT_AMOUNT NUMBER(15,2), 
   NAME VARCHAR2(64),  
   BILL_NAME VARCHAR2(64), 
   BILL_NO VARCHAR2(64), 
   ACCOUNT_ID VARCHAR2(64),
   IS_POST VARCHAR2(4)  
) on commit preserve rows;

创建存储过程

CREATE OR REPLACE PROCEDURE SP_JOURNAL_SEARCH (
    -- 定义参数
	ACCOUNTID INTEGER, 
	ACCOUNTTYPE INTEGER,  
	TOTAL VARCHAR2, 
	BEGIN_DATE VARCHAR2, 
	END_DATE VARCHAR2,  
	OUT_RESULT OUT SYS_REFCURSOR -- 游标
	) AS 
    -- 定义变量
	TMP_BALANCE FLOAT := 0; 
BEGIN
-- INTO :给变量赋值
SELECT BALANCE INTO TMP_BALANCE FROM CU_ACCOUNTBOOK WHERE ID = ACCOUNTID;
-- 删除临时表数据
DELETE FROM TEMP_JOURNAL_SEARCH;
-- 添加数据到临时表
INSERT INTO TEMP_JOURNAL_SEARCH (
    ROWNUMBER, TRANS_DAY, ID, TRANS_NUM, SUBJECT, VOUCHER_ID, CONTENT, SETTLEMENT_NUM,
    SUMMARY, CURRENCY_TYPE, DEBIT_AMOUNT, CREDIT_AMOUNT, NAME, BILL_NAME, BILL_NO
) 
SELECT ROWNUM AS ROWNUMER, A.* FROM (
SELECT
	TO_CHAR( TRANS_DATE, 'YYYY-MM-DD' ) TRANS_DAY, A.ID, A.TRANS_NUM, A.SUBJECT,
	A.VOUCHER_ID, X.CONTENT, A.SETTLEMENT_NUM, A.SUMMARY, Z.CURRENCY_TYPE,
	A.DEBIT_AMOUNT, A.CREDIT_AMOUNT, U.NAME, V.BILL_NAME, K.BILL_NO
FROM CU_JOURNAL A LEFT JOIN CU_ACCOUNTBOOK Z ON Z.ID = A.ACCOUNT_ID LEFT JOIN CU_SETTLEMENT X ON X.ID = A.SETTLEMENT_ID LEFT JOIN SYS_USER U ON U.ID = A.DEAL_WITH LEFT JOIN CU_BILLTYPE V ON V.ID = A.BILLTYPE_ID LEFT JOIN CU_BILLBOOK K ON K.ID = A.BILLBOOK_ID WHERE A.ACCOUNT_ID = ACCOUNTID AND Z.ACCOUNT_TYPE = ACCOUNTTYPE AND TO_CHAR( TRANS_DATE, 'YYYY-MM-DD' ) BETWEEN BEGIN_DATE AND END_DATE
ORDER BY TRANS_DATE, ID 
) A;
-- 查询数据
OPEN OUT_RESULT FOR 
SELECT * FROM (
SELECT
	TO_CHAR( SUMMARY ) SUMMARY,
	TRANS_DAY,
	DEBIT_AMOUNT AS DEBITAMOUNT,
	CREDIT_AMOUNT AS CREDITAMOUNT,
	( SELECT TMP_BALANCE + SUM( DEBIT_AMOUNT ) - SUM( CREDIT_AMOUNT ) FROM TEMP_JOURNAL_SEARCH WHERE ROWNUM <= A.ROWNUMBER ) AS BALANCE,
	TRANS_NUM AS TRANSNUM,
	SUBJECT AS SUBJECT,
	VOUCHER_ID AS VOUCHERID,
	CONTENT,
	SETTLEMENT_NUM AS SETTLEMENTNUM,
	CURRENCY_TYPE AS CURRENCYTYPE,
	NAME,
	BILL_NAME AS BILLNAME,
	BILL_NO AS BILLNO,
	ID 
FROM TEMP_JOURNAL_SEARCH A

	) B 
ORDER BY
	TRANS_DAY NULLS FIRST,
	ID;
END;

Java后台调用

Mapper:
<resultMap id="cursorMap" type="Journal" >
    <result column="transDay" property="transDay" />  
    <result column="content" property="content" />  
    <result column="currencyType" property="currencyType" />  
    <result column="name" property="name" />  
    <result column="billName" property="billName" />  
    <result column="billNo" property="billNo" />  
</resultMap >  

<select id="getJournalSearchGridData" statementType="CALLABLE">
   CALL SP_JOURNAL_SEARCH(
     #{ACCOUNTID,mode=IN},
     #{ACCOUNTTYPE,mode=IN},
     #{TOTAL,mode=IN},
     #{BEGIN_DATE,mode=IN},
     #{END_DATE,mode=IN},
   )
</select>
Dao层:
public abstract List<Map<String,Object>> getJournalSearchGridData(Map<String, Object> map);
Service层:
/**map: 参数**/
public Page<Map<String,Object>> findPageSearch(Page<Map<String,Object>> page, Map<String, Object> map) {
   dao.getJournalSearchGridData(map);
   List<Map<String, Object>> list =(List<Map<String,Object>>) map.get("OUT_RESULT");
   page.setList(list);
   return page;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值