On 19-Aug-2016 14:53 -0700, Bruno Almeida wrote:
>
> DB2 10.1 LUW
>
> I'm trying to understand this scenario:
>
> <<SNIP>>
>
> $ db2 "insert into TEST values ('08/20/2016')"
> DB21034E The command was processed as an SQL statement because it was
> not a valid Command Line Processor command. During SQL processing it
> returned:
> SQL0181N The string representation of a datetime value is out of
> range. SQLSTATE=22007
>
> $ db2 "insert into TEST values ('20/08/2016')"
> DB20000I The SQL command completed successfully.
>
>
> $ db2 "select * from TEST"
>
> C1
> ----------
> 08/19/2016
> 08/20/2016
>
> 2 record(s) selected.
>
> db2inst1@renata-molinaro:~$ db2 get db cfg | grep -i territory
> Database territory = US
>
> Would you help me with this issue?
>
If all that is required is to have a circumvention, then I suspect
that one or both of the following should assist to effect the insert of
a date literal representing 20-Aug-2016, irrespective the /territory/ or
other date-formatting attributes established for the DB2 LUW Command
Line Processor (CLP):
db2 "insert into TEST values ( date'2016-08-20' )"
db2 "insert into TEST values ( '2016-08-20' )"
For reference, the following document suggests a revision to the "CLP
packages" binding established for date-formatting; perhaps of possible
assistance in the scenario of the OP, despite the quite specific nature
of the issue being quite different:
[
http://www.ibm.com/support/docview.wss?uid=swg21437999]
SQL0180N error from the DB2 Command Line Processor (CLP) when date
with default format concatenated with timestamp …
Reference #: 1437999
"…
What are the solutions available to change from one format to another?
Users can follow the below methods to resolve the problem:
• Bind the CLP packages using the ISO format
db2 bind @db2ubind.lst DATETIME ISO SQLERROR CONTINUE
…"
FWiW:
Perhaps not very helpful to offer, but the IBM DB2 for i would have
accepted the value for the first of the INSERT requests quoted above
[i.e. the failing INSERT], and would have rejected the second of the
INSERT requests quoted above [i.e. the successful INSERT] with the same
sqlcode\sqlstate as the above-quoted failing INSERT; i.e. the opposite
effect would have been exhibited using a DB2 for i SQL session, and that
remains true, irrespective the date-formatting attributes established:
set current schema qtemp
-- SET CURRENT SCHEMA statement complete.
create table test ( c1 date )
-- Table TEST created in QTEMP.
insert into TEST values current date
-- 1 rows inserted in TEST in QTEMP.
select * from TEST
-- SELECT statement run complete.
-- the report was two row values: 08/20/2016
insert into TEST values ('08/20/2016')
-- 1 rows inserted in TEST in QTEMP.
insert into TEST values ('20/08/2016')
-- SQL0180 "Value in date, time, or timestamp string not valid."
The reason for that opposite effect, is that with the DB2 for i, the
string representation for a date, the one that was shown being used,
matches to the "IBM® USA standard" format of "mm/dd/yyyy"; i.e. the
##/##/####, where # represents a digit, and per the slashes in those
positions, implies that the *USA* standard format defines the
date-string-value. That USA _standard_ format is consistently
documented in both of the DB2 for i and the DB2 LUW. Thus I would
expect the sqlcode -181 for the string '20/08/2016', but expect no error
to be issued for the string '08/20/2016'.
However I agree with the comment made by Hogan in another followup
reply, about the nature of the issue, being essentially, that there is
an expectation of a possible difference between the displayed-formatting
of date values and the input-formatting for date values. I would be
frustrated nevertheless, by the effect seen; similarly to what I infer
the OP alludes. That is because I am quite used to [and even reliant
upon] the DB2 for i SQL /understanding/ all of the "standard" formats,
irrespective the /local/ formatting I have defined for input of
non-standard date-values.
I suspect that despite the Territory=US being in effect for the
formatting of *displayed* date values, there is quite likely to be
_another setting_ for the formatting required for the *input* of date
values; in the scenario of the OP, for which the expectation has been
established with the DB2 LUW CLP, that a date string must be formatted
as 'dd/mm/yyyy'. Essentially, I wonder if, there might be an override
of the /standard/ USA format that has the DB2 LUW CLP insisting that the
string-value-as-date must be formatted as 'dd/mm/yyyy'; that
essentially, per that insistence, the ability of the CLP to accept the
standard 'mm/dd/yyyy' date-string values is _necessarily nullified_ due
to the conspicuous conundrum of accepting both formats. FWiW, the DB2
for i could not exhibit that same behavior, simply because, there is _no
ability_ to override\insist that the DB2 for i must accept
input-date-strings with the format 'dd/mm/yyyy'; the non-standard [i.e.
the "LOCAL" or "LOC"; see the CHAR scalar function] string
representations of dates are limited to formats with two-digit years.
For reference, an older doc link for the sqlstate=22007:
[
https://www.ibm.com/support/knowledgecenter/en/SSEPGG_9.7.0/com.ibm.db2.luw.messages.sql.doc/doc/msql00181n.html]
For reference, the following docs also from DB2 LUW 9.7 is [best I
can recall] consistent with all releases of DB2 for i:
[
https://www.ibm.com/support/knowledgecenter/en/SSEPGG_9.7.0/com.ibm.db2.luw.sql.ref.doc/doc/r0008474.html]
"…
_Date strings_
A string representation of a date is a string that starts with a digit
and has a length of at least 8 characters. Trailing blanks may be
included; leading zeros may be omitted from the month and day portions.
Valid string formats for dates are listed in the following table. Each
format is identified by name and associated abbreviation.
Table 1. Formats for String Representations of Dates
Format Name Abbrev Date Format Example
International Standards Organization ISO yyyy-mm-dd 1991-10-27
IBM® USA standard USA USA mm/dd/yyyy 10/27/1991
IBM European standard EUR dd.mm.yyyy 27.10.1991
Japanese Industrial Std Christian Era JIS yyyy-mm-dd 1991-10-27
Site-defined LOC Depends on
territory code -
of application
…"
--
Regards, Chuck