c# 对oracle插入数据字段过长超出限制的解决方案

通过建立存储过程的方法解决问题,如下所示,存储过程的名字为insertGEO,有4个输入参数,Childrens,RingInParent直接通过sql语句插入时,字段值过长会报错,所以先在数据库中建立存储过程

create or replace procedure insertGEO
(v_id  number,
v_pid number,
Childrens clob,
RingInParent clob)
is
  content clob;
  ring clob;
begin
  content := Childrens;
  ring:=RingInParent;
  insert into geoobjects(PLGID,PARENTID,CHILDRENLIST,RINGINPARENT) values(v_id,v_pid,content,ring );
  update geoobjects set CHILDRENLIST = content,RINGINPARENT=ring where PLGID = v_id;
commit;
end;

然后,调用存储过程插入语句解决问题,c#代码如下:

//执行储存过程
                        OracleCommand om = myConnection.CreateCommand();
                        om.CommandType = CommandType.StoredProcedure;
                        om.CommandText = "insertGEO";
                        om.Parameters.Add("v_id", OracleDbType.Int32).Direction = ParameterDirection.Input;
                        om.Parameters["v_id"].Value = node.m_objList[i].ID;
                        om.Parameters.Add("v_pid", OracleDbType.Int32).Direction = ParameterDirection.Input;
                        om.Parameters["v_pid"].Value = parentID;
                        om.Parameters.Add("Childrens", OracleDbType.NClob).Direction = ParameterDirection.Input;
                        om.Parameters["Childrens"].Value = node.m_objList[i].printChildrens();
                        string ring = "";
                        if (node.m_objList[i].RingInParent != null)
                        {
                            ring = node.m_objList[i].RingInParent.printGeoLineRing();
                        }
                        om.Parameters.Add("RingInParent", OracleDbType.NClob).Direction = ParameterDirection.Input;
                        om.Parameters["RingInParent"].Value = ring;
                        om.ExecuteNonQuery();

猜你喜欢

转载自blog.csdn.net/baidu_23263735/article/details/84798677