I have a cursor for loop include credit and debit amount of my daily transaction account, and I want to show them respectively.

DECLARE

v_debit := 0;
v_credit := 0;

CURSOR c_acct_rec is 
select bk.acctname, bk.bsb, bk.accountnr, bk.value, bk.code
from mybank_tbl bk
r_acct_rec c_acct_rec%ROWTYPE;

FOR r_acct_rec in c_acct_rec LOOP
   if r_acct_rec.code = 'dr' then
      v_debit := show_debit;     
   else
      v_credit := v_credit + r_acct_rec;
   end if;

DBMS_OUTPUT.PUT_LINE(v_credit || v_debit); 

END LOOP;
END;

This part of the SQL query from the above is showing all the debit and credit values.

+-----------------+
| value  | code | |
+-----------------+
| | 12   |  dr  | |
| |  5   |  dr  | |
| |  7   |  dr  | |
| | 33   |  dr  | |
| | 16   |  dr  | |
| | 1000 |  cr  | |
+-----------------+

The problem I found because they are in the cursor loop, it will populate all value in one column like below

+-------+--------+
| Debit | Credit |
+-------+--------+
|    12 |        |
|     5 |        |
|     7 |        |
|    33 |        |
|    16 |        |
|  1000 |        |
+-------+--------+

The if/else statement can't control it to show all row records.

+-------+--------+
| Debit | Credit |
+-------+--------+
|    12 |    0   |
|     5 |    0   |
|     7 |    0   |
|    33 |    0   |
|    16 |    0   |
|  1000 |    0   |
|  1000 |  1000  |
+-------+--------+

Is that a way to separate it using a stored procedure or separate the row from the account value (r_acct_rec.value) to check to get this expected outcome?

+-------+--------+
| Debit | Credit |
+-------+--------+
|    12 |        |
|     5 |        |
|     7 |        |
|    33 |        |
|    16 |        |
|       |  1000  |
+-------+--------+

0 Answers