title: Date and conditions using PL/SQL
body: <p>I am having a problem with the procedure below as whenever I pass a date of month and year, the IF condition loops on the number of records that exists in my table- only two rows existed- and also it shows the two possibilities. I also included the result to show what I mean!</p>
  
  <pre><code> PRODUCT_NUM   ORDER_NUM    QUANTITY        PRICE     MONTHLY_DATE
  -------------- ----------- ------------- ------------ -------------
     12345         106           3             19.99     21-DEC-15   
     67894         107           1             19.99     21-DEC-15
  
  
   CREATE OR REPLACE PROCEDURE Proce_Name (Pram_Date DATE ) 
     AS
   BGIN
    FOR Y IN 
      (SELECT SUM(PRICE) AS TOTAL_AMOUNT, SUM(NVL(QUANTITY,0) * NVL (   
      (PRICE,0)) AS TOTAL, MONTHLY_DATE   
      FROM PRODUCTS
      GROUP BY MONTHLY_DATE 
      ORDER BY MONTHLY_DATE DESC) LOOP
      IF  TO_CHAR( Y.MONTHLY_DATE, 'mm-yyyy')= TO_CHAR(Pram_Date,'mm-yyyy') THEN
       DBMS_OUTPUT.PUT_LINE('TOTAL AMOUNT: '|| '  '|| Y.TOTAL_AMOUNT);
       DBMS_OUTPUT.PUT_LINE('');
       DBMS_OUTPUT.PUT_LINE('TOTAL: '|| '   '||  Y.TOTAL);
     ELSE
       DBMS_OUTPUT.PUT_LINE('No Data for this month');
     END IF;
    END LOOP;
  
  END Proce_name;
  </code></pre>
  
  <p>calling block:</p>
  
  <pre><code>DECLARE
     MONTHLY_D DATE := TO_DATE('01-2012','mm-yyyy');
  BEGIN
   Proce_Name(MONTHLY_D);
  END;
  </code></pre>
  
  <p>/</p>
  
  <p>This is when the date I pass matches the records in the table: </p>
  
  <pre><code>     No Data for this month
  
       TOTAL AMOUNT:   4
  
       TOTAL:      99.96
  </code></pre>
  
  <p>The result here when I pass a date that is not existed in the table:</p>
  
  <pre><code>     No Data for this month
       No Data for this month
  </code></pre>
  
  <p>How can I alter my procedure to examine the above date format accurately ? </p>
  
  <p><a href="https://i.stack.imgur.com/823DA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/823DA.png" alt="enter image description here"></a></p>