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 调整桌面图标大小

    打开文件浏览器,例如从“位置” 里打开 “主文件夹”,点 “编辑” –>“首选项”,把 “图标视图默认值” 下的“默认缩放级别” 改为 75%.现在图标大小跟WinXP 下的差不多. 或者 在 ...

  2. LintCode Search Insert Position

    找出指定target的位置(没有此数时为按顺序应当位置). public class Solution { /** * param A : an integer sorted array * para ...

  3. datatables 前端表格插件 增删改查功能

    官方网站:http://datatables.club/example/<!-- DataTables CSS -->css引入的<link rel="stylesheet ...

  4. Android 开发错误信息001

    Error:Execution failed for task ':app:dexDebug'. > com.android.ide.common.process.ProcessExceptio ...

  5. 用正则从html代码中提取图片路径

    $str = '<div align="center"> <img src="http://www.99tyg.com/public/images/e8 ...

  6. MySql取得日期(前一天、某一天)

    在测试一个统计表格,发现每次手写一个地址实在很烦,干脆就搞个自动计算好时间区间的东西.以下内容作为收获吧! 取得当天: SELECT curdate(); mysql> SELECT curda ...

  7. H5课程大纲

    K1模块课程: 课程模块 课程阶段 课程内容 K1 模块 第1阶段 认识前端开发 环境配置.使用标签的分类.写法及使用规范CSS样式的使用.各类常见样式Photoshop使用16大常用样式盒模型.语义 ...

  8. Codeforces 724C [坐标][乱搞][模拟]

    /* 不要低头,不要放弃,不要气馁,不要慌张 题意: 从(0,0)出发与x轴正方向呈45度角的射线,在给定的矩形区域内不断发射,直到射入矩形的某个角停止. 给出多个坐标,问光线最早经过某坐标的时间. ...

  9. FreeBSD 10 中文环境

    中文字体位置 FontPath        "/usr/local/lib/X11/fonts/misc/:unscaled" FontPath        "/us ...

  10. 升级正版win10及保持yosemite双操

    因为有同事升级了正版的win10,心头长草了,本来x230的win7就是正版,现在win10可以免费升级,为何不做? 为此跑了2趟lenovo的维修站,诸多限制,最终决定自己搞定.据说,需要恢复到原厂 ...