Connecting with Oracle: Accessing Oracle via Access and Excel - Page 2

May 26, 2004

Configuring Access to connect to Oracle

Configuring Access is just about as simple as the previous steps. In the next example, I created a new Access database and used it to read Scott's EMP table. I also updated data and added a new employee.

As a side note, Oracle has stated that the Scott schema has become a deprecated feature. It seems that future releases will be using the sample schemas (HR, SH, etc.) you see installed when using DBCA. If you want to keep the Scott schema, you can get its creation scripts from one of two places: ORACLE_HOME\rdbms\admin\utlsampl.sql and \sqlplus\demo\demobld.sql.

Start Access and create a new database. Go to File>External Data>Link Tables. In the Link window, you will have to scroll down the list shown in the Files of Type field. Select ODBC Database as shown in the screenshot.

Click for larger image

Once you have done that, you will be prompted to select a data source. Switch tab views to the Machine Data Source tab. Recognize the items in that list? You should, because it is the same as what you previously saw in the ODBC Data Source Administrator window.

After highlighting your Oracle database data source, click OK. You will be presented with a list of tables. You can control-click on tables to add more than one at a time. Shown below is the area in the list where Scott's tables reside (somewhat towards the bottom of the list).

I selected BONUS, EMP, DEPT and SALGRADE. After selecting the tables, you will be ready to access them. Highlight one (EMP, in this case) and click Open.

The results of querying the EMP table should look very familiar. In the display shown below, I changed James' salary to 952 and saved the table.

Did the save (update) operation take effect? Let's see.

SQL> select * from emp;

     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 17-DEC-80        800                    20
      7499 ALLEN2     SALESMAN        7698 20-FEB-81       1600        300         30
      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
      7566 JONES      MANAGER         7839 02-APR-81       2975                    20
      7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
      7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
      7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
      7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
      7839 KING       PRESIDENT            17-NOV-81       5000                    10
      7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
      7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
      7900 JAMES      CLERK           7698 03-DEC-81        952 LOOK HERE        30
      7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
      7934 MILLER     CLERK           7782 23-JAN-82       1300                    10

14 rows selected.

A simple query in SQL*Plus confirms the update (LOOK HERE was typed in later). That was easy, but what if I had made a mistake? For example, what happens if I create a new employee, but violate a constraint? In the screenshot shown below, I attempted to insert a new employee named Linda Cole, but I used an existing empno. What does Access tell me about what happened?

The ODBC call failed,

and here is why:

After fixing my mistake, the save (insert) operation takes place, and a query in SQL*Plus confirms it.

SQL> /

     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 17-DEC-80        800                    20
      7499 ALLEN2     SALESMAN        7698 20-FEB-81       1600        300         30
      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
      7566 JONES      MANAGER         7839 02-APR-81       2975                    20
      7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
      7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
      7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
      7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
      7839 KING       PRESIDENT            17-NOV-81       5000                    10
      7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
      7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
      7900 JAMES      CLERK           7698 03-DEC-81        952                    30
      7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
      7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
***** 7935 COLE       LINDA           7839 01-MAY-04       4000                    30

15 rows selected.







The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers