Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Retrieve records for a particular month

james_pJan 7 2016 — edited Jan 7 2016

DB version: 11gR2

Is there a shorter way to find all orders placed on the month of June 2015 ? ie something shorter than the below mentioned one

create table orders (product varchar2(35), order_date date);

insert into orders VALUES ('APPLE' , TO_DATE('07-JUN-2015 21:00','DD-MON-YYYY HH24:MI')) ;

insert into orders VALUES ('ORANGE' , TO_DATE('07-JUN-2015 08:30','DD-MON-YYYY HH24:MI')) ;

insert into orders VALUES ('AVOCADO' , TO_DATE('21-SEP-2012 19:30','DD-MON-YYYY HH24:MI')) ;

SQL> alter session set nls_date_format='DD-MM-YYYY HH24:MI';

Session altered.

SQL> select * from orders;

PRODUCT                             ORDER_DATE

----------------------------------- ----------------

APPLE                               07-06-2015 21:00

ORANGE                              07-06-2015 08:30

AVOCADO                             21-09-2012 19:30

-- Retrieving all orders placed on the month of June 2015

SQL> Select * from orders where order_date  >= TO_DATE('01-JUN-2015 00:00','DD-MON-YYYY HH24:MI')

  2  and

  3  order_date <  TO_DATE('30-JUN-2015 23:59','DD-MON-YYYY HH24:MI');

PRODUCT                             ORDER_DATE

----------------------------------- ----------------

APPLE                               07-06-2015 21:00

ORANGE                              07-06-2015 08:30

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 4 2016
Added on Jan 7 2016
5 comments
5,388 views