Oracle中 表名: TBExam
字段: ID(varchar类型) Result(BLOB类型)TBExam中已经存在的 记录
ID Result(BLOB类型)
001 写不进来
-------------- 想实现的 效果: ID 为 001 的 Result值 改成 终于,写进来了------------
我的做法如下,但是没有成功
byte[] b = System.Text.Encoding.Unicode.GetBytes("终于,写进来了");
mySql="update TBExam set Result=b where ID=001"
OracleCommand cmd = new OracleCommand(mySql, conn);
cmd.ExecuteNonQuery();
------------
在线等高手 解答~~~要求是 C#编程实现的~~~---------关于分值
在C#社区
http://topic.csdn.net/u/20101212/15/88d3ee91-ef10-4bbe-88a8-ebbcf89ea3bc.html
发了个100分的 求助帖, 问题尚未被解决。 没有足够分在这里开个100分了--!
如果哪位高手在 这能解决 请在
http://topic.csdn.net/u/20101212/15/88d3ee91-ef10-4bbe-88a8-ebbcf89ea3bc.html
发个回复~~ 从那里额外给分。
解决方案 »
- 怎么得到上个月一号零时零分零秒
- 跪求解决sql消耗CPU过高的方法!!
- Oracle 跪求时间倒序获取第二条记录
- 知道oracle执行计划的进来说说!~
- 请教下大家学习oracle 的经验,我想有了大家的帮助我可以少走弯路。
- 想用execute immediate执行一条update的SQL语句,但不成功,请各位帮看看
- 高手一定要来看看,帮解决问题
- 请教Oracle9i的SQL*PLUS与SQL*PLUSWorkSheet有什么区别么?同一条命令为什么结果不同?是缓冲么?
- >>大家来讨论一下两本书<<
- 请问我的Oracle http server启动为何总是报错:无法找到动态链接库OCI.dll于指定路径?
- ORA-00918: 未明确定义列
- 通过ctl文件导入数据库
如果使用BLOB来存储,试试:
mySql="update TBExam set Result=rawtohex("+"终于,写进来了"+") where ID=001"
mySql="update TBExam set Result=rawtohex('"+"终于,写进来了"+"') where ID=001"
测试未通过~~
3x anyway先去吃饭~~~
using System;
using System.Collections.Generic;
using System.Text;// using oracle ado.net instead of MS ado.net for oracle
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;namespace oracledemo
{
class TestOracle
{ OracleConnection _conn; public void test()
{ string connstr = "User Id=scott;Password=tiger;Data Source=ora102"; try
{
_conn = new OracleConnection(connstr);
_conn.Open();
}
catch (Exception ex)
{
Console.WriteLine("Error: {0}", ex.Message);
return;
} // setup StringBuilder blr;
OracleCommand cmd = new OracleCommand("", _conn); blr = new StringBuilder();
blr.Append("DROP TABLE TBExam");
cmd.CommandText = blr.ToString();
try
{
cmd.ExecuteNonQuery();
}
catch (Exception e)
{
Console.WriteLine("Warning: {0}", e.Message);
} blr = new StringBuilder();
blr.Append("CREATE TABLE TBExam(ID varchar(32) PRIMARY KEY,");
blr.Append("story CLOB, Result BLOB)");
cmd.CommandText = blr.ToString();
try
{
cmd.ExecuteNonQuery();
}
catch (Exception e)
{
Console.WriteLine("Error: {0}", e.Message);
} blr = new StringBuilder();
blr.Append("INSERT INTO TBExam values(");
blr.Append("'001',");
blr.Append("'This is a long story. Once upon a time ...',");
blr.Append("empty_blob())");
cmd.CommandText = blr.ToString();
try
{
cmd.ExecuteNonQuery();
}
catch (Exception e)
{
Console.WriteLine("Error: {0}", e.Message);
} // update the blob value
string res = "终于,写进来了";
byte[] b = System.Text.Encoding.Unicode.GetBytes(res); cmd.Dispose();
OracleTransaction txn = _conn.BeginTransaction();
cmd = new OracleCommand("", _conn);
try
{ cmd.CommandText = "select result from TBExam where id='001' for update";
OracleDataReader reader = cmd.ExecuteReader();
reader.Read();
OracleBlob blob = reader.GetOracleBlob(0);
blob.Write(b, 0, b.Length);
blob.Flush();
txn.Commit();
cmd.CommandText = "select result from TBExam where id='001'";
reader = cmd.ExecuteReader();
reader.Read();
blob = reader.GetOracleBlob(0);
byte[] bout = new byte[blob.Length];
blob.Read(bout, 0, bout.Length);
Console.WriteLine("blob length = " + blob.Length);
Console.WriteLine("result = " + new string(System.Text.Encoding.Unicode.GetChars(bout)) );
}
catch (Exception e)
{
Console.WriteLine("Error: {0}", e.Message);
}
finally
{
cmd.Dispose();
_conn.Close();
_conn.Dispose();
} } static void Main(string[] args)
{
new TestOracle().test();
}
}
}
输出结果:
blob length = 14
result = 终于,写进来了