Home » SQL & PL/SQL » SQL & PL/SQL » sql stmt precedence of functions and how they are evaluated.
sql stmt precedence of functions and how they are evaluated. [message #6433] Wed, 16 April 2003 15:04 Go to next message
Doug Tatum
Messages: 2
Registered: April 2003
Junior Member
Can anyone tell me the precedence of the operations in this stmt? I'm now cross-eye'd. The result is 4/22 given the sysdate of 4/16.

select

(to_char (trunc (sysdate) + 7 - to_number (to_char (sysdate + 7,'d')) +3, 'mm/dd'))

from dual

Thanks in advance.
Re: sql stmt precedence of functions and how they are evaluated. [message #6434 is a reply to message #6433] Wed, 16 April 2003 15:25 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
There's no real operator precedence issue here because the only operators involved are + and -, and they share the same level of precedence. Other than that, any expressions will be resolved before being included in the date/math calculations.

As written, it:

1) Takes midnight today (4/16)
2) Adds 7 days = 4/23
3) Subtracts the number of days equal to the day of week that is a week from today (a week from today is Wednesday, 4/23, and Wednesday is day 4 of the week - so we subtract 4 days = 4/19
4) Adds 3 days = 4/22
5) Convert the date to a character string.

By the way, the addition of 7 in step 3 is superfluous. A week from today will be the same day of week that today is.

Does this help?
Re: sql stmt precedence of functions and how they are evaluated. [message #6436 is a reply to message #6433] Wed, 16 April 2003 16:32 Go to previous message
Doug Tatum
Messages: 2
Registered: April 2003
Junior Member
Thanks Todd. Yes. I saw the wierdness in step 3 and it seemed odd. Don't you hate trying to figure out someone else's code? ;-)
Previous Topic: Selecting last record
Next Topic: Script to gather information about DDL stmts executed
Goto Forum:
  


Current Time: Fri Apr 26 19:33:28 CDT 2024