[20181224]使用odbc連線oracle資料庫.txt

lfree發表於2018-12-24

[20181224]使用odbc連線oracle資料庫.txt


--//測試使用odbc連線oracle資料庫.


1.首先檢查是否按照odbc驅動:


# scp unixODBC64-*x86_64* root@192.168.100.78:/root/rpm_tgz/

root@192.168.100.78's password:

unixODBC64-2.2.14-3.el5.x86_64.rpm         100%  138KB 137.8KB/s   00:00

unixODBC64-devel-2.2.14-3.el5.x86_64.rpm   100%   44KB  43.8KB/s   00:00

unixODBC64-libs-2.2.14-3.el5.x86_64.rpm    100%  331KB 330.7KB/s   00:00


# scp libtool-ltdl-1.5.22-7.el5_4.x86_64.rpm root@192.168.100.78:/root/rpm_tgz

root@192.168.100.78's password:

libtool-ltdl-1.5.22-7.el5_4.x86_64.rpm     100%   38KB  37.6KB/s   00:00


--//注:我伺服器是64位的,可以選擇按照64位版本.


# rpm -ivh unixODBC64-2.2.14-3.el5.x86_64.rpm unixODBC64-devel-2.2.14-3.el5.x86_64.rpm unixODBC64-libs-2.2.14-3.el5.x86_64.rpm libtool-ltdl-1.5.22-7.el5_4.x86_64.rpm

warning: unixODBC64-2.2.14-3.el5.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 1e5e0159

Preparing...                ########################################### [100%]

   1:libtool-ltdl           ########################################### [ 25%]

   2:unixODBC64-libs        ########################################### [ 50%]

   3:unixODBC64             ########################################### [ 75%]

   4:unixODBC64-devel       ########################################### [100%]


2.建立配置檔案:

--//定位驅動程式.

$ locate libsqora.so

/u01/app/oracle/product/11.2.0.4/dbhome_1/lib/libsqora.so.11.1


$ mkdir odbc

$ cd    odbc


--//也可以配置在/etc下odbc.ini,odbcinst.ini檔案.


$ cat odbc.ini

[BOOK]

Driver = OracleODBC11

DSN = BOOK

ServerName = BOOK


$ cat odbcinst.ini

[OracleODBC11]

Description     = Oracle ODBC driver for Oracle 11

Driver          = /u01/app/oracle/product/11.2.0.4/dbhome_1/lib/libsqora.so.11.1


$ export ODBCSYSINI=/home/oracle/odbc


3.測試:

$ isql BOOK scott book -v

[01000][unixODBC][Driver Manager]Can't open lib '/u01/app/oracle/product/11.2.0.4/dbhome_1/lib/libsqora.so.11.1' :libodbcinst.so.1: cannot open shared object file: No such file or directory

[ISQL]ERROR: Could not SQLConnect


--//奇怪libodbcinst在unixODBC64-libs包裡面已經安裝了.


# ls -l libodbcinst.so*

lrwxrwxrwx 1 root root    20 2018-12-24 09:16:56 libodbcinst.so -> libodbcinst.so.2.0.0

lrwxrwxrwx 1 root root    20 2018-12-24 09:16:55 libodbcinst.so.2 -> libodbcinst.so.2.0.0

-rwxr-xr-x 1 root root 64816 2011-12-21 06:56:57 libodbcinst.so.2.0.0

--//奇怪沒有連結到libodbcinst.so.1,連結的是libodbcinst.so.2.0.0.


# ln -s libodbcinst.so.2.0.0 libodbcinst.so.1

# ls -l libodbcinst.so*

lrwxrwxrwx 1 root root    20 2018-12-24 09:16:56 libodbcinst.so -> libodbcinst.so.2.0.0

lrwxrwxrwx 1 root root    20 2018-12-24 10:00:09 libodbcinst.so.1 -> libodbcinst.so.2.0.0

lrwxrwxrwx 1 root root    20 2018-12-24 09:16:55 libodbcinst.so.2 -> libodbcinst.so.2.0.0

-rwxr-xr-x 1 root root 64816 2011-12-21 06:56:57 libodbcinst.so.2.0.0


$ rlwrap isql BOOK scott book -v

+---------------------------------------+

| Connected!                            |

|                                       |

| sql-statement                         |

| help [tablename]                      |

| quit                                  |

|                                       |

+---------------------------------------+

SQL> select * from dept;

+-------+---------------+--------------+

| DEPTNO| DNAME         | LOC          |

+-------+---------------+--------------+

| 10    | ACCOUNTING    | NEW YORK     |

| 20    | RESEARCH      | DALLAS       |

| 30    | SALES         | CHICAGO      |

| 40    | OPERATIONS    | BOSTON       |

+-------+---------------+--------------+

SQLRowCount returns -1

4 rows fetched

--//OK.

--//估計自己也不會用,僅僅作為簡單的學習筆記.


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2286153/,如需轉載,請註明出處,否則將追究法律責任。

相關文章