Skip to main content

Oracle Client インストール

brew で入れる場合 (自分的には非推奨)

brew install --cask instantclient-basic

→ この場合の制限は下記

  • Thin モードでしか使えない
    • select 結果を dictionary として取れない
    • tnsnames.ora での接続名解決できない
  • ネイティブライブラリでないので遅いかもしれない

→ あえて使う理由がわからん。「おとなしく純正を使おう」という感想

→ でも試してみた感じは、Thin モードのほうが速い・・謎

Oracle 純正

Download

https://www.oracle.com/jp/database/technologies/instant-client/downloads.html

  • M1 Mac なら ARM64 用をダウンロード
  • dmg ファイルを開くと、インストーラが起動するわけではなく、展開(マウント?)されるだけ
    • /Volumes/instantclient-basic-macos.arm64-23.3.0.23.09

いくつかある

  1. Python (たとえば) から使いたい → instantclient-basic を入れる
  2. SQL*Plus も使いたい → instantclient-sqlplus も入れる
  3. SQL*Loader も使いたい →instantclient-tools も入れる

配置

zsh
sudo mkdir -p /opt/oracle/instantclient_23_3

sudo cp -pi /Volumes/instantclient-basic*/* /opt/oracle/instantclient_23_3
sudo cp -pi /Volumes/instantclient-sqlplus*/* /opt/oracle/instantclient_23_3
sudo cp -pi /Volumes/instantclient-tools*/* /opt/oracle/instantclient_23_3

同じファイルは上書きしないことにした (readme とか installer のようだし)

環境変数設定

.zshrc
ORACLE_INSTANT_CLIENT_PATH=/opt/oracle/instantclient_23_3
export DYLD_LIBRARY_PATH=$ORACLE_INSTANT_CLIENT_PATH:$DYLD_LIBRARY_PATH
export PATH=$ORACLE_INSTANT_CLIENT_PATH:$PATH

ついでに言語設定

.zshrc
# NLS_LANG=Japanese_Japan.AL32UTF8
NLS_LANG=American_America.AL32UTF8

設定 再読み込み(または Terminal を開き直す)

zsh
. ~/.zshrc

tnsnames.ora を使用する場合

zsh
mkdir -p /opt/oracle/instantclient_23_3/network/admin
sudo vim /opt/oracle/instantclient_23_3/network/admin/tnsnames.ora

hp というのがホスト名だとして

tnsnames.ora
ORCLPDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = hp)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orclpdb)
)
)