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. 重新安装配置ubuntu的引导菜单

     查看分区挂在情况,找到ubuntu所在分区(boot)$sudo fdisk   -l   卸载isodevice镜像设备所在盘分区(boot) $sudo  umount  -l  /isodev ...

  2. Sublime Text 快捷键及插件安装

    Sublime Text是一款跨平台的编辑器,它小巧绿色且速度非常快,支持各种流行编程语言的语法高亮.代码补全等,插件非常丰富!editplus.notepad++也都是不错的工具,体积轻巧,启动迅速 ...

  3. 一个基于ANTLR 4的布尔表达式语句解释器的实现

    Reference The Definitive ANTLR 4 Reference, 2nd Edition. 0 Features labeled grammar definition, i.e. ...

  4. Opencv创建有滚动条的视频

    #include "stdafx.h"#include "cv.h"#include "cxcore.h"#include "hi ...

  5. spring mvc 请求转发和重定向

    spring mvc controller间跳转 重定向 传参 url:http://zghbwjl.blog.163.com/blog/static/12033667220137795252845/ ...

  6. vim显示行数

    在根目录下,新建.vimrc文件,添加以下内容 set number

  7. UVa 156 (映射 map)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  8. linux cpu性能测试

    sysbench --test=cpu --cpu-max-prime=20000000 run --num-threads=4 mpstat -P ALL 1 1000000

  9. 关于URL编码

    关于URL编码 作者: 阮一峰 日期: 2010年2月11日 一.问题的由来 URL就是网址,只要上网,就一定会用到. 一般来说,URL只能使用英文字母.阿拉伯数字和某些标点符号,不能使用其他文字和符 ...

  10. ajax请求后弹开新页面被浏览器拦截

    window.open()我想应该很多人都不陌生吧,它可以实现除用a标签以外来实现打开新窗口! 最近开发项目用到时,却遇到了麻烦,本来好好的弹出窗口,结果被浏览器无情的给拦截了! 代码如下: $.ge ...