2017-10-07 49 views
1

我正嘗試使用c#更新oracle表記錄。當我執行我的代碼SoapFault時 - faultcode:'a:InternalServiceFault'faultstring:'ORA-01438:值大於指定精度允許的此列'faultactor:'null'detail:org.kxml2.kdom時出現此錯誤。節點@ 99c0b9c。錯誤:'ORA-01438:值大於該列所允許的指定精度'faultactor:'null'詳細信息:[email protected]

這是我用我的服務端代碼:

[OperationContract] 

public int pushData(string CustomObjects) 
{ 

    List<CustomObject> myDeserializedObjList = (List<CustomObject>)Newtonsoft.Json.JsonConvert.DeserializeObject(CustomObjects, 
    typeof(List<CustomObject>)); 
    string constr = "my connection string"; 
    int rowid = 0; 
    using(OracleConnection con = new OracleConnection(constr)){ 

    con.Open(); 
    OracleCommand cmd = new OracleCommand(); 
    cmd.Connection = con; 
    cmd.CommandType = CommandType.Text; 

    foreach (CustomObject element in myDeserializedObjList) 
    { 

     int num = element.num; 

     string mydate = element.mydate; 

     long num2 = element.num2; 

     string user = element.user; 


     string sqlStatement= "UPDATE CustomObjectS SET num = :num, 
     mydate=:to_date(:mydate, 'YYYY/MM/DD HH:MI:SS'), num2=:num2, user=:user WHERE num =:num"; 
     OracleTransaction myTrans; 

     // Start a local transaction 
     myTrans = con.BeginTransaction(); 
     // Assign transaction object for a pending local transaction 
     cmd.Transaction = myTrans; 
     cmd.CommandText=sqlStatement; 
     cmd.Parameters.Add(new OracleParameter("num", num)); 
     cmd.Parameters.Add(new OracleParameter("user", user)); 
     cmd.Parameters.Add(new OracleParameter("num2", num2)); 
     cmd.Parameters.Add(new OracleParameter("mydate", mydate)); 
     cmd.Parameters[3].Value = mydate; 


       rowid= cmd.ExecuteNonQuery(); 

       myTrans.Commit(); 



     } 


     } 


    return rowid; 

     } 

能否請你幫

+0

什麼是'CustomObjectS'的定義是什麼? – Richard

+0

'num'和'num2'的數據類型(在數據庫中)是什麼? – mjwills

+0

它們的類型是數字 –

回答

0

ORA-01438: value larger than specified precision allows for this column

無論是INSERT或UPDATE語句過程中出現此錯誤。這意味着,您正嘗試爲超過爲此列定義的精度的列指定一個值。

一個簡單的例子:

CREATE TABLE abc1(
    x NUMBER(5) 
); 


INSERT INTO abc1(x) values (123456); 
ORA-01438: value larger than specified precision allowed for this column 


INSERT INTO abc1(x) values (12345); 
1 row inserted. 

你可以做什麼:

  • 指定較小的精度值的列(不assing這麼大的數字)。
  • 更改表格的定義以允許列中的精度更高。這可以通過ALTER TABLE語句完成。

ALTER TABLE abc1 MODIFY x NUMBER(10); 
Table ABC1 altered. 

INSERT INTO abc1(x) values (123456); 
1 row inserted.