NLS setting for multilanguages - forms

My current application is running with NLS_lang as American.america on Oracle forms. We are planning make this application available on multilanguage. we are in the process of the modifying the code to handle application labels, prompts,hint, messages,etc run time. we dont want to change the time/date formats and leave it as it would in American.america. But for example, When i change the NLS_lang to French_canadian or anything else. Along with the language the date formats and date language paramters are changing. I am in need to change the NLS_lang as that is the only way i can translate the oracle error messages. But my date formats having DD-MON-YYYY format in Oracle DB create a problem in my weblogic sesssion. Is there are way to only change my weblogic session for my forms to be French_canadian but leave the date formats/ date format languages in American? Can we make this happen? except Language other paramters to remain same as american??? Please help.
Advance thanks for your time and valuable ideas...

You can set language and date/time formats individually.
Have a look at these parameters:
NLS_DATE_FORMAT
NLS_DATE_LANGUAGE
NLS_LANGUAGE
NLS_TERRITORY
NLS_NUMERIC_CHARACTERS
NLS_LANG is used to define the default for all these, but each of them can be different.
With NLS_TERRITORY you can commonly set "NLS_DATE_FORMAT", "NLS_NUMERIC_CHARACTERS", "NLS_CURRENCY", and "NLS_ISO_CURRENCY"
See example here:
ALTER SESSION SET NLS_TERRITORY = 'germany';
ALTER SESSION SET NLS_LANGUAGE = 'polish';
ALTER SESSION SET NLS_DATE_LANGUAGE = 'french';
SELECT SYSDATE AS german_date_format, TO_CHAR(SYSDATE, 'Day') AS french_day FROM dual;
SELECT 1/0 AS polish_error_message FROM dual;
GERMAN_DATE_FORMAT FRENCH_DAY
--------------------------------
23.01.14 Jeudi
SELECT 1/0 AS polish_error_message FROM dual
*
Error at line 1
ORA-01476: dzielnik jest równy zero

Related

sql developer issue in visualizing date

since few weeks I started working on SQL developer.
I noticed an important issue that I do not know how to solve. This is related to the way my SQL developer visualizes the date.
First of all, here are my settings:
and here is my problem:
select to_date('01-01-0001', 'DD-MM-YYYY') from dual;
Instead of correctly visualizin 01-01-2001, it visualizes 03-JAN-0001
select select to_date('01-01-2001', 'DD-MM-YYYY') from dual;
It is interesting to observe that the issue of the day disappear when we change year.
So this -
defines for your session how to display dates and timestamps.
Example:
If you were querying a date w/o supplying a date format, then it adopts said settings.
But if you query a string, and ask Oracle to treat it as a date
select to_date('1-1-1990', 'DD-MM-YYYY') from dual;
The DD-MM-YYYY tells Oracle how to interpret your string as a date.
And then the output is shown using the format defined for NLS
Now, for your scenario, the year '1' - there is a bug in SQL Developer 18.1 that is causing the date to come back as 3 vs 1.
Bug 28093149 - DATE IS RETURNED INCORRECTLY FOR 01/01/0001 - COMES BACK AS 03/01/0001

Postgres timestamp to date

I am building a map in CartoDB which uses Postgres. I'm simply trying to display my dates as: 10-16-2014 but, haven't been able to because Postgres includes an unneeded timestamp in every date column.
Should I alter the column to remove the timestamp or, is it simply a matter of a (correct) SELECT query? I can SELECT records from a date range no problem with:
SELECT * FROM mytable
WHERE myTableDate >= '2014-01-01' AND myTableDate < '2014-12-31'
However, my dates appear in my CartoDB maps as: 2014-10-16T00:00:00Z and I'm just trying to get the popups on my maps to read: 10-16-2014.
Any help would be appreciated - Thank you!
You are confusing storage with display.
Store a timestamp or date, depending on whethether you need time or not.
If you want formatted output, ask the database for formatted output with to_char, e.g.
SELECT col1, col2, to_char(col3, 'DD-MM-YY'), ... FROM ...;
See the PostgreSQL manual.
There is no way to set a user-specified date output format. Dates are always output in ISO format. If PostgreSQL let you specify other formats without changing the SQL query text it'd really confuse client drivers and applications that expect the date format the protocol specifies and get something entirely different.
You have two basic options.
1 Change the column from a timestamp to a date column.
2 Cast to date in your SQL query (i.e. mytimestamp::date works).
In general if this is a presentation issue, I don't usually think that is a good reason to muck around with the database structure. That's better handled by client-side processing or casting in an SQL query. On the other hand if the issue is a semantic one, then you may want to revisit your database structure.

Format Hour in DB2?

Is there any way to display db2 Hour function with AM and PM?
select hour(TIMESTAMP) from ORDERS with ur
This will give out like 5,6,7 etc..
But i want AM/PM after the Hour time.
I'd like to Dislpay as 5AM,6AM,7AM. Is it possible in db2?
Use the TIME() and CHAR() functions:
SELECT CHAR(TIME(timestamp), USA)
FROM Orders
WITH UR
Although, honestly, you should be doing this type of formatting in the application layer, not the SQL Layer.
(Statement run on my local DB2 instance)
EDIT:
Sorry, I missed that part earlier. Going through the documentation has shown me a new function, VARCHAR_FORMAT(). Assuming you're on DB2 9.5, the following should grant you some form of what you're looking for:
SELECT VARCHAR_FORMAT(timestamp, 'HH12 AM')
FROM Orders
WITH UR
Unfortunately, I can't test this myself, as iSeries V6R1 doesn't support the HH12 flag (HH24 only, what?). Otherwise, you're going to have to parse it out yourself.

How do I alter the date format in Postgres?

I'm getting the following error message
ERROR: date/time field value out of range: "13/01/2010"
HINT: Perhaps you need a different "datestyle" setting.
I want to get my date in the format DD/MM/YYYY
SHOW datestyle;
DateStyle
-----------
ISO, MDY
(1 row)
INSERT INTO container VALUES ('13/01/2010');
ERROR: date/time field value out of range: "13/01/2010"
HINT: Perhaps you need a different "datestyle" setting.
SET datestyle = "ISO, DMY";
SET
INSERT INTO container VALUES ('13/01/2010');
INSERT 0 1
SET datestyle = default;
SET
http://www.postgresql.org/docs/current/static/runtime-config-client.html#GUC-DATESTYLE
DateStyle - Sets the display format
for date and time values, as well as
the rules for interpreting ambiguous
date input values.
For historical reasons, this variable
contains two independent components:
the output format specification (ISO,
Postgres, SQL, or German) and the
input/output specification for
year/month/day ordering (DMY, MDY, or
YMD).
Of course it's best to use unambiguous input format (ISO 8601), but there is no problem to adjust it as you need.
You could set the date style to European dd/mm/yyyy:
SET DateStyle TO European;
I'd advise against this though. I generally try to convert between formats, and keep ISO formatted dates in the data source. After all, it's only a matter of representation, not a matter of different data.
Edit:
When using this COPY, the valid input format is defined by the server configuration and can either be changed for the current session using the SET command as described by Berry or by adjusting the server configuration.
DateStyle description in the manual:
http://www.postgresql.org/docs/current/static/runtime-config-client.html#GUC-DATESTYLE
The following is not valid for the real situation, but I'm keeping it for reference anyway
When using date (or timestamp) literals always specify a format mask to convert them. Otherwise your statements aren't portable and won't necessarily run on every installation.
The ANSI SQL standard for date literals is like this:
UPDATE some_table
SET date_column = DATE '2011-05-25'
WHERE pk_column = 42;
If you cannot change the literal format, you need to apply the to_date() function
UPDATE some_table
SET date_column = to_date('13/01/2010', 'dd/mm/yyyy')
WHERE pk_column = 42;
If this is not what you are doing you should show us the full SQL statement that generated the error.

Best method for varchar date validation in Sybase (T-SQL)?

I have a stored procedure which takes as its parameter a varchar which needs to be cast as a datetime for later use:
SET #the_date = CAST(#date_string AS DATETIME)
I'm expecting the date string to be supplied in the format "DD-MON-YYYY", but in an effort to code defensively, if for some reason it can't be cast successfully, I want to default to the system date and continue. In PL/SQL I could use exception handling to achieve this and I could do this fairly easily with regular expressions too, but the limited pattern matching supported out of the box by Sybase doesn't let me do this and I can't rely on third party libraries or extensions. Is there a simple way of doing this in T-SQL?
NB: using Sybase ASE 12.5.3, there is no ISDATE function
I'm having a similar issue. You might be able to do something like this:
SET arithabort arith_overflow off
SET #the_date = CAST(#date_string AS DATETIME)
IF #the_date is NULL
set #the_date = getdate()
SET arithabort arith_overflow on
However, this doesn't work well in a select. It will work well in a cursor (boo) or in logic before / after a SQL batch.
My goodness, if the question was about Microsoft SQL Server then we'd have been in business!
Sybase, sadly, is a whole 'nother database these days, since about 1997, in fact, give or take a year.
If the input format simply has to be 'DD-MON-YYYY' and no exceptions, then I think a fair amount of validation was be achieved by slicing the input using SUBSTR(), after first doing some simple things, such as checking length.
I thought that recent releases of Sybase (SQL Anywhere 11, for example) have regular expression support, however, although it's been a while since I've had to suffer T-SQL. Some googling leaves me in rather more doubt.
Can't you do something like this:
SELECT #the_date = CASE #date_string
WHEN '[0-9][0-9]-[A-Z][A-Z][A-Z]-[0-9][0-9][0-9][0-9]'
THEN CONVERT(datetime, #date_string)
ELSE GETDATE()
END
?
Found this in the second result in Google when searching for "validate date string sql".
----Invalid date
SELECT ISDATE('30/2/2007')
RETURNS : 0 (Zero)
----Valid date
SELECT ISDATE('12/12/20007')
RETURNS : 1 (ONE)
----Invalid DataType
SELECT ISDATE('SQL')
RETURNS : 0 (Zero)
Make sure SQL Server knows the order of Days, Months and Years in your string by executing
SET DATEFORMAT mdy;
Did you try convert instead of cast?
select convert( datetime , #date_string )