A 100 million question among IT managers???
MS-EXCEL is one of the most useful business tool, but can I display the RECORDS from our company Database... say from ORACLE?
This will enable the executive to process the data as per their working style and make useful decision!!! This facility offers flexibility and fidelity.
Here is a simple solution from kg.
MS-EXCEL can access data from any ODBC compatible RDBMS. Being a popular RDBMS of many corporate choice, I am going to demonstrate how to access ORACLE data using MS-EXCEL.
Step by Step Procedure
- Create a Data Source Name in ODBC. Using
Control panel
Administrative Tools
Data Sources (ODBC)
Add an User DSN (You can get help from competitive person from your organization) - Start MS-EXCEL
- Start Visual Basic Editor (Tools / Macro / Visual Basic Editor)
- In the VBE (Visual Basic Editor), view the Project Explorer
(VIEW / Project Explorer) I use CTRL+R key. - Double click on the ThisWorkBook. You can see the CODE WINDOW. In this select WorkBook in the Object List and select Open in the Event List.
- Type the following code in Workbook_Open procedure
Private Sub Workbook_Open()
Dim cnEmp As ADODB.Connection
Dim rsEmp As ADODB.Recordset
If cnEmp Is Nothing Then
Set cnEmp = New ADODB.Connection
With cnEmp
.ConnectionString = "DRIVER={Microsoft ODBC for Oracle};UID=SCOTT;PWD=TIGER;"
.Open
End With
End If
If rsEmp Is Nothing Then
Set rsEmp = New ADODB.Recordset
rsEmp.Open "select * from emp", cnEmp, adOpenStatic, adLockBatchOptimistic
End If
'To display Column names
For i = 1 To rsEmp.Fields.Count
Sheets("Sheet1").Cells(3, i).Value = rsEmp.Fields(i - 1)
End If
Sheets("sheet1").Range("a4").CopyFromRecordset rsEmp
End Sub
Here I uploaded the excel workbook also.
I hope that this is a simple yet more useful solution. Once you tasted, I am sure you will not leave this elegant tool. It can be put into effective use by ORACLE DBAs.
Once again, You can email me your queries. I am ready to give my assistance.
No comments:
Post a Comment