32 conn.Open();
33 txn = conn.BeginTransaction();
34 cmd = new OracleCommand(strSql,conn, txn);
35
36 //
37 // 注意这里的 FOR UPDATE 进行记录锁定
38 //
39 cmd.CommandText = "SELECT content FROM mytable FOR UPDATE";
40 dr = cmd.ExecuteReader();
41 dr.Read();
42
43 while(dr.Read())
44 {
45 lob = dr.GetOracleLob(0);
46 if(lob!=OracleLob.Null)
47 {
48 content = lob.Value.ToString();
49
50 //
51 // 进行修改操作
52 //
53 content = "这是新的数据";
54
55 //
56 // 将新的数据值转换成byte[]
57 //
58 byte[] buffer = System.Text.Encoding.Unicode.GetBytes(content);
59
60 //
61 // 写回lob对象
62 //
63 lob.Write(buffer, 0, buffer.Length);
64 }
65
66 }
67 // 提交操作
68 txn.Commit();
69 Console.WriteLine("===============Success================");
70 }
71 catch(Exception ex)
72 {
73 Console.WriteLine("Error: {0}", ex.ToString());
74 }
75 finally
76 {
77 dr.Close();
78 conn.Close();
79 cmd.Dispose();
80 }
81 }
82
83 }
84}
| 广告合作:400-664-0084 全国热线:400-664-0084 Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号 珠峰网 版权所有 All Rights Reserved
|