惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

月光博客
月光博客
Martin Fowler
Martin Fowler
博客园_首页
量子位
T
Tailwind CSS Blog
博客园 - Franky
G
Google Developers Blog
D
DataBreaches.Net
Vercel News
Vercel News
B
Blog
Recent Announcements
Recent Announcements
S
SegmentFault 最新的问题
M
MIT News - Artificial intelligence
爱范儿
爱范儿
博客园 - 【当耐特】
The Cloudflare Blog
H
Help Net Security
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
C
Check Point Blog
有赞技术团队
有赞技术团队
Microsoft Security Blog
Microsoft Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - ccczqh

Entity Framework对NULL值的处理 整理一下Entity Framework的查询 sqlhelper 使用事务实例 SqlHelper 类实现详细信息 SQL Server 2008R2中增加了新的智能 DateTime 数字型 C# tostring()汇总 DataGridView 列宽和行高自动调整的设定 datagridview,第一列前没有灰的一列 DataGridView取消默认选中行 dataGridView空白列,默认选中行的背景色,dataGridView中加入复选框勾选状态的更改 C# winform DataGridView 常见属性 C# dataGridView上下移动选中行 转ADO.NET Entity Framework 入门示例向导(附Demo程序下载) c#加密解密 WinForm 下实现一个自动关闭的MessageBox C#简单游戏外挂制作(以Warcraft Ⅲ为例) [WebBrowser][Cookie] Document.Cookie 取得的Cookies不完整問題 C# DllImport的用法
大数据类型通过存储过程保存数据(clob,blob)
ccczqh · 2012-08-07 · via 博客园 - ccczqh

今天终于把通过 存储过程传递和保存大数据类型的问题给解决了.在网上找了好多的资料,最试了都不行.最后还是按照微软的msdn上的例子参照自己的理解写了个执行存储过程的函数. ///

/// 执行带有clob,blob,nclob大对象参数类型的存储过程 ///

///

存储过程名称 ///

存储过程参数 ///

大对象在参数中的位置 ///

大对象的值 ///

大对象具体类型 public void RunProcedure(string storedProcName, IDataParameter[] parameters,int[] index,byte[][]tempbuff,OracleType[] DBType) { Connection.Open(); OracleTransaction tx = Connection.BeginTransaction(); OracleCommand cmd = Connection.CreateCommand(); cmd.Transaction = tx; string type=" declare "; for(int i=0;i< DBType.Length;i++) { type=type+" xx"+i.ToString()+" "+DBType[i].ToString()+";"; } string createtemp=type+" begin "; for(int i=0;i< DBType.Length;i++) { createtemp=createtemp+" dbms_lob.createtemporary(xx"+i.ToString()+", false, 0); "; } string setvalue=""; for(int i=0;i< DBType.Length;i++) { setvalue=setvalue+":templob"+i.ToString()+" := xx"+i.ToString()+";"; } cmd.CommandText =createtemp+setvalue+" end;"; for(int i=0;i< DBType.Length;i++) { cmd.Parameters.Add(new OracleParameter("templob"+i.ToString(), DBType[i])).Direction = ParameterDirection.Output; } cmd.ExecuteNonQuery(); int j=0; foreach(int i in index) { OracleLob tempLob = (OracleLob)cmd.Parameters["templob"+j.ToString()].Value; tempLob.BeginBatch(OracleLobOpenMode.ReadWrite); int abc=tempbuff[j].Length; if(DBType[j]==OracleType.Clob||DBType[j]==OracleType.NClob) { double b=abc/2; double a=Math.Ceiling(b); abc=(int)(a*2); } tempLob.Write(tempbuff[j],0,abc); tempLob.EndBatch(); parameters[i].Value=tempLob; j++; } cmd.Parameters.Clear(); cmd.CommandText = storedProcName; cmd.CommandType = CommandType.StoredProcedure; foreach (OracleParameter parameter in parameters) { cmd.Parameters.Add( parameter); } cmd.ExecuteNonQuery(); tx.Commit(); Connection.Close(); } 可以支持一个存储过程包含多个大对象类型参数. 在存储过程中保存数据可以这样写 PROCEDURE document_create ( strdocname VARCHAR2, strdocdirid number, strdoctime date, strdoccontect clob, p_new blob ) AS tmp_id number; lobloc blob; tmp_clob clob; BEGIN select sq_strdocid.Nextval into tmp_id from dual; INSERT INTO document (doc_id,doc_name,doc_dir_id,doc_time,doc_contect,news) VALUES (tmp_id,strdocname,strdocdirid,strdoctime,empty_clob(),empty_blob()); select news into lobloc from document where doc_id=tmp_id for update; DBMS_LOB.copy(lobloc,p_new,DBMS_LOB.getlength(p_new)); -- DBMS_LOB.write(lobloc,DBMS_LOB.getlength(p_new),1,p_new); select doc_contect into tmp_clob from document where doc_id=tmp_id for update; DBMS_LOB.copy(tmp_clob,strdoccontect,DBMS_LOB.getlength(strdoccontect)); -- DBMS_LOB.write(tmp_clob,DBMS_LOB.getlength(strdoccontect),1,strdoccontect); END document_create; 数据足够大的时候也可以保存数据... 但我一直有一个疑问,开始的时候我使用DBMS_LOB.write来保存数据,如果数据太大就报错,不知道是什么原因,后来改成DBMS_LOB.Copy就没有问题,,,不知道哪为大虾知道为什么