Home » SQL & PL/SQL » SQL & PL/SQL » Date Question
Date Question [message #23101] Mon, 18 November 2002 10:52 Go to next message
Rizwan Qazi
Messages: 135
Registered: August 2002
Senior Member
I have a field called book_date. I want to write a query where I want to replace the output by the first day of the corresponding month. The query I am using currently is

select ADD_MONTHS(LAST_DAY(BOOK_DT),-1)+1 from TRANSACTION_QUEUE

to Return this output

I tried to use

select TO_DATE(TO_CHAR(BOOK_DT),'YYYYMM') from TRANSACTION_QUEUE
but I get the error

ERROR at line 1:
ORA-01830: date format picture ends before converting entire input string

What am I doing wrong? Which query is more efficient?

Thanks,

Rizwan
Re: Date Question [message #23103 is a reply to message #23101] Mon, 18 November 2002 11:14 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
select trunc(book_dt, 'mm')
  from transaction_queue;


will be the most efficient way to do this...
Re: Date Question [message #23109 is a reply to message #23101] Mon, 18 November 2002 15:13 Go to previous messageGo to next message
Amit Chauhan
Messages: 74
Registered: July 1999
Member
Hi,
Just to elaborate on Todd's reply. The query you are looking for may look like this :
select to_date ('01'||to_char(book_dt, 'mmyyyy'), 'ddmmyyyy')
from transaction_queue


Hope that helps
Thanks
Amit
Re: Date Question [message #23111 is a reply to message #23101] Mon, 18 November 2002 15:34 Go to previous message
Amit Chauhan
Messages: 74
Registered: July 1999
Member
Hi Todd,
My apologies. You are right.
I totally forgot abt this.

Price you pay when you dont work in Oracle for some time.

Thanks
Amit
Previous Topic: Best way to process large volume of data (Oracle9i)
Next Topic: Re: Best way to process large volume of data (Oracle9i)
Goto Forum:
  


Current Time: Mon Apr 29 05:07:44 CDT 2024