接口分析sql
返回結構spa
效果圖code
存儲過程接口
create or replace procedure sp_getcustomersum(i_oprtAcc in t_customer.oprt_acc%type, --操做帳號 i_zoneId in t_zone.zone_id%type, --區域id i_fchsId in t_franchiser.fchs_id%type, --經銷商id i_storeId in t_store.store_id%type, --門店id i_dateFlag in char, --日期標誌 0:月份 1:年份 2:區間 i_date in char, --日期 i_startTime in char, --開始時間 i_endTime in char, --結束時間 o_resultCursor out sys_refcursor, --返回消息 o_errorNumber out integer) --錯誤碼 is --當前年 l_currentYear char(4); --xx之前客戶總量 l_allCounts integer; l_exception exception; --檢查帳號異常 l_exceptionAccount exception; --錯誤消息 l_error_msg varchar2(100); /********** *creater: lxl *craeateTime: 2015-07-15 *function: 得到客戶信息明細 **********/ begin pkg_utility.sp_writeLog(i_log_type => 'INFO', i_acc_id => i_oprtAcc, i_sp_name => 'sp_getcustomersum', i_log_desc => '開始'); --這裏先調用下級聯檢查存儲過程,看帳號是否可用 sp_checkaccount(i_account => i_oprtAcc, o_errNumber => o_errorNumber); --帳號不可用,直接退出 if o_errorNumber != 0 then --異常處理 raise l_exceptionAccount; end if; --初始化狀態值 o_errorNumber := pkg_constants.C_RTN_SUCCESS; l_error_msg := ''; --取系統年份 select to_char(sysdate, 'YYYY') into l_currentYear from dual; --須要對dateFlag進行判空 --檢測到異常時,須要對輸出值進行設置 if i_dateFlag is null then raise l_exception; end if; --1.i_dateFlag = 0,初始化進來顯示當年12個月的客戶量 if i_dateFlag = 0 then begin --1.先根據i_date計算出i_date以前全部的客戶量 select nvl(count(*),0) into l_allCounts from t_customer tc where tc.add_date < i_date || '0101'; --2.再將結果相加返回給前臺 open o_resultCursor for select rownum, ny, sumCs, cstmAllNum, max(sumCs) over() as maxSumCs, min(sumCs) over() as minSumCs, max(cstmAllNum) over() as maxCstmAllNum, min(cstmAllNum) over() as minCstmAllNum from (select rownum, ny, sumCs, (sum(sumCs) over(order by ny) + l_allCounts) as cstmAllNum from (select nvl(substr(tc.add_date, 0, 6),0) as ny, nvl(count(tc.cstm_id),0) as sumCs from t_customer tc where substr(tc.add_date, 0, 4) = i_date --帶上區域id and (trim(i_zoneId) is null or tc.zone_id = i_zoneId) --帶上經銷商id and (trim(i_fchsId) is null or tc.fchs_id = i_fchsId) --帶上門店id and (trim(i_storeId) is null or tc.store_id = i_storeId) group by substr(tc.add_date, 0, 6)) order by ny); --加缺陷判斷 exception when others then raise l_exception; end; end if; --end i_dateFlag = 0 --2.i_dateFlag = 1,查詢當年前6年的數據 --按照年來分組 if i_dateFlag = 1 then begin --1.先計算出(l_currentYear - i_date + 1) || '0101以前的客戶量 select nvl(count(*),0) into l_allCounts from t_customer tc where tc.add_date < (l_currentYear - i_date + 1) || '0101'; --2.再將結果相加返回給前臺 open o_resultCursor for select rownum, ny, sumCs, cstmAllNum, max(sumCs) over() as maxSumCs, min(sumCs) over() as minSumCs, max(cstmAllNum) over() as maxCstmAllNum, min(cstmAllNum) over() as minCstmAllNum from (select rownum, ny, sumCs, (sum(sumCs) over(order by rownum) + l_allCounts) as cstmAllNum from (select nvl(substr(tc.add_date, 0, 4),0) as ny, nvl(count(tc.cstm_id),0) as sumCs from t_customer tc where substr(tc.add_date, 0, 4) between (l_currentYear - i_date + 1) and l_currentYear group by substr(tc.add_date, 0, 4)) order by ny); --加缺陷判斷 exception when others then raise l_exception; end; end if; --end i_dateFlag = 1 --3.i_dateFlag = 2時,只須要開始時間和結束時間 if i_dateFlag = 2 then begin --1.先計算出i_startTime以前的客戶量 select nvl(count(*),0) into l_allCounts from t_customer tc where tc.add_date < i_startTime; --2.再將結果相加返回給前臺 open o_resultCursor for select rownum, ny, sumCs, cstmAllNum, max(sumCs) over() as maxSumCs, min(sumCs) over() as minSumCs, max(cstmAllNum) over() as maxCstmAllNum, min(cstmAllNum) over() as minCstmAllNum from (select rownum, ny, sumCs, (sum(sumCs) over(order by rownum) + l_allCounts) as cstmAllNum from (select nvl(substr(tc.add_date, 0, 6),0) as ny, nvl(count(tc.cstm_id),0) as sumCs from t_customer tc where substr(tc.add_date, 0, 6) between i_startTime and i_endTime group by substr(tc.add_date, 0, 6)) order by ny); --加缺陷判斷 exception when others then raise l_exception; end; end if; --end i_dateFlag = 2 pkg_utility.sp_writeLog(i_log_type => 'INFO', i_acc_id => i_oprtAcc, i_sp_name => 'sp_getcustomersum', i_log_desc => '結束'); exception when l_exceptionAccount then --給遊標賦值 open o_resultCursor for select rownum, '' as ny, '' as sumCs, '' as cstmAllNum, '' as maxSumCs, '' as minSumCs, '' as maxCstmAllNum, '' as minCstmAllNum from dual where rownum = 1; when l_exception then o_errorNumber := PKG_CONSTANTS.C_RTN_FAILURE; when others then o_errorNumber := PKG_CONSTANTS.C_RTN_FAILURE; l_error_msg := '獲取客戶信息明細異常'; pkg_utility.sp_writeLog(i_log_type => 'ERROR', i_acc_id => i_oprtAcc, i_sp_name => 'sp_getcustomersum', i_log_desc => l_error_msg); end sp_getcustomersum;
結束
get