MacLochlainns Weblog

Michael McLaughlin's Technical Blog

Site Admin

Query Oracle database

with 105 comments

I caught a post on the OTN forum asking how to do this, and it happened to be something I’m working on for a new course that I’ll be teaching on data analytics. Ultimately, Microsoft Excel is the de facto tool of many accounts and financial analysts, protests notwithstanding.

This shows you how to query an Oracle 11g database from Excel 2007 (only available when you do a FULL install of Excel 2007). Actually, it should work on any current version of the Oracle database. The key to making this work is having the Oracle 10g Client software or an Oracle 11g database on the same machine. The Oracle client software allows you to resolve an Oracle Network Alias (found in the %ORACLE_HOME%\network\admin\tnsnames.ora file).

Here are the instructions with screen shots:

1. Click on the Data ribbon, and then click on the From Other Sources icon in the Get External Data section, as shown:

2. When you click on the From Other Sources icon, you’ll get the following drop down list. Click on the From Data Connection Wizard item.

3.The Data Connection Wizard provides a number of Microsoft data sources, but you click the Other/Advanced option to connect to an Oracle database.

4. The Other/Advanced selection launches the Data Link Properties dialog with the Provider tab open and active. Click the Oracle Provider for OLE DB choice. If you don’t have the Oracle Provider for OLE DB option, download the Oracle Data Access Components for Windows from Oracle site. The installation should also load it as a new data source, if not you can follow the same instructions provided for MySQL’s ODBC here. After clicking the Oracle Provider for OLE DB choice, you click the Next button.

5. The Next button brings you to the Connection tab. You should fill it out as noted below, and if you wish check the Allow saving password checkbox.

6. Before preceding, you should verify that the connection works. Click the Test Connection button to do that, and if successful you’ll see the following. Click the OK button in the Microsoft Data Link dialog to complete the test and the OK button in the Data Link Properties dialog.

7. After setting up the data connection in the Data Link Properties dialog, you’ll be taken to the Data Connection Wizard dialog. Here you can pick any table that you have access to within the PL/SQL schema (remember a schema in Oracle is a database in Microsoft SQL Server or MySQL). Click the Next button to continue.

8. After clicking the Next button, you’ll see the second Data Connection Wizard dialog. Click the Finish button to begin importing the data.

9. The Import Data dialog asks you how and where you want to import it. The following chooses to import it as an ordinary table. Click the OK button to import the data from a table. If you want to write a query against one or more tables, click here for the additional instructions.

10. Imports into Excel 2007 as a table are automatically created as a table. The following screen shot formats the display columns.

You have a number of very advantageous features in Excel 2007. They allow a number of options that resemble working within a database but honestly they’re much more difficult than working in SQL. I’d advise you create preformatted data by using views. Then, query the views through these steps.

Written by maclochlainn

November 7th, 2008 at 12:25 am

105 Responses to 'Query Oracle database'

Subscribe to comments with RSS or TrackBack to 'Query Oracle database'.

  1. Hammad, You can write a SQL Query and assign the results to the Excel page, instead of a table. I’ve written the following post to highlight how to use a query instead of a table reference.

    maclochlainn

    20 Nov 15 at 11:46 pm

  2. Hi,
    i want to connect oracle DB using excel 2013(32 bit) in windows8.1 (64 bit)
    always throws an error message
    “Net working components were not found..
    Please help me on this

    Vinay

    26 Nov 15 at 3:23 am

  3. Viney, You need 32-bit drivers for Oracle client installed on your server. Otherwise you’re trying to connect a 32-bit client software with 64-bit server software and it won’t work.

    maclochlainn

    21 Dec 15 at 8:25 pm

  4. Hi Guys,

    We are trying to build a small report, which needs to pull the data from DB into excel file, we are hitting a deadlock, tried most of the options suggested in google but couldn’t figure out a solution…so reaching out to you guys if anyone has tried to integrate excel and Oracle.

    1. the specified dsn contains architecture mismatch..
    2. oracle client and networking components are not found.

    revanth

    10 May 16 at 3:50 am

  5. Revanth, I’ll try to get to it but probably not for a couple weeks.

    maclochlainn

    10 May 16 at 11:16 pm

Leave a Reply