1

私はOracleに少し悩まされています

以下の私のSQL

select * from orders where 
trunc(ordered_date)
between
to_date('01-JAN-12') 
and 
to_date('07-JAN-12')

Ordered_date は DATE データ型です

以下のエラーが発生していますか。

Error starting at line 1 in command:
select * from orders
where 
trunc(ordered_date)
between 
to_date('01-JAN-12') 
and 
to_date('07-JAN-12')
Error report:
SQL Error: ORA-01841: (full) year must be between -4713 and +9999, and not be 0
01841. 00000 -  "(full) year must be between -4713 and +9999, and not be 0"
*Cause:    Illegal year entered
*Action:   Input year in the specified range

mu コードでこのエラーを引き起こしている原因がわかりません。

どんな入力でも素晴らしいでしょう。

ありがとう !!!

4

3 に答える 3

1

日付形式を指定する必要があります。

to_date関数にパラメーターを追加します。

 to_date('01-JAN-12', 'DD-Mon-YY')

お役に立てば幸いです。

よろしく。

于 2012-04-10T23:18:22.240 に答える
0

本当に日付リテラルを使用している場合は、代わりに次の構文を使用できます。

select * from orders where 
trunc(ordered_date)
between
date '2012-01-01'
and
date '2012-01-07'
于 2012-04-11T01:32:58.260 に答える
0

このように、両方の日付、つまり DB 日付と 2 つの入力日付を同じ形式に変換する必要があるかもしれません。


SELECT *
  FROM ORDERS O
 WHERE TO_DATE(TO_CHAR(O.ORDERED_DATE, 'DD-MON-YY'), 'DD-MON-YY') BETWEEN
       TO_DATE('01-JAN-12', 'DD-MON-YY') AND
       TO_DATE('07-JAN-12', 'DD-MON-YY')

それが役に立てば幸い

于 2012-04-17T04:32:30.040 に答える