title: Oracle decode function not working for date
body: <p>The query does not give correct result. I am giving submit date between 01-Dec-14 to 30-Dec-14 but getting result for Nov.</p>
  
  <pre><code>SELECT DISTINCT O.id,
                  pg.name,
                  pt.name,
                  PP.company_name,
                  PP.code,
                  O.order_number,
                  O.status,
                  O.submit_date,
                  O.approval_date
  FROM   orders O,
         partnerprofile PP,
         partnertype pt,
         partnergroup pg
  WHERE  PP.id = O.to_partner_id
         AND Pp.type_id (+) = 8
         AND o.ordering_ratio_flag = Decode('NO', 'YES', '1',
                                                  'NO', '0')
         AND pp.group_id = pg.id
         AND Pp.type_id(+) = Pt.id
         AND Decode(NULL, NULL, '1',
                          Pp.code) = Decode(NULL, NULL, '1',
                                                  NULL)
         AND submit_date BETWEEN Decode('01-Dec-14', NULL, ( '01-JAN-01' ),
                                                     '01-Dec-14') AND
                                     Decode('30-Dec-14', NULL, ( '01-JAN-01' ),
                                                         '30-Dec-14')
         AND approval_date BETWEEN Decode(p_approved_from, NULL, ( '01-JAN-01' ),
                                                           p_approved_from) AND
                                   Decode(
                                       p_approved_to, NULL, ( '01-JAN-01' ),
                                                      p_approved_to
                                                                                )
         AND Decode(p_status, NULL, '1',
                              O.status) = Decode(p_status, NULL, '1',
                                                           p_status)
  ORDER  BY O.id; 
  </code></pre>