在我的应用程序中,我捕获了一个"时间戳"。稍后在调用存储过程时使用这个时间戳。目前我得到的错误:
ORA-01830:日期格式图片在转换整个输入之前结束字符串ORA-06512: at line 2
我需要小时,分钟和秒,因为表中的列必须是唯一的。
下面是我获取datetime的方法:private void getDate()
{
conn.Open();
string query;
query = "select to_char(sysdate, 'dd/mon/yyyy hh24:mi:ss') as CurrentTime from dual";
OracleCommand cmd = new OracleCommand(query, conn);
OracleDataReader dr = cmd.ExecuteReader();
dr.Read();
text = dr[0].ToString();
dr.Close();
conn.Close();
}
我是这样调用这个过程的:
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
conn.Open();
OracleTransaction trans = conn.BeginTransaction();
cmd.CommandTimeout = 0;
cmd.CommandText = "dc.hhrcv_insert_intrnl_audit_scn";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("pn_pallet_id", OracleDbType.Number).Value = palletid;
cmd.Parameters.Add("pn_emp_id_no", OracleDbType.Number).Value = empid;
cmd.Parameters.Add("pd_intrnl_audit_scan_datetime", OracleDbType.VarChar).Value = text;
cmd.Parameters.Add("pn_company_id_no", OracleDbType.VarChar).Value = companyIdNo2;
cmd.Parameters.Add("pn_order_no", OracleDbType.Number).Value = orderNo2;
cmd.Parameters.Add("pn_carton_code", OracleDbType.Number).Value = carton_Code2;
cmd.Parameters.Add("pn_no_of_full_carton", OracleDbType.Number).Value = txtNoOfCartons.Text;
cmd.Parameters.Add("pn_no_of_packs", OracleDbType.Number).Value = txtNoOfPacks.Text;
cmd.Parameters.Add(new OracleParameter("pv_error", OracleDbType.VarChar));
cmd.Parameters["pv_error"].Direction = ParameterDirection.Output;
string pv_error;
cmd.ExecuteNonQuery();
pv_error = cmd.Parameters["pv_error"].Value.ToString();
if (pv_error.ToString() == "")
{
trans.Commit();
frmMsgAudit ms = new frmMsgAudit(empid,palletid,orderno,text);
ms.Show();
this.Hide();
}
else
{
trans.Rollback();
MessageBox.Show("" + pv_error, "Error");
}
conn.Close();
出现错误:
cmd.ExecuteNonQuery ();
ORA-01830:日期格式图片在转换整个输入之前结束字符串ORA-06512: at line 2
感谢大家的快速回复!
叽阿. .我真的需要坐下来一步一步地走一遍!无论如何,这就是问题所在:
在存储过程中我有:
...
begin
insert into dc_internal_audit_scan (pallet_id_no,
internal_audit_scan_emp,
internal_audit_scan_datetime,
company_id_no,
order_no,
carton_code,
no_of_full_cartons,
no_of_packs,
last_update_datetime,
username)
values (ln_pallet_id_no,
pn_emp_id_no,
**pd_intrnl_audit_scan_datetime,**
pn_company_id_no,
pn_order_no,
pv_carton_code,
pn_no_of_full_cartons,
pn_no_of_packs,
sysdate,
lv_emp_username);
end;
:
...
begin
insert into dc_internal_audit_scan (pallet_id_no,
internal_audit_scan_emp,
internal_audit_scan_datetime,
company_id_no,
order_no,
carton_code,
no_of_full_cartons,
no_of_packs,
last_update_datetime,
username)
values (ln_pallet_id_no,
pn_emp_id_no,
**TO_DATE(pd_intrnl_audit_scan_datetime,'dd/mon/yyyy hh24:mi:ss'),**
pn_company_id_no,
pn_order_no,
pv_carton_code,
pn_no_of_full_cartons,
pn_no_of_packs,
sysdate,
lv_emp_username);
end;
TO_DATE (pd_intrnl_audit_scan_datetime, dd/我的/yyyy hh24: mi: ss")
谢谢
看起来这行不对;
query = "select to_char(sysdate, 'dd/mon/yyyy hh24:mi:ss')
24
在这里做什么?
尝试;
query = "select to_char(sysdate, 'dd/mon/yyyy hh:mi:ss AM')
FROM ORA-01830 Error
您尝试输入日期值,但输入的日期不匹配日期格式。
EDIT:由于A.B.Cade 警告我, hh24
是有效的oracle格式,但我仍然认为您的sysdate
的格式和'dd/mon/yyyy hh24:mi:ss'
是不同的格式。