vbaでOracleに接続

 

Const PROVIDER = "OraOLEDB.Oracle"
Const DATA_SOURCE = "XEPDB1"
Const USER_ID = "USER"
Const PASSWORD = "PASS"

Sub Test()
Dim sql As String
sql = "select sysdate from dual"
Dim conn As New ADODB.Connection

conn.ConnectionString = "Provider=" & PROVIDER & ";" & _
"Data Source=" & DATA_SOURCE & ";" & _
"USER ID=" & USER_ID & ";" & _
"Password=" & PASSWORD & ";"

conn.Open

Dim rs As New ADODB.Recordset

rs.Source = sql
rs.ActiveConnection = conn

rs.Open


Do Until rs.EOF
MsgBox (rs(0).Value)

rs.MoveNext
Loop

rs.Close

conn.Close

MsgBox "test"
End Sub