我有这个 Oracle 11g 表

CREATE TABLE "DBNAME"."CANDIDATES"
(
    "ID" NUMBER(24,0),
    "USRINS" VARCHAR2(30 CHAR),
    "DATINS" DATE,
    "USRUPD" VARCHAR2(30 CHAR),
    "DATUPD" DATE,
    "EXM_ID" NUMBER(24,0),
    "TYPE" NUMBER(3,0),
    "PSN_ID" NUMBER(24,0),
    "KOD" NUMBER(20,0),
    "STATUS" NUMBER(20,0),
    "PRICINA" VARCHAR2(200 CHAR)
)

现在我在 C# 中有这个命令
string insertIntoCandidates = "INSERT INTO CANDIDATES " &
  "(USRINS, DATINS, PSN_ID, KOD, STATUS, PRICINA) " &
  values ("
                     + ":usrins, "
                     + ":datins, "
                     + ":psn_id, "
                     + ":kod, "
                     + ":status, "
                     + ":pricina"
                     + ") ";

command.Parameters.Add(":usrins", null);
command.Parameters.Add(":datins", DateTime.Now);
command.Parameters.Add(":psn_id", getPsnIDByEMBG(result.embg));
command.Parameters.Add(":kod", result.kod_kandidat);
if (result.status)
{
    command.Parameters.Add(":status", 1);
}
else
{
    command.Parameters.Add(":status", 0);
}

command.Parameters.Add(":pricina", result.pricina);

int res = command.ExecuteNonQuery();

我不为其插入值的列可以获得空值。
执行最后一行后,我得到异常 ORA-01722: invalid number。我试图寻找答案,但没有任何运气。你能帮我吗?谢谢

最佳答案

当尝试将字符串转换为数字时,会发生 ORA-01722(“无效数字”)错误,并且无法将字符串转换为有效数字。因此,请检查参数以获取正确的数据类型。
另请参阅:
C# parameterized queries for Oracle - serious & dangerous bug!

Why am I getting an ORA-01722 (invalid number)?

关于c# - ORA-01722 : invalid number on INSERT in C# - Oracle 11g,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28450268/

10-11 04:38