title: How to seperate a debit and credit in a cursor for loop in plsql
body: <p>I have a <code>cursor for loop</code> include credit and debit amount of my daily transaction account, and I want to show them respectively.</p>
  
  <pre><code>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;
  </code></pre>
  
  <p>This part of the SQL query from the above is showing all the debit and credit values.</p>
  
  <pre><code>+-----------------+
  | value  | code | |
  +-----------------+
  | | 12   |  dr  | |
  | |  5   |  dr  | |
  | |  7   |  dr  | |
  | | 33   |  dr  | |
  | | 16   |  dr  | |
  | | 1000 |  cr  | |
  +-----------------+
  </code></pre>
  
  <p>The problem I found because they are in the cursor loop, it will populate all value in one column like below</p>
  
  <pre><code>+-------+--------+
  | Debit | Credit |
  +-------+--------+
  |    12 |        |
  |     5 |        |
  |     7 |        |
  |    33 |        |
  |    16 |        |
  |  1000 |        |
  +-------+--------+
  </code></pre>
  
  <p>The if/else statement can't control it to show all row records.</p>
  
  <pre><code>+-------+--------+
  | Debit | Credit |
  +-------+--------+
  |    12 |    0   |
  |     5 |    0   |
  |     7 |    0   |
  |    33 |    0   |
  |    16 |    0   |
  |  1000 |    0   |
  |  1000 |  1000  |
  +-------+--------+
  </code></pre>
  
  <p>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?</p>
  
  <pre><code>+-------+--------+
  | Debit | Credit |
  +-------+--------+
  |    12 |        |
  |     5 |        |
  |     7 |        |
  |    33 |        |
  |    16 |        |
  |       |  1000  |
  +-------+--------+
  </code></pre>