0

私はこのようなクエリを持っています:

INSERT INTO some_table (date1, date2) 
VALUES (to_date('2012-10-24','YYYY-MM-DD'), to_date('2012-10-24','YYYY-MM-DD'));

しかし、私は得る:

SQL Error: ORA-01858: a non-numeric character was found where a numeric was expected
01858. 00000 -  "a non-numeric character was found where a numeric was expected"

と:

*Cause:    The input data to be converted using a date format model was
           incorrect.  The input data did not contain a number where a number was
           required by the format model.
*Action:   Fix the input data or the date format model to make sure the
           elements match in number and type.  Then retry the operation.

しかし、私の使用法はto_date大丈夫のようですか?

どうもありがとう。

4

1 に答える 1

4

それは正しいようです。そして、それは私にとってはうまくいくので、あなたの例の一部ではない問題に何か他のものがあるに違いありません...

SQL> create table some_table( date1 date, date2 date );

Table created.

SQL> INSERT INTO some_table (date1, date2)
  2  VALUES (to_date('2012-10-24','YYYY-MM-DD'), to_date('2012-10-24','YYYY-MM-DD'));

1 row created.

ハードコーディングされたリテラルを本当に使用していますか? to_dateそれとも、テーブルから渡された文字列ですか? データが期待される形式と一致しないテーブルに (少なくとも) 1 行ある可能性はありますか? 最終的に句によって除外される行は、サブクエリWHEREの句であっても、除外される前に呼び出してエラーを引き起こす可能性があることに注意してください。したがって、次のようなものがあることは完全にもっともらしいでしょうWHEREto_date

INSERT INTO some_table( date1, date2 )
  SELECT to_date( string1, 'YYYY-MM-DD' ), to_date( string2, 'YYYY-MM-DD' )
    FROM (SELECT *
            FROM some_other_table
           WHERE condition_that_limits_the_data_to_just_valid_date_strings )
   WHERE some_other_condition

エラーを返します。

于 2012-10-24T21:21:22.757 に答える