2010-08-03 52 views

回答

1

下面是一些示例代碼:

Dim objConn 
Set objConn = CreateObject("ADODB.Connection") 

Dim connString 
connString = "YOUR ORACLE CONNECTION STRING HERE!" 

objConn.Open connString 

Dim objRS 
Dim strSQL 
strSQL = "SELECT * FROM YourTable" 

Set objRS = objConn.Execute(strSQL) 
If objRS.EOF Then 
    ' No Records Returned 
Else 
    Do 
      ' Do what you want with your output 
     objRS.MoveNext 
    Loop Until objRS.EOF 
End If 
End With 

objRS.Close 
Set objRS = Nothing 


objConn.Close 
Set objConn = Nothing 

使用Oracle Connection Strings頁面找到你的連接字符串。這是VBScript,對於VB,您可能需要進行一些更改,例如定義變量類型。

Dim strSQL As String 
1

下面是如何使用Oracle對象爲OLE自動化與Excel一個例子:

... 
' Declare variables 
Dim OraSession As OraSession 
Dim OraDatabase As OraDatabase 
Dim OraDynaset As OraDynaset 
Dim OraFields As OraFields 

' Create the OraSession Object. The argument to CreateObject is the 
' name by which the OraSession object is known to the OLE system. 
Set OraSession = CreateObject("OracleInProcServer.XOraSession") 

' Create the OraDatabase Object by opening a connection to Oracle. 
Set OraDatabase = OraSession.OpenDatabase("ExampleDb", "scott/tiger", 0&) 

' Create the OraDynaset Object. 
Set OraDynaset = OraDatabase.CreateDynaset("select * from emp", 0&) 

' You can now display or manipulate the data in the dynaset. For example: 
Set OraFields = OraDynaset.fields 
OraDynaset.movefirst 
Do While Not OraDynaset.EOF 
    gMsgBox OraFields("ename").Value 
    OraDynaset.movenext 
Loop 
:從上面的鏈接

http://download.oracle.com/docs/cd/B28359_01/win.111/b28378/clients.htm#CIHFAHJJ

實施例