Solved

What Day is Today

Posted on 2009-04-08
9
854 Views
Last Modified: 2013-12-19
Hey Folks,

I was wondering if you could help?  Needless to say I was driven crazy for a week before I whittled the problem down to the fact that our databases are set to "AMERICA" when we are in "AUSTRALIA":

select * from sys.props$ where name = 'NLS_TERRITORY'
gives...
NAME    VALUE$    COMMENT$
NLS_TERRITORY    AMERICA    Territory

The question is:
Why do different Oracle clients give me a different answer to...?
select sysdate, to_char(sysdate, 'D') day_id from dual

If Today is Thursday, the answer to this SELECT is different with different VB.NET, Oracle clients (11g ODP.NET / 9i OracleClient)...

Oracle 9i design time (running query as "Preview Data" in a strongly-typed dataset)
9/04/2009 1:59 PM      5

Oracle 9i runtime:
9/04/2009 2:00 PM      4 (correct as far as I'm concerned!!!)

Oracle 11g (design / runtime):
9/04/2009 2:01 PM      5

I would like to be able to run either client and always get an answer of "4" for a Thursday.

Any help would be most appreciated.

cheers,
SnowyIT

0
Comment
Question by:hydroIT
  • 3
  • 3
  • 3
9 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24104073
try this:

select sysdate, to_char(sysdate, 'D', NLS_TERRITORY 'AMERICA') day_id from dual

Open in new window

0
 

Author Comment

by:hydroIT
ID: 24104336
Hmmm, thanks Angellll, looking good...

However, is that the exact syntax?  It gives the error:

ORA-00907: missing right parenthesis

BTW Looking in:
HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\

I noticed my home, which is 9i (\HOME0), has NLS_LANG key = "ENGLISH_AUSTRALIA.WE8MSWIN1252"
whereas 11g (\KEY_ora11g) has NLS_LANG = "AMERICAN_AMERICA.WE8MSWIN1252"

whereas

Cheers


0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24104608
sorry, small typo:
http://www.ss64.com/orasyntax/nls.html

select sysdate, to_char(sysdate, 'D', 'NLS_TERRITORY=AMERICA') day_id from dual

Open in new window

0
 
LVL 18

Expert Comment

by:sventhan
ID: 24107151
try this...
select sysdate, to_char(sysdate, 'DAY') TODAY_IS from dual  
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:hydroIT
ID: 24134482
Thanks guys,

Angellll, your updated sql still seems to upset Oracle:
"select sysdate, to_char(sysdate, 'D', 'NLS_TERRITORY=AMERICA') day_id from dual"
gives
ORA-12702: invalid NLS parameter string used in SQL function

and Sventhan, using 'DAY' as a format gives "TUESDAY" for instance but I was hoping on getting the Day of Week index (ie "2") as that is used in referenced tables as a foreign key.

Any other ides?
Many thanks
HydroIT
0
 
LVL 18

Expert Comment

by:sventhan
ID: 24136605
try this...

select sysdate, to_char(sysdate, 'D') TODAY_IS from dual  
http://www.techonthenet.com/oracle/functions/to_char.php 
0
 

Accepted Solution

by:
hydroIT earned 0 total points
ID: 24144141
Hey Sventhan,

Thanks for the suggestion, but that's the sql that has been not playing ball from the start.  It is dependent on you "NLS_LANG" registry property of your client locale.

I think I have finally found the answer on another thread:
http://forums.oracle.com/forums/thread.jspa?messageID=2022888

select mod(to_char(sysdate, 'J'), 7) + 1 from DUAL

Cheers for your efforts,
HydroIT
0
 
LVL 18

Expert Comment

by:sventhan
ID: 24144376
sooper!!!
I'm glad you found the solution.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24158045
sorry for coming back "late". this should do also, simpler, without having to rely on the current client's nls_xxx settings:

TO_CHAR(sysdate, 'D', 'nls_date_language = American')

Open in new window

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now