【问题标题】:Not a valid month while inserting data in oracle在 oracle 中插入数据时月份无效
【发布时间】:2016-09-29 11:49:40
【问题描述】:

我正在使用以下查询将数据插入表中..

INSERT INTO xxcus.xxacl_pn_agrmnt_mst
        (mkey, transaction_type, survey_area_7_12, ref_date, status,
         mst_date, remarks, tran_type, created_by, creation_date,
         last_update_date, last_updated_by, delete_flag
        )
 VALUES (1, 'AGR', 'khan,', '29-09-2016', 'AGD',
         '11/09/2016', 'Test', 'AM', '5681', '29-09-2016 17:10:19',
         '29-09-2016 17:10:19', '5681', 'N'
        )

但出现错误

2016 年 9 月 29 日的月份无效

这是我要插入的代码

xw.WriteElementString("REF_DATE", txtRefdate.Value);

我不知道这里出了什么问题

【问题讨论】:

    标签: oracle


    【解决方案1】:

    您应该将日期列的数据类型转换为

    to_date('29-09-2016 17:10:19', 'DD-MM-YYYY HH24:MI:SS')
    

    【讨论】:

    • 让我知道如何在此处添加它GridPayInfo.Rows[intGrdPay].Cells[GridPayInfo.Columns.GetColumnIndexByDataField("CHEQUE_DT")].Text.Trim()
    • 能否请您添加上面提到的xw 对象的完整代码?
    【解决方案2】:

    '29-09-2016 17:10:19' 不是日期而是字符串。

    Oracle will use the NLS_DATE_FORMAT session parameter as the format mask when implicitly converting a string to a date(即当您尝试将字符串值插入日期列时)并且如果此格式掩码与字符串的格式不匹配,则会出现错误。

    要生成日期,您应该通过以下方式将字符串显式转换为日期:

    您的查询应该是(如果您使用 ANSI 文字):

    INSERT INTO xxcus.xxacl_pn_agrmnt_mst (
      mkey,
      transaction_type,
      survey_area_7_12,
      ref_date,
      status,
      mst_date,
      remarks,
      tran_type,
      created_by,
      creation_date,
      last_update_date,
      last_updated_by,
      delete_flag
    ) VALUES (
      1,
      'AGR',
      'khan,',
      DATE '2016-09-29',
      'AGD',
      DATE '2016-09-11',
      'Test',
      'AM',
      '5681',
      TIMESTAMP '2016-09-29 17:10:19',
      TIMESTAMP '2016-09-29 17:10:19',
      '5681',
      'N'
    )
    

    【讨论】:

    • 那么我应该如何在这里添加它GridPayInfo.Rows[intGrdPay].Cells[GridPayInfo.Columns.GetColumnIndexByDataField("CHEQUE_DT")].Text.Trim()
    • @nad 这不是 SQL,我无法在没有任何上下文的情况下根据一小段代码 sn-p 来回答。您最好用 all 相关代码提出问题。创建minimal reproducible example
    猜你喜欢
    • 1970-01-01
    • 2015-03-28
    • 2021-11-06
    • 2021-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-26
    相关资源
    最近更新 更多