Guest User

Untitled

a guest
Jan 21st, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. I need to read a CLOB field from an ORACLE table int a C# variable of type String. Does anyone know how to accomplish this task?
  2.  
  3. public void ReadFunction(string FName, out string fContent)
  4. {
  5. OracleCommand command = _connection.CreateCommand();
  6. OracleTransaction transaction = _connection.BeginTransaction();
  7. command.Transaction = transaction;
  8. command.CommandText = "SELECT TO_CLOB(TO_NCLOB(FUNCTION_SCRIPT)) FROM IS_FUNCTION where FNAME=:fName ";
  9. command.Parameters.Add("FName", OracleType.NVarChar).Value = FName;
  10. OracleDataReader odr = command.ExecuteReader();
  11. int temp = odr.GetOrdinal("FUNCTION_SCRIPT");
  12. OracleLob myLob = odr.GetOracleLob(temp);
  13. fContent = (String)myLob.Value;
  14. odr.close();
  15. }
  16.  
  17. // create and open connection
  18. // change for your environment
  19. string connStr = "User Id=pm; Password=pm; Data Source=orcllx; Pooling=false";
  20. OracleConnection con = new OracleConnection(connStr);
  21. try
  22. {
  23. con.Open();
  24. }
  25. catch (OracleException ex)
  26. {
  27. MessageBox.Show(ex.Message);
  28. }
  29.  
  30. // statement to get a blob
  31. string sql = "select ad_composite from print_media where product_id=3106 and
  32. ad_id=13001";
  33.  
  34. // create command object
  35. // InitialLOBFetchSize
  36. // defaults to 0
  37. OracleCommand cmd = new OracleCommand(sql, con);
  38.  
  39. cmd.InitialLOBFetchSize = 8192;
  40.  
  41. // create a datareader
  42. OracleDataReader dr = cmd.ExecuteReader();
  43.  
  44. // read the single row result
  45. try
  46. {
  47. dr.Read();
  48. }
  49. catch (OracleException ex)
  50. {
  51. MessageBox.Show(ex.Message);
  52. }
  53.  
  54. // use typed accessor to retrieve the blob
  55. OracleBlob blob = dr.GetOracleBlob(0);
  56.  
  57. // create a memory stream from the blob
  58. MemoryStream ms = new MemoryStream(blob.Value);
  59.  
  60. // set the image property equal to a bitmap
  61. // created from the memory stream
  62. pictureBox1.Image = new Bitmap(ms);
Add Comment
Please, Sign In to add comment