Вы находитесь на странице: 1из 8

Setting up the data source definition

If you expand the Start>Programs>Your Oracle Home program>Configuration and


Migration Tools path, you will see a utility named Microsoft ODBC Administrator. Launch
that utility to begin the process. If you have a fairly standard PC from any major vendor, it
will already have definitions for dBASE, Excel and Access (note that these are all
Microsoft products). Not to worry, because adding an Oracle database as a source is just
a few clicks away. Shown below is a typical pre-Oracle view of the window.

Click on the Add button to add a new data source. In the window shown below, simply
enter the name of your Oracle database, give it a description, enter the name of the
service and provide a user ID (I added Scott's password so as not to be prompted for it
down the road). If you want to test the connectivity, click on the Test Connection button
(good idea).
If your connection test was successful, you will see the following

After clicking OK on the Oracle ODBC Driver Configuration window, you will see your
Oracle database listed in the ODBC Data Source Administrator window.
Now you are ready to make a link in Access.

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.
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.

Вам также может понравиться