private void clob(byte[] bytes, int ContentLength)
{
OracleConnection conn = new OracleConnection("TODO:yourconnect");
try
{
conn.Open();
OracleTransaction trans = conn.BeginTransaction();
OracleCommand command = new OracleCommand();
command.Transaction = trans;
command.Connection = conn;
command.CommandType = CommandType.Text;
//获取临时clob
command.CommandText = "declare xx blob; begin dbms_lob.createtemporary(xx, false, 0); :templob := xx; end;";
command.Parameters.Add(new OracleParameter("templob", OracleType.Blob)).Direction = ParameterDirection.Output;
command.ExecuteNonQuery();
OracleLob tempblob = (OracleLob)command.Parameters[0].Value;
//end 获取临时clob
tempblob.Write(bytes, 0, ContentLength);
tempblob.Position = 0;
trans.Commit();
command.Parameters.Clear();
command.CommandText = " insert into subprojectfiles values(subprojectfiles_id.nextval,:subprojectid,:filetype,:name,:diskfile) ";
command.Parameters.Add(new OracleParameter("subprojectid","67"));
command.Parameters.Add(new OracleParameter("filetype","1"));
command.Parameters.Add(new OracleParameter("name", FileUpload1.FileName));
command.Parameters.Add(new OracleParameter("diskfile", OracleType.Blob, ContentLength,
ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, tempblob));
command.ExecuteNonQuery();
this.Response.Write("insert OK");
}
catch (Exception ex)
{
this.Response.Write(ex.Message);
}
finally
{
if (conn != null)
conn.Close();
}
}
网上找来的,收藏下~
原文http://www.cnblogs.com/OwenWu/archive/2011/04/05/2005521.html