Пример #1
0
        /// <summary>
        /// 更新大文本字符串保存到数据库
        /// 王方圆添加 2017-5-16
        /// </summary>
        /// <param name="tableName">表明</param>
        /// <param name="id">唯一标识ID</param>
        /// <param name="longTextFieldName">字段名称</param>
        /// <param name="longTextContent">更新文本内容</param>
        public static void UpdateLongText(string tableName, long id, string longTextFieldName, string longTextContent)
        {
            string connectStr = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultDB"].ConnectionString;

            using (Oracle.DataAccess.Client.OracleConnection conn = new Oracle.DataAccess.Client.OracleConnection(connectStr))
            {
                conn.Open();
                //OracleTransaction trans = conn.BeginTransaction();
                Oracle.DataAccess.Client.OracleCommand cmd = conn.CreateCommand();
                //cmd.Transaction = trans;
                cmd.CommandText = "declare xx clob; begin dbms_lob.createtemporary(xx, false, 0); :templob := xx; end;";
                cmd.Parameters.Add(new Oracle.DataAccess.Client.OracleParameter(":templob", Oracle.DataAccess.Client.OracleDbType.Clob)).Direction = ParameterDirection.Output;
                cmd.ExecuteNonQuery();

                OracleClob tmplob = (OracleClob)cmd.Parameters[0].Value;
                byte[]     buffer = System.Text.Encoding.Unicode.GetBytes(longTextContent);
                tmplob.Write(buffer, 0, buffer.Length);
                tmplob.Position = 0;

                cmd.Parameters.Clear();
                string cmdText = "update {0} set {1} = :lob where EMAIL_ID= :id";
                cmdText         = string.Format(cmdText, tableName, longTextFieldName);
                cmd.CommandText = cmdText;
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.Add(new Oracle.DataAccess.Client.OracleParameter(":lob", Oracle.DataAccess.Client.OracleDbType.Clob)).Value = tmplob;
                cmd.Parameters.Add(new Oracle.DataAccess.Client.OracleParameter(":id", id));
                cmd.ExecuteNonQuery();
            }
        }