Linux Use ODBC Connect Oracle

eric0435發表於2020-03-26

因為工作需要,需要使用ODBC訪問Oracle,下面是ODBC訪問Oracle的具體配置
1.下載unixODBC和Oracle簡易客戶端軟體包
1.1下載地址:


1.1.1下載檔案:

unixODBC-2.3.0.tar.gz

2 Oracle ODBC Driver
2.1下載地址:


2.1.1下載檔案:

instantclient-sqlplus-linux.x64-12.2.0.1.0.zip
instantclient-basic-linux.x64-12.2.0.1.0.zip
instantclient-sdk-linux.x64-12.2.0.1.0.zip
instantclient-jdbc-linux.x64-12.2.0.1.0.zip
instantclient-odbc-linux.x64-12.2.0.1.0-2.zip
instantclient-basiclite-linux.x64-12.2.0.1.0.zip
instantclient-tools-linux.x64-12.2.0.1.0.zip

將這些軟體包上傳到/soft目錄

3.安裝unixODBC(root使用者)

#cd /soft
#tar xvf unixODBC-2.3.0.tar.gz
#cd /soft/unixODBC-2.3.0
#./configure
#make
#make install

(預設是被安裝到/usr/local)

4.安裝Oracle ODBC(root使用者)

#cd /soft/
#unzip instantclient-sqlplus-linux.x64-12.2.0.1.0.zip
#unzip instantclient-basic-linux.x64-12.2.0.1.0.zip
#unzip instantclient-sdk-linux.x64-12.2.0.1.0.zip
#unzip instantclient-jdbc-linux.x64-12.2.0.1.0.zip
#unzip instantclient-odbc-linux.x64-12.2.0.1.0-2.zip
#unzip instantclient-basiclite-linux.x64-12.2.0.1.0.zip
#unzip instantclient-tools-linux.x64-12.2.0.1.0.zip
[root@dmks instantclient_12_2]# ./odbc_update_ini.sh /usr/local
 *** ODBCINI environment variable not set,defaulting it to HOME directory!

更新操作完成後,會在/usr/local/etc/odbcinst.ini增加Oracle12C的驅動描述資訊。

[root@dmks etc]# cat odbcinst.ini
[DM7 ODBC DRIVER]
Description = ODBC DRIVER FOR DM7
Driver = /dm_home/dmdbms/bin/libdodbc.so
[Oracle 12c ODBC driver]
Description     = Oracle ODBC driver for Oracle 12c
Driver          = /soft/instantclient_12_2/libsqora.so.12.1
Setup           =
FileUsage       =
CPTimeout       =
CPReuse         =

並且會在HOME目錄下也就是/root,生成.odbc.ini檔案,修改.odbc.ini檔案

[root@dmks ~]# cat .odbc.ini
[OracleODBC-12c]
Application Attributes = T
Attributes = W
BatchAutocommitMode = IfAllSuccessful
BindAsFLOAT = F
CloseCursor = F
DisableDPM = F
DisableMTS = T
Driver = Oracle 12c ODBC driver
DSN = OracleODBC-12c
EXECSchemaOpt =
EXECSyntax = T
Failover = T
FailoverDelay = 10
FailoverRetryCount = 10
FetchBufferSize = 64000
ForceWCHAR = F
Lobs = T
Longs = T
MaxLargeData = 0
MetadataIdDefault = F
QueryTimeout = T
ResultSets = T
ServerName = shardcat 與tnsnames.ora檔案中的伺服器一致
SQLGetData extensions = F
Translation DLL =
Translation Option = 0
DisableRULEHint = T
UserID =
StatementCache=F
CacheBufferSize=20
UseOCIDescribeAny=F
SQLTranslateErrors=F
MaxTokenSize=8192
AggregateSQLType=FLOAT
5.測試ODBC連線Oracle
[root@dmks ~]# isql  OracleODBC-12c system xxzx7817600 -v
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL> select * from v$version;
+---------------------------------------------------------------------------------+-----------------------------------------+
| BANNER                                                                          | CON_ID                                  |
+---------------------------------------------------------------------------------+-----------------------------------------+
| Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production    | 0                                       |
| PL/SQL Release 12.2.0.1.0 - Production                                          | 0                                       |
| CORE  12.2.0.1.0      Production                                                      | 0                                       
| TNS for Linux: Version 12.2.0.1.0 - Production                                  | 0                                       |
| NLSRTL Version 12.2.0.1.0 - Production                                          | 0                                       |
+---------------------------------------------------------------------------------+-----------------------------------------+

到此使用odbc連線Oracle的操作完成,還是很簡單的。


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

相關文章