Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Oracle Newbie - SQL question

Re: Oracle Newbie - SQL question

From: Jack Straw <jkstraw_no_spam__at_hotmail.com>
Date: Wed, 17 Jul 2002 17:54:03 GMT
Message-ID: <%aiZ8.2493$95.40166@news>


Thank you very much for the reply!

I am still a little unclear however. (or maybe just slow!)

I understand that it is subtracting 1 from the hire_date, but I don't see where the ORDER BY statement tells it to sort starting at Monday.

For example I read the statement as follows:

ORDER by TO_CHAR(hire_date -1,'d')

ORDER [the results] BY
TO_CHAR [convert from number to character] (hire_date -1 [subtract 1 day from the hire date], 'd'[no clude what this does?]

Questions:

  1. What does the 'd' represent?
  2. I have 20 rows of data with all different hire dates....how does subtracting 1 day from all the hire dates cause all rows to be ordered Monday -> Sunday in the query result?

thanks again...sorry if I am not catching on :-P

jon

"Sybrand Bakker" <postbus_at_sybrandb.demon.nl> wrote in message news:do9bjugff89u2hbp1j53pvjq9e89guuobl_at_4ax.com...
> On Wed, 17 Jul 2002 16:19:58 GMT, "Jack Straw"
> <jkstraw_no_spam__at_hotmail.com> wrote:
>
> >Hey everyone,
> >
> >Just getting my feet wet with Oracle and I have run into a question I was
> >hoping to get some help with.
> >
> >I am currently studying for the Oracle SQL cert and came accross this
> >question:
> >
> >"Display the last name, hire date and the day of the week on which the
> >employee started. Label the column DAY. ORder the results by the day of
> >the week starting with Monday"
> >
> >My question concerns the answer supplied in the text:
> >
> >"SELECT last_name, hire_date, TO_CHAR(hire_date,'fmDay')
> >FROM employees
> >ORDER by TO_CHAR(hire_date -1,'d')"
> >
> >I don't understand the ORDER BY clause.
> >
> >Specifically:
> >
> >1) "hire_date -1"
> >- My understanding is that Oracle's day 1 of a week is Sunday. It
doesn't
> >seem intuative to use "-1" to move a day forward? Am I misunderstanding
> >something?
> >
> >2) 'd'
> >- What does this represent? I had assumed "day" but that substitution
> >results in 'some other' weird grouping I don't understand. (ie. it
groups
> >all the days of the week but in no apparent order)
> >
> >Thanks in advance for any help!
> >
> >Jon
> >
> >
> >
> >
> 1 This is a trick solution. It subtracts one day from the hiredate and
> runs a to_char on it. Monday will end up as 1 instead of 2, Tuesday as
> 2 and so on.
>
> 2 The should return the ordinal day number.
>
> Hth
>
>
> Sybrand Bakker, Senior Oracle DBA
>
> To reply remove -verwijderdit from my e-mail address
Received on Wed Jul 17 2002 - 12:54:03 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US