DEVELOPER: ODP.NET Serving Winning LOBs:

http://www.oracle.com/technetwork/issue-archive/2005/05-nov/o65odpnet-085139.html

Data Provider for .NET Developer's Guide:

https://docs.oracle.com/database/121/ODPNT/OracleBlobClass.htm#ODPNT4035

从blob字段读取一个图片文件的代码:

        OracleConnection con = new OracleConnection(connStr);
con.Open(); // statement to get a blob
string sql = "select yz from sysusers where yhdh='123'"; // create command object
// InitialLOBFetchSize
// defaults to 0
OracleCommand cmd = new OracleCommand(sql, con); // create a datareader
using (OracleDataReader dr = cmd.ExecuteReader())
{
// read the single row result
dr.Read();
// use typed accessor to retrieve the blob
OracleBlob blob = dr.GetOracleBlob(); // create a memory stream from the blob
using (MemoryStream ms = new MemoryStream(blob.Value))
{
// set the image property equal to a bitmap
// created from the memory stream
pictureBox1.Image = new Bitmap(ms);
}
}

保存文件到blob字段的代码:

         con.Open();

         // 利用事务处理(必须)
OracleTransaction transaction = con.BeginTransaction();
string sql="select yz from sysusers where yhdh='123' FOR UPDATE";
OracleCommand cmd = new OracleCommand(sql, con); using ( OracleDataReader reader = cmd.ExecuteReader())
{
//Obtain the first row of data.
reader.Read();
//Obtain a LOB.
OracleBlob blob = reader.GetOracleBlob();
blob.Erase();
// 将文件写入 BLOB 中
byte[] Buffer;
FileStream fs = new FileStream(@"d:\01.jpg", FileMode.Open);
using (MemoryStream ms = new MemoryStream())
{
int b;
while ((b = fs.ReadByte()) != -)
{
ms.WriteByte((byte)b);
}
Buffer = ms.ToArray();
} // Begin ChunkWrite to improve performance
// Index updates occur only once after EndChunkWrite
blob.Position=;
blob.BeginChunkWrite(); //启用BeginChunkWrite不是必须,只与性能有关
blob.Write(Buffer, ,Buffer .Length); //从字节数据写入blob字段
blob.EndChunkWrite();
blob.Close();
}
// 提交事务
transaction.Commit();
con.Close();

odp.net 读写oracle blob字段的更多相关文章

  1. java 读写Oracle Blob字段

    许久没有分享代码了,把这段时间写的一个Java操作Blob字段,有日子没写Java了,就当作笔记记录一下.1. [代码][Java]代码     跳至 [1] [全屏预览]package com.wa ...

  2. Oracle Blob 字段的模糊查询

    原文地址:http://blog.csdn.net/springk/article/details/6866248

  3. 分块读取Blob字段数据(Oracle)

    试过了MSSQL的分块读取Blob字段,又尝试在Oracle下完成,发现还是可行的. 首先建立一个存储过程: create or replace procedure PRO_GET_BLOB(     ...

  4. Oracle数据库BLOB字段的存取

    述]     Oracle的Blob字段比较特殊,他比long字段的性能要好很多,可以用来保存例如图片之类的二进制数据. 写入Blob字段和写入其它类型字段的方式非常不同,因为Blob自身有一个cur ...

  5. Java读取oracle数据库中blob字段数据文件保存到本地文件(转载)

    转自:https://www.cnblogs.com/forever2698/p/4747349.html package com.bo.test; import java.io.FileOutput ...

  6. c# winform 操作oracle数据库的Blob字段,把图片存储到数据库,保存图片到数据库

    ///c# winform 操作oracle数据库的Blob字段,把图片存储到数据库,保存图片到数据库 闲话不多说,直接上代码 using System; using System.Collectio ...

  7. FIREDAC保存ORACLE的BLOB字段数据

     FIREDAC默认识别ORACLE的BLOB字段为HUGEBLOB,需要将HBLOB映射为BLOB,才可以保存ORACLE的BLOB字段的数据.

  8. oracle 下操作blob字段是否会产生大量redo

    操作blob字段是否会产生大量redo,答案是不会.以下来做一个实验,測试数据库版本号是11.2.0.1.0: --创建一张表做測试之用 create table test_blob (   id n ...

  9. mybatis oracle BLOB类型字段保存与读取

    一.BLOB字段 BLOB是指二进制大对象也就是英文Binary Large Object的所写,而CLOB是指大字符对象也就是英文Character Large Object的所写.其中BLOB是用 ...

随机推荐

  1. ubuntu配置命令

    sudo apt-get update 更新源 sudo apt-get install package 安装包 sudo apt-get remove package 删除包 sudo apt-ca ...

  2. 笔记-python异常信息输出

    笔记-python异常信息输出 1.      异常信息输出 python异常捕获使用try-except-else-finally语句: 在except 语句中可以使用except as e,然后通 ...

  3. https refused 解决方法

    今天调试Android程序,所有的手机都ok,后来,我一个手机一直说,refused. 其实这就说明代码是没有问题的,你应该可以根据这个把代码的原因排除.然后剩下的,网络请求还能有什么,网路白. 果然 ...

  4. js限制文本框只能输入特定字符

    限制只能输入数字 // ---------------------------------------------------------------------- // <summary> ...

  5. 【Minimum Window】cpp

    题目: Given a string S and a string T, find the minimum window in S which will contain all the charact ...

  6. PC Server远程管理卡用户管理脚本实现

    1.IPMI工作原理图: 2.脚本实现流程图: 3.适配服务器机型: 4.演示效果: 5.实现代码: #!/usr/bin/env bash # Author : JACK ZHAO # Date : ...

  7. CentOS7 编译安装nodejs,配置环境变量记录

    每次都装,每次都查 阿里云备案了一个域名,续费了好多年,但是没钱买服务器,就挂在github上.今天收到消息:域名解析服务器不在阿里云,要被GG.只能咬牙买了个阿里云乞丐版. 所有服务都装好了,pin ...

  8. NodeJs06 高并发

    高并发架构 在业务的最初期,由于业务和用户的体量比较小,可能采用单机就足够了.随着业务的增长,用户量和并发请求量都会不断上升.当增长到一定的瓶颈的时候,系统能否抗住压力,就需要采取一些方案了.这就是著 ...

  9. 团队项目-第八次scrum 会议

    时间:11.4 时长:30分钟 地点:F楼2层沙发休息处 工作情况 团队成员 已完成任务 待完成任务 解小锐 修复员工招聘时bug 完成员工commit函数的数值函数编写 陈鑫 实现雇佣与解雇功能的界 ...

  10. RMAN 增量备份级别说明

    通过Bat批处理调用RMan是我们定时备份数据库的好帮手,但是RMan的备份级别需要我们好好了解一下. RMAN备份全为全备和增量备份 增量备份:分为0 1 2级 ORACLE官方解释: A leve ...