Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

What Day is Today

Posted on 2009-04-08
9
Medium Priority
?
876 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
9 Comments
 
LVL 143

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 143

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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 18

Expert Comment

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

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 143

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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
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 explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

688 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