Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple oracle sql statement question 1

Status
Not open for further replies.

mikeyd

Technical User
Jan 28, 2002
38
US
How can I use a select * from statement and also use the to_char function for a date so it shows the date with hour and minutes.

For example I am tying this but it is not working

select *, to_char(lastupdatetime, 'DD:MON:YY:HH:MI:SS AM)
from whatevertable

I just want to be able to select all and format the date in the lastupdatetime field all in one statement.
thanks and sorry for the simple question I just can not remember how to do it.

 
a) You're missing a quote at the end of the date format.
b) To do a select * and also another column, you would need to give an alias to the table name.
c) You need to make sure that lastupdatetime is definitely a date, not a varchar2.

select w.*, to_char(lastupdatetime, 'DD:MON:YY:HH:MI:SS AM')
from whatevertable w

If you just want to test the date format mask on its own, the easiest way to do this is just apply it to SYSDATE e.g.

select to_char(sysdate, 'DD:MON:YY:HH:MI:SS AM') from dual



For Oracle-related work, contact me through Linked-In.
 
When you use the astersik you get all columns, so you will see lastupdatetime twice.
Code:
SELECT whatevertable.*, to_char(lastupdatetime, 'DD:MON:YY:HH:MI:SS AM)
  FROM whatevertable
 
Thanks guys...that is exactely what I was looking for.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top