How to write procedure in oracle database


Declare procedure verifyPointOutStandingByTcbsId(tcbsid_in IN varchar2)
is
sumOfCreditPointRedem number;
sumOfDebitPointRedem number;
resultRedem number;
currentBalanceRedem number;
sumOfCreditPointRank number;
sumOfDebitPointRank number;
resultRank number;
currentBalanceRank number;
begin

-- dbms_output.PUT_LINE('verifying this tcbsid: ' || tcbsid_in);
select sum(POINT)
into sumOfDebitPointRedem
from IXU_TRANSACTION_HISTORY
where ACTION = 'Debit'
and AWARD_TYPE = 'Redeemable'
and TCBSID = tcbsid_in;

select sum(POINT)
into sumOfDebitPointRank
from IXU_TRANSACTION_HISTORY
where ACTION = 'Debit'
and AWARD_TYPE = 'Ranking'
and TCBSID = tcbsid_in;

select sum(POINT)
into sumOfCreditPointRedem
from IXU_TRANSACTION_HISTORY
where ACTION = 'Credit'
and AWARD_TYPE = 'Redeemable'
and TCBSID = tcbsid_in;

select sum(POINT)
into sumOfCreditPointRank
from IXU_TRANSACTION_HISTORY
where ACTION = 'Credit'
and AWARD_TYPE = 'Ranking'
and TCBSID = tcbsid_in;

if sumOfDebitPointRedem is null then
sumOfDebitPointRedem := 0;
end if;
if sumOfDebitPointRank is null then
sumOfDebitPointRank := 0;
end if;
if sumOfCreditPointRedem is null then
sumOfCreditPointRedem := 0;
end if;
if sumOfCreditPointRank is null then
sumOfCreditPointRank := 0;
end if;
resultRedem := sumOfCreditPointRedem - sumOfDebitPointRedem;
resultRank := sumOfCreditPointRank - sumOfDebitPointRank;


SELECT (gl.REDEEMABLE_POINT)
into currentBalanceRedem
FROM IXU_GENERAL_LEDGER gl
where TCBSID = tcbsid_in;

SELECT (gl.RANKING_POINT)
into currentBalanceRank
FROM IXU_GENERAL_LEDGER gl
where TCBSID = tcbsid_in;

if currentBalanceRedem is null then
currentBalanceRedem := 0;
end if;
if currentBalanceRank is null then
currentBalanceRank := 0;
end if;

if currentBalanceRedem != resultRedem or currentBalanceRank != resultRank then
dbms_output.PUT_LINE(
'cbRedem: ' || currentBalanceRedem || '--' || 'resultRedem: ' || resultRedem || '=='||'cbRank: ' ||
currentBalanceRank || '--' || 'resultRank: ' || resultRank);
dbms_output.PUT_LINE('need check: ' || tcbsid_in);
end if;

end;
BEGIN
FOR tx IN (
SELECT distinct TCBSID as tcbsid
FROM IXU_GENERAL_LEDGER
-- where TCBSID IN ( '0001907082')
)
LOOP

verifyPointOutStandingByTcbsId(tx.tcbsid);
END LOOP;

-- commit;

END ;

Comments

Popular posts from this blog

Fixing the DeepSpeed Import Error While Fine-Tuning the Qwen Model

Amazon Linux 2023 - User data configuration for launch templates to connect to the EKS cluster

How to create ISM policy and rotate logs in opensearch