You are getting wrong records because you are converting the dates into a string. That means the query uses string semantics when doing the comparison. As a string, '15-12-2999'
and '15-05-2000
are between '10-09-2018'
and '30-09-2018'
because '15'
has a higher ASCII value than '10'
and a lower ASCII value than '30'
.
The solution is quite simple: use date datatypes for the comparison.
select * from sales
where txn_date between date '2018-09-10' and date '2018-09-30'
If TXN_DATE has a time element you may want to change the query to
select * from sales
where txn_date >= date '2018-09-10'
and txn_date < date '2018-10-01'
Otherwise you will not retrieve records for transactions made after midnight on 30th September.
Alternatively you could remove the time element by truncating the date:
select * from sales
where trunc(txn_date) between date '2018-09-10' and date '2018-09-30'