PC Review


Reply
Thread Tools Rate Thread

clob into oracle

 
 
ewen mcdonald
Guest
Posts: n/a
 
      15th Sep 2003
Can any one give me an example of using the microsoft .net
managed provider for oracle to insert a clob into the
database.
We have a stored procedure which takes a clob as a
parameter, but are struggling to populate a clob type
parameter with the text we want to save.
 
Reply With Quote
 
 
 
 
Paul Clement
Guest
Posts: n/a
 
      15th Sep 2003
On Mon, 15 Sep 2003 04:47:19 -0700, "ewen mcdonald" <(E-Mail Removed)> wrote:

¤ Can any one give me an example of using the microsoft .net
¤ managed provider for oracle to insert a clob into the
¤ database.
¤ We have a stored procedure which takes a clob as a
¤ parameter, but are struggling to populate a clob type
¤ parameter with the text we want to save.

What kind of problems are you having? Keep in mind that Oracle stored procedure parameters are
limited to 32k.


Paul ~~~ (E-Mail Removed)
Microsoft MVP (Visual Basic)
 
Reply With Quote
 
Ewen McDonald
Guest
Posts: n/a
 
      15th Sep 2003
I am running the following code based on a microsoft article :
http://support.microsoft.com/default...b;en-us;322796

Dim conn As New OracleConnection("server=;Uid=;pwd=")
Dim filePath As String

filePath = "C:\temp\test.txt" 'Add the path to the file you want
to insert
If Not File.Exists(filePath) Then
' handle error
End If

Dim fs As New FileStream(filePath, FileMode.OpenOrCreate,
FileAccess.Read)

'Dim fs As Stream = File.OpenRead(filePath)
Dim tempBuff(fs.Length) As Byte

fs.Read(tempBuff, 0, fs.Length)
fs.Close()
conn.Open()

Dim tx As OracleTransaction
tx = conn.BeginTransaction()

Dim cmd As New OracleCommand()
cmd = conn.CreateCommand()

cmd.Transaction = tx

cmd.CommandText = "declare xx clob; begin
dbms_lob.createtemporary(xx, false, 0); :tempclob := xx; end;"
cmd.Parameters.Add(New OracleParameter("tempclob",
OracleType.Clob)).Direction = ParameterDirection.Output
cmd.ExecuteNonQuery()

Try

Dim tempLob As OracleLob
tempLob = cmd.Parameters(0).Value
tempLob.BeginBatch(OracleLobOpenMode.ReadWrite)

tempLob.Write(tempBuff, 0, tempBuff.Length)
tempLob.EndBatch()


cmd.Parameters.Clear()
cmd.CommandText = "InsertClob.TestClobInsert"
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add(New OracleParameter("ClobParam",
OracleType.Clob)).Value = tempLob

cmd.ExecuteNonQuery()
Catch myex As Exception
MsgBox(myex.Message)
End Try
tx.Commit()


my test file contains the following string : abcdefghi
the code runs ok, but I get "żżżżi" in the database????

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
David Browne
Guest
Posts: n/a
 
      15th Sep 2003

"ewen mcdonald" <(E-Mail Removed)> wrote in message
news:081701c37b7f$1e11ec60$(E-Mail Removed)...
> Can any one give me an example of using the microsoft .net
> managed provider for oracle to insert a clob into the
> database.
> We have a stored procedure which takes a clob as a
> parameter, but are struggling to populate a clob type
> parameter with the text we want to save.


Oracle has an example using ODP.NET:

http://otn.oracle.com/sample_code/te...ob/UpdLob.html

And in general I would recommend using ODP.NET over the Microsoft managed
provider.
It's faster, better supported and exposes much more Oracle functionality.

David


 
Reply With Quote
 
Paul Clement
Guest
Posts: n/a
 
      15th Sep 2003
On Mon, 15 Sep 2003 07:26:45 -0700, Ewen McDonald <(E-Mail Removed)> wrote:

¤ I am running the following code based on a microsoft article :
¤ http://support.microsoft.com/default...b;en-us;322796
¤
¤ Dim conn As New OracleConnection("server=;Uid=;pwd=")
¤ Dim filePath As String
¤
¤ filePath = "C:\temp\test.txt" 'Add the path to the file you want
¤ to insert
¤ If Not File.Exists(filePath) Then
¤ ' handle error
¤ End If
¤
¤ Dim fs As New FileStream(filePath, FileMode.OpenOrCreate,
¤ FileAccess.Read)
¤
¤ 'Dim fs As Stream = File.OpenRead(filePath)
¤ Dim tempBuff(fs.Length) As Byte
¤
¤ fs.Read(tempBuff, 0, fs.Length)
¤ fs.Close()
¤ conn.Open()
¤
¤ Dim tx As OracleTransaction
¤ tx = conn.BeginTransaction()
¤
¤ Dim cmd As New OracleCommand()
¤ cmd = conn.CreateCommand()
¤
¤ cmd.Transaction = tx
¤
¤ cmd.CommandText = "declare xx clob; begin
¤ dbms_lob.createtemporary(xx, false, 0); :tempclob := xx; end;"
¤ cmd.Parameters.Add(New OracleParameter("tempclob",
¤ OracleType.Clob)).Direction = ParameterDirection.Output
¤ cmd.ExecuteNonQuery()
¤
¤ Try
¤
¤ Dim tempLob As OracleLob
¤ tempLob = cmd.Parameters(0).Value
¤ tempLob.BeginBatch(OracleLobOpenMode.ReadWrite)
¤
¤ tempLob.Write(tempBuff, 0, tempBuff.Length)
¤ tempLob.EndBatch()
¤
¤
¤ cmd.Parameters.Clear()
¤ cmd.CommandText = "InsertClob.TestClobInsert"
¤ cmd.CommandType = CommandType.StoredProcedure
¤ cmd.Parameters.Add(New OracleParameter("ClobParam",
¤ OracleType.Clob)).Value = tempLob
¤
¤ cmd.ExecuteNonQuery()
¤ Catch myex As Exception
¤ MsgBox(myex.Message)
¤ End Try
¤ tx.Commit()
¤
¤
¤ my test file contains the following string : abcdefghi
¤ the code runs ok, but I get "żżżżi" in the database????


I think you're encountering a unicode conversion issue by doing a read/write to the tempLob. If
you're going to use a stored procedure, just do a straight Insert using an Oracle.Clob parameter
type.


Paul ~~~ (E-Mail Removed)
Microsoft MVP (Visual Basic)
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Oracle <CLOB> question jason Microsoft Excel Programming 3 20th Nov 2009 07:52 PM
ACCESS/ORACLE CLOB datatype-export ACCESS report to EXCEL CLOB tru Lynn Microsoft Access Form Coding 0 18th Jul 2008 04:01 PM
Oracle CLOB column =?Utf-8?B?RGlmZmlkZW50?= Microsoft ASP .NET 0 7th Jun 2005 03:42 PM
how to insert a clob to Oracle 9i db Linda Chen Microsoft ADO .NET 1 2nd Jul 2004 02:18 PM
C# Oracle CLOB Puleen Patel Microsoft ADO .NET 6 24th Mar 2004 09:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:04 PM.