sql - how can i run this select to_char('01-jan-2016',day dd ddspth month yyyy) from dual; why to_date function not give output to our desire format? -
why query not run on oracle select to_date('01-jan-2016',day dd ddspth month yyyy) dual;
? why date function not give output our desire format?
why to_char
function not run in @ runtime? why run in in attribute sysdate
or else
?
i know select to_char(to_date('01-jan-2016',day-month-yyyy) dual;
run on oracle want run @ runtime without specific attribute select to_char('01-jan-2016',day-month-yyyy) dual;
. same case to_date
function.
why query not run on oracle
select to_date('01-jan-2016',day dd ddspth month yyyy) dual;
? why date function not give output our desire format?
the query not run because violate proper syntax. easy check oracle documentation post questions here. to_date
takes string parameter, did fine. '01-jan-2016'
fine. second argument should tell compiler format used string. string '01-jan-2016'
gave format model 'day dd ddspth month yyyy'
- there no connection between , '01-jan-2016'
. not oracle's fault (or anyone's fault on forum), ask more nicely.
your format dd
(day, 2 digits), dash (-
), short form of month name in english, lower-case letters, dash (-
), year (four digits). correct mask 'dd-mon-yyyy'
try this:
select to_date('01-jan-2016', 'dd-mon-yyyy') dual;
a couple of things this. first, solution assumes session date language english or american or such; if it's italian or chinese, jan
not recognized valid month name (short form). if in fact error message ora-01843, "not valid month", first check make sure jan spelled correctly, , check nls_date_language parameter.
second, ask "date function" giving "output our desired format." please learn more difference between dates , character strings. dates not have format. strings do. call to_date()
way wrote query show date, not string. show according nls_date_format parameter. can check both nls parameters mentioned here select * nls_session_parameters;
if want input date in format '01-jan-2016'
, want result string, showing same date in different format, must first translate string '01-jan-2016'
date - showed how above. then, must put inside call to_char()
, take date , present string, in whatever (other) format want. this:
select to_char(to_date('01-jan-2016', 'dd-mon-yyyy'), 'day dd ddspth month yyyy') dual;
the result looks (note column name - if don't use alias in select
statement, you'll garbage names that):
to_char(to_date('01-jan-2016','dd --------------------------------- friday 01 first january 2016
note many spaces between friday
, 01
. format model 'day' creates string of length equal longest day-of-the-week name in english. 9, length of wednesday. shorter names padded right blank spaces max length. note names friday , january, both lower-case; if want capitalized initial (as customary in english), should use day , month instead of day , month in format mask.
finally, query has mistake. format mask must string (enclosed in single quotes). didn't that, error message that, if else correct.
i didn't understand second , third paragraphs (which means nonsensical, since english pretty good); if rewrite them make sense, may still volunteers willing you, if show more respect. luck!
Comments
Post a Comment