oracle table:

CREATE TABLE "SCOTT"."TEST_BLOB"
   (    "NAME" VARCHAR2(200),
    "PHOTO" BLOB
   )

Operating Code:

private static void OprBlob()
        {
            var connStr = ConfigurationManager.ConnectionStrings["ora"].ConnectionString;

using (OracleConnection conn = new OracleConnection())
            {
                conn.ConnectionString = connStr;
                conn.Open();
                var cmd = conn.CreateCommand();
                cmd.CommandText = @"
begin
insert into test_blob values(:1,:2);
end;
";;
                byte[] photo;
                using (var fileStrm = new FileStream(@"D:\abc.png", FileMode.Open))
                {
                    photo = new byte[fileStrm.Length];
                    fileStrm.Read(photo, 0, photo.Length);
                }
                cmd.Parameters.Add("name", OracleDbType.NVarchar2,"Phil",ParameterDirection.Input);
                cmd.Parameters.Add("photo", OracleDbType.Blob, photo, ParameterDirection.Input);

cmd.ExecuteNonQuery();
            }

using (OracleConnection conn = new OracleConnection())
            {
                conn.ConnectionString = connStr;
                conn.Open();
                var cmd = conn.CreateCommand();
                cmd.CommandText = @"
begin
select photo into :1 from test_blob where rownum =1;
end;
"; ;

var photoParam = cmd.Parameters.Add("p", OracleDbType.Blob, ParameterDirection.Output);

cmd.ExecuteNonQuery();

byte[] photo2 = (byte[])((Oracle.DataAccess.Types.OracleBlob) photoParam.Value).Value;

using (var fileStrm = new FileStream(@"D:\phil.png",FileMode.CreateNew))
                {
                    fileStrm.Write(photo2,0,photo2.Length);
                    fileStrm.Flush(true);
                }
            }

}

Operate blob data in Oracle via C#的更多相关文章

  1. How to get blob data using javascript XmlHttpRequest by sync

    Tested: Firefox 33+ OK Chrome 38+ OK IE 6 -- IE 10 Failed Thanks to 阮一峰's blog: http://www.ruanyifen ...

  2. caffe出错:Unknown bottom blob 'data' (layer 'conv1', bottom index 0)

    原文https://blog.csdn.net/u011070171/article/details/75425740 caffe训练出现如下错误: Unknown bottom blob 'data ...

  3. Data Base oracle常见错误及解决方案

    Data Base oracle常见错误及解决方案 一.TNS协议适配器错误: 原因: 此问题的原因都是由于监听没有配置好. 解决: 1.打开oracle工具Net Manager,删除服务及监听,重 ...

  4. Data Base Oracle 常用命令

    Data Base  Oracle 常用命令 1.登录:(不需要密码,属于管理员权限) conn /as sysdba; 2.查看数据库存储位置: select name from v$datafil ...

  5. Manipulating Data from Oracle Object Storage to ADW with Oracle Data Integrator (ODI)

    0. Introduction and Prerequisites This article presents an overview on how to use Oracle Data Integr ...

  6. Flashback Data Archive ( Oracle Total Recall ) introduced in 11g

    Flashback Data Archive feature is part of Oracle Total Recall technology. Flashback Data Archive fea ...

  7. Streaming data from Oracle using Oracle GoldenGate and Kafka Connect

    This is a guest blog from Robin Moffatt. Robin Moffatt is Head of R&D (Europe) at Rittman Mead, ...

  8. SQOOP Load Data from Oracle to Hive Table

    sqoop import -D oraoop.disabled=true \ --connect "jdbc:oracle:thin:@(description=(address=(prot ...

  9. oracle闪回、闪回数据归档Flashback Data Archive (Oracle Total Recall)的真正强大之处、11gR2增强以及合理使用

    oracle的闪回很早就出来了,准确的说一直以来应该都较少被真正用户广为使用,除了dba和极少部分开发人员偶尔用于逻辑出错.误删恢复之外,较少被用于产生更有价值的用途. 各种闪回表flashback ...

随机推荐

  1. 将Rmarkdown文件转为pdf文件

    knitr包只能够将R markdown文件转为html格式,若想要将其转化为pdf格式,还要安装另一个包 # Install and load package install.packages(&q ...

  2. elasticsearch的marvel

    摘自: http://kibana.logstash.es/content/logstash/plugins/input/syslog.html 一:marvel介绍 marvel 是 Elastic ...

  3. Visual Studio 启动修复命令

    今天VS启动不了了,连命令行的 devenv.exe /? 都执行不了,看不到帮助命令了,记性不好,以前看过但没记住呀,还好我装了两个不同版本的VS, 另一个VS的帮助命令还是可以看到的.虽然修复了, ...

  4. JavaScript 中的window.event代表的是事件的状态,jquery事件对象属性,jquery中如何使用event.target

    http://wenda.haosou.com/q/1373868839069215 http://kylines.iteye.com/blog/1660236 http://www.cnblogs. ...

  5. 开发技巧-Java通过HttpProxy实现穿越

    需求描述     在正常的项目开发需求中,连接远程服务器的场景一般有二:     1  自家实现的http服务器,api接口都已经约定好:     2  开发平台服务,通常如新浪.百度云等平台提供的r ...

  6. mac android studio 编译时报Class JavaLaunchHelper is implemented in both

    Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Cont ...

  7. zookeeper安装及部署

    安装及部署 一. 单机安装.配置 1.下载zookeeper二进制安装包 下载 curl -L -O http://apache.fayea.com/zookeeper/stable/zookeepe ...

  8. Hibernate5.2之原生SQL查询

    Hibernate5.2之原生SQL查询 一. 介绍  在上一篇博客中笔者通过代码的形式给各位读者介绍了Hibernate中最重要的检索方式--HQL查询.在本博文中笔者将向各位读者介绍Hiberna ...

  9. 在 github 上获取源码

    比如访问: https://github.com/alifellod/NWebGather 可以找到下面的源码获取方式. 在github开源项目的页面上可以找到上图的三个获取源码方式. 使用git的网 ...

  10. iOS 关于GCD中的队列

    GCD中队列分类及获得方式 1.串行队列  dispatch_queue_t queue = dispatch_queue_create("队列名", DISPATCH_QUEUE ...