나는 pl/sql과 코딩에 비교적 익숙하고 도움을 주셔서 감사합니다. 다음과 같이 2 개의 테이블을 준비하십시오. 날짜 범위의 합계 (amt1) + 합계 (amt2)를 계산하는 함수 작성.다른 커서의 2 가지 변수의 합 계산 - Pl/sql function
나쁜 결과를 줄 수 있으므로 직접 table1과 table2를 연결할 수 없습니다. 커서를 table1에서 sum (amt1)을 계산하고 table2에서 sum (amt2)을 계산하기 위해 다른 커서를 계산했습니다. 어떻게 내가이 컴파일있어 제 기능입니다
Table 1
Id Amt Date
1 342 21-May-02
2 421 30-Mar-01
3 598 4-May-11
2 843 14-Jun-12
4 457 21-May-09
1 2346 24-Apr-98
Table 2
Id Amt2 Date2
1 342 21-May-02
2 421 30-Mar-01
3 598 4-May-11
2 843 14-Jun-12
4 457 21-May-09
1 2346 24-Apr-98
이 2 커서에서 합 (amt1) + 합계 (amt2)을 계산합니까하지만 난 그것을 테스트입니다 때, 어떤 값을 반환 나던
CREATE OR REPLACE FUNCTION FZ_HH_BY_DATE_COMMITMENT (pidm number,
start_date date,
end_date date,
desg varchar2)
RETURN number
AS
total_commit number(13,2) := 0;
total_gifts number(13,2) := 0;
total_pledges number(13,2) := 0;
sp_pidm number (9);
CURSOR date_commit_gifts IS
SELECT SUM(azvglst_amt) FROM acu.azvglst
WHERE azvglst_pidm IN (pidm, sp_pidm)
AND SUBSTR (azvglst_desg, 0, LENGTH (desg)) = desg
AND azvglst_gift_date BETWEEN start_date AND end_date
AND azvglst_pledge_no = '0000000'
AND (azvglst_pgve_code <> '3P' OR azvglst_pgve_code IS NULL);
CURSOR all_date_commit_gifts IS
SELECT SUM(azvglst_amt) FROM acu.azvglst
WHERE azvglst_pidm IN (pidm, sp_pidm)
AND azvglst_gift_date BETWEEN start_date AND end_date
AND azvglst_pledge_no = '0000000'
AND (azvglst_pgve_code <> '3P' OR azvglst_pgve_code IS NULL);
CURSOR date_commit_pledges
IS
SELECT SUM (agvplst_amt_pledged)
FROM agvplst
WHERE agvplst_pledge_date BETWEEN start_date AND end_date
AND SUBSTR (agvplst_desg, 0, LENGTH (desg)) = desg
AND agvplst_pidm IN (pidm, sp_pidm)
AND agvplst_psta_code NOT IN ('I','C','U');
CURSOR all_date_commit_pledges
IS
SELECT SUM (agvplst_amt_pledged)
FROM agvplst
WHERE agvplst_pledge_date BETWEEN start_date AND end_date
AND agvplst_pidm IN (pidm, sp_pidm)
AND agvplst_psta_code NOT IN ('I','C','U');
BEGIN
sp_pidm := TO_NUMBER (fz_split_fields (fz_spouse_info (pidm), 1));
IF desg IS NULL
THEN
OPEN all_date_commit_gifts;
FETCH all_date_commit_gifts INTO total_gifts;
CLOSE all_date_commit_gifts;
OPEN all_date_commit_pledges;
FETCH all_date_commit_pledges INTO total_pledges;
CLOSE all_date_commit_pledges;
ELSE OPEN date_commit_gifts;
FETCH date_commit_gifts INTO total_gifts;
CLOSE date_commit_gifts;
OPEN date_commit_pledges;
FETCH date_commit_pledges INTO total_pledges;
CLOSE date_commit_pledges;
END IF;
total_commit := total_gifts + total_pledges;
RETURN total_commit;
종료;
커서로 함수로 파싱중인 정보가있는 값이 반환되는지 여부를 테스트 했습니까? – Ben