niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Databases » Oracle
to_char syntax
Post new topic   Reply to topic Page 1 of 1 [7 Posts] View previous topic :: View next topic
Author Message
Liz J
*nix forums beginner


Joined: 01 Aug 2005
Posts: 4

PostPosted: Thu Feb 23, 2006 12:10 am    Post subject: to_char syntax Reply with quote

Hi

Could someone help me with some syntax?

I know that

SELECT To_char (sysdate, 'ddth Month YYYY')

will give me the format I want if it is today's date that I need.

But suppose it is another date that I know - say 3rd February 2006?

I can't get the syntax right.

thanks

Liz
Back to top
Mark D Powell
*nix forums Guru


Joined: 23 Apr 2005
Posts: 701

PostPosted: Thu Feb 23, 2006 2:02 am    Post subject: Re: to_char syntax Reply with quote

To convert a character representation to a date you use the to_date
function:

to_date('03-Feb-2006','DD-Mon-YYYY')

If you have a character representation of a date and you want to
reformat it but keep it in character format you can either use the
provide character manipulation functions like instr, substr, lenght,
replace, and transform or you can convert the data to a date with
to_date and enclose the to_date in a to_char to convert the data back
to character representation.

Normally you to_date the data into the database one time and use
to_char to display the data as desired.

All functions mentioned in my reply are described in the SQL manual
chapter on single row functions.

HTH -- Mark D Powell --
Back to top
Randy Harris
*nix forums Guru Wannabe


Joined: 23 Apr 2005
Posts: 202

PostPosted: Thu Feb 23, 2006 4:09 am    Post subject: Re: to_char syntax Reply with quote

"Liz J" <thejordanschangethistoanatsignclara.net> wrote in message
news:1140653404.29042.0@damia.uk.clara.net...
Quote:
Hi

Could someone help me with some syntax?

I know that

SELECT To_char (sysdate, 'ddth Month YYYY')

will give me the format I want if it is today's date that I need.

But suppose it is another date that I know - say 3rd February 2006?

I can't get the syntax right.

thanks

Liz



How about:

To_char ('03-Feb-2006', 'ddth Month YYYY')

--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.
Back to top
Martin Doherty
*nix forums beginner


Joined: 10 Jan 2006
Posts: 23

PostPosted: Thu Feb 23, 2006 3:41 pm    Post subject: Re: to_char syntax Reply with quote

Randy Harris wrote:

Quote:
"Liz J" <thejordanschangethistoanatsignclara.net> wrote in message
news:1140653404.29042.0@damia.uk.clara.net...


Hi

Could someone help me with some syntax?

I know that

SELECT To_char (sysdate, 'ddth Month YYYY')

will give me the format I want if it is today's date that I need.

But suppose it is another date that I know - say 3rd February 2006?

I can't get the syntax right.

thanks

Liz





How about:

To_char ('03-Feb-2006', 'ddth Month YYYY')



That might work, but it relies on an implicit type conversion of the

literal string '03-Feb-2006' into a valid date, and assumes that the
default NLS_DATE_FORMAT string is set to 'dd-mon-yyyy'.

A safer method would be
to_char(to_date('03-Feb-2006', 'dd-mon-yyyy'), 'ddth Month YYYY')
Back to top
Mark C. Stock
*nix forums Guru


Joined: 05 May 2005
Posts: 730

PostPosted: Thu Feb 23, 2006 4:12 pm    Post subject: Re: to_char syntax Reply with quote

:
: "Martin Doherty" <martin.doherty@undisclosed.com> wrote in message
news:7YkLf.30$AP2.42@news.oracle.com...
: Randy Harris wrote:
:
: : "Liz J" <thejordanschangethistoanatsignclara.net> wrote in message
: : news:1140653404.29042.0@damia.uk.clara.net...
: :
: : How about:
: :
: : To_char ('03-Feb-2006', 'ddth Month YYYY')
: :
:
: That might work, but it relies on an implicit type conversion of the
literal string '03-Feb-2006' into a valid date, and assumes
: that the default NLS_DATE_FORMAT string is set to 'dd-mon-yyyy'.
:
: A safer method would be
: to_char(to_date('03-Feb-2006', 'dd-mon-yyyy'), 'ddth Month YYYY')
:

better yet:

to_char(date '2006-02-03', 'ddth Month YYYY')

++ mcs
Back to top
Liz J
*nix forums beginner


Joined: 01 Aug 2005
Posts: 4

PostPosted: Thu Feb 23, 2006 11:49 pm    Post subject: Re: to_char syntax Reply with quote

"Many thanks everyone

Liz
Back to top
Randy Harris
*nix forums Guru Wannabe


Joined: 23 Apr 2005
Posts: 202

PostPosted: Fri Feb 24, 2006 12:36 am    Post subject: Re: to_char syntax Reply with quote

"Liz J" <thejordanschangethistoanatsignclara.net> wrote in message
news:1140738562.18261.0@damia.uk.clara.net...
Quote:

"Many thanks everyone

Liz


Liz, the solutions suggested by Mark and Martin are much better than the one
I offered, since they don't depend on implicit type coercion.

--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [7 Posts] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 5:39 pm | All times are GMT
navigation Forum index » Databases » Oracle
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Invalid syntax with STD() function when more than one fie... William Bronsema MySQL 1 Thu Jul 20, 2006 2:18 pm
No new posts to_char number format with optional decimal-point? Martin T. Oracle 3 Thu Jul 20, 2006 10:53 am
No new posts dk-milter: syntax error in signature data Tuan Van Postfix 1 Wed Jul 19, 2006 9:58 pm
No new posts Must GET/POST Parameters Have Values? (And What is the Sy... David T. Ashley PHP 2 Wed Jul 19, 2006 1:10 am
No new posts Good Representation for an Abstract Syntax Tree johan.tibell@gmail.com C 9 Tue Jul 18, 2006 1:28 pm

Debt Consolidation | Online College Degrees | Credit Card | Loans | Credit Cards
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.3780s ][ Queries: 16 (0.2751s) ][ GZIP on - Debug on ]