// This should be pasted in a module of the workbook
1
2 Function ORAQUERY(strHost As String, strDatabase As String, strSQL As String, strUser As String, strPassword As String)
3 Dim strConOracle, oConOracle, oRsOracle
4 Dim StrResult As String
5
6 StrResult = ""
7
8 strConOracle = "Driver={Microsoft ODBC for Oracle}; " & _
9 "CONNECTSTRING=(DESCRIPTION=" & _
10 "(ADDRESS=(PROTOCOL=TCP)" & _
11 "(HOST=" & strHost & ")(PORT=1521))" & _
12 "(CONNECT_DATA=(SERVICE_NAME=" & strDatabase & "))); uid=" & strUser & " ;pwd=" & strPassword & ";"
13 Set oConOracle = CreateObject("ADODB.Connection")
14 Set oRsOracle = CreateObject("ADODB.Recordset")
15 oConOracle.Open strConOracle
16 Set oRsOracle = oConOracle.Execute(strSQL)
17 Do While Not oRsOracle.EOF
18 If StrResult <> "" Then
19 StrResult = StrResult & Chr(10) & oRsOracle.Fields(0).Value
20 Else
21 StrResult = oRsOracle.Fields(0).Value
22 End If
23 oRsOracle.MoveNext
24 Loop
25 oConOracle.Close
26 Set oRsOracle = Nothing
27 Set oConOracle = Nothing
28 ORAQUERY = StrResult
29 End Function