


RHEL 8にOracle Database 19cをインストールして勉強しています。
今回の一連の作業でsqlplusを起動してからのSQL文の入力が面倒で、テキストエディタからのコピー&ペーストでやっていました。
そもそもSQL文が書けない老眼SEですが…(泣
補完機能までは出来なくてもカーソルキーでヒストリーがでてくれば、少しは効率が上がるのに。
第5回 SQL*Plusを使いやすくする
https://www.intellilink.co.jp/article/column/oracle-yam05.html
有難う御座います。本当に助かります。
環境
・Red Hat Enterprise Linux release 8.5 (Ootpa)
・Kernel 4.18.0-348.7.1.el8_5.x86_64
・oracle-database-preinstall-19c-1.0-3.el7.x86_64.rpm
・oracle-database-ee-19c-1.0-1.x86_64.rpm
・開発環境、GNOME環境、日本語入力インストール
・Subscription登録
以下、作業でdnfコマンドを実行するとエラーになるかもしれません。
おそらくoracle repositoryと競合している可能性が高いので、その場合はoracle repositoryを無効にしてみて下さい。
- rlwrapのインストール
- codeready-builder-for-rhel-8-x86_64-rpmsの有効化
- EPEL repositoryのインストール
- rlwrapのインストール
- rlwrap-extensionsのインストール
- sql+, asm+をコピー
- 確認
- シンボリックリンクの作成
- 再度確認
rlwrapをインストールするにはEPEL repositoryが必要ですが、EPELをインストールするにはcodeready-builder-for-rhel-8-x86_64-rpmsが必要になります。
What’s EPEL, and how do I use it?
https://www.redhat.com/en/blog/whats-epel-and-how-do-i-use-it
1 2 |
[root@rhel8 ~]# subscription-manager repos --enable codeready-builder-for-rhel-8-x86_64-rpms Repository 'codeready-builder-for-rhel-8-x86_64-rpms' is enabled for this system. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
[root@rhel8 ~]# dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm Updating Subscription Management repositories. epel-release-latest-8.noarch.rpm 24 kB/s | 23 kB 00:00 Dependencies resolved. ============================================================================================================ Package Architecture Version Repository Size ============================================================================================================ Installing: epel-release noarch 8-13.el8 @commandline 23 k Transaction Summary ============================================================================================================ Install 1 Package Total size: 23 k Installed size: 35 k Is this ok [y/N]: y Downloading Packages: Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : epel-release-8-13.el8.noarch 1/1 Running scriptlet: epel-release-8-13.el8.noarch 1/1 Verifying : epel-release-8-13.el8.noarch 1/1 Installed products updated. Installed: epel-release-8-13.el8.noarch Complete! |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
[root@rhel8 ~]# dnf install rlwrap Updating Subscription Management repositories. Dependencies resolved. ============================================================================================================ Package Architecture Version Repository Size ============================================================================================================ Installing: rlwrap x86_64 0.44-1.el8 epel 128 k Transaction Summary ============================================================================================================ Install 1 Package Total download size: 128 k Installed size: 304 k Is this ok [y/N]: y Downloading Packages: rlwrap-0.44-1.el8.x86_64.rpm 397 kB/s | 128 kB 00:00 ------------------------------------------------------------------------------------------------------------ Total 147 kB/s | 128 kB 00:00 Extra Packages for Enterprise Linux 8 - x86_64 1.6 MB/s | 1.6 kB 00:00 Importing GPG key 0x2F86D6A1: Userid : "Fedora EPEL (8) <epel@fedoraproject.org>" Fingerprint: 94E2 79EB 8D8F 25B2 1810 ADF1 21EA 45AB 2F86 D6A1 From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8 Is this ok [y/N]: y Key imported successfully Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : rlwrap-0.44-1.el8.x86_64 1/1 Running scriptlet: rlwrap-0.44-1.el8.x86_64 1/1 Verifying : rlwrap-0.44-1.el8.x86_64 1/1 Installed products updated. Installed: rlwrap-0.44-1.el8.x86_64 Complete! |
rlwrap-extensionsをダウンロードして所定の場所に設置します。
rlwrap_ext
http://www.linuxification.at/rlwrap_ext.html.en
Oracle Version 12.1.0.2用までしか無いのでこれをダウンロードしました。
基本的なコマンドは変わらないと期待して。
設置は/usr/share/rlwrap/completionsになります。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
[root@rhel8 ~]# wget http://www.linuxification.at/download/rlwrap-extensions-V12-0.05.tar.gz [root@rhel8 ~]# cd /usr/share/rlwrap/completions [root@rhel8 completions]# tar xvfz ~root/rlwrap-extensions-V12-0.05.tar.gz adrci asm+ asmcmd dgmgrl README README.english rman sql+ sql.functions sqlplus sqlplus.all sqlplus.cdb sqlplus.dba sqlplus.dbms_packages sqlplus.functions sqlplus.gvdollar sqlplus.init sqlplus._init sqlplus.packages sqlplus.rman sqlplus.tables sqlplus.user sqlplus.utl_packages sqlplus.vdollar [root@rhel8 completions]# chown root:root * |
sql+, asm+をPATHの通っている場所にコピーします。/usr/loca/binにコピーしました。
1 2 |
[root@rhel8 completions]# cp sql+ /usr/local/bin/ [root@rhel8 completions]# cp asm+ /usr/local/bin/ |
oracleユーザで確認してみます。
あら!? /usr/local/share/rlwrap/completions/sqlplusが無いと。
1 2 |
[oracle@rhel8 ~]$ sql+ rootlinks/Password@ORCLPDB1 rlwrap: error: Could not open /usr/local/share/rlwrap/completions/sqlplus: そのようなファイルやディレクトリはありません |
1 2 |
[root@rhel8 completions]# mkdir -p /usr/local/share/rlwrap/ [root@rhel8 completions]# ln -s /usr/share/rlwrap/completions /usr/local/share/rlwrap/completions |
カーソルキーやTABでの入力補完機能が使えました。
1 2 3 4 5 6 7 8 9 10 |
[oracle@rhel8 ~]$ sql+ rootlinks/Password@ORCLPDB1 SQL*Plus: Release 19.0.0.0.0 - Production on Version 19.3.0.0.0 Copyright (c) 1982, 2019, Oracle. All rights reserved. 最終正常ログイン時間: 金 1月 14 2022 16:34:07 +09:00 Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Version 19.3.0.0.0 に接続されました。 SQL> SELECT |
aliasを設定してもいいかも。
1 2 3 4 5 6 7 8 9 10 11 12 |
[oracle@rhel8 ~]$ alias sqlplus=sql+ [oracle@rhel8 ~]$ sqlplus rootlinks/Password@ORCLPDB1 SQL*Plus: Release 19.0.0.0.0 - Production on Version 19.3.0.0.0 Copyright (c) 1982, 2019, Oracle. All rights reserved. 最終正常ログイン時間: 金 1月 14 2022 17:56:14 +09:00 Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Version 19.3.0.0.0 に接続されました。 SQL> SELECT * FROM |
【追記】
あとで気づいたのですがsql+ はスクリプトなので確認したら記述がありました。
スクリプトを修正した方がいいですね。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
[root@rhel8 ~]# cat /usr/local/bin/sql+ #!/bin/bash # This file is public domain and comes with NO WARRANTY of any kind # sql+ sqlplus with rlwrap [ _"$DEBUG" = _ON ] && set -x # saftey checks [ -n "$ORACLE_HOME" ] || { echo ORACLE_HOME is not set 1>&2; exit 1; } [ -d "$ORACLE_HOME/bin" ] || { echo ORACLE_HOME/bin is not a directory 1>&2; exit 1; } R_HOME=${RLWRAP_HOME:=/usr/local/share/rlwrap/completions} if [ $# = 0 ] ; then if [ _"${ORACLE_SID:0:1}" = _+ ] ; then set -- / as sysasm else set -- / as sysdba fi fi # prepare list of stop words FILE_LIST="-f $R_HOME/sqlplus -f $R_HOME/sqlplus.all -f $R_HOME/sqlplus.cdb -f $R_HOME/sqlplus.dba -f $R_HOME/sqlplus.dbms_packages -f $R_HOME/sqlplus.functions -f $R_HOME/sqlplus.gvdollar -f $R_HOME/sqlplus.init -f $R_HOME/sqlplus._init -f $R_HOME/sqlplus.packages -f $R_HOME/sqlplus.rman -f $R_HOME/sqlplus.tables -f $R_HOME/sqlplus.user -f $R_HOME/sqlplus.utl_packages -f $R_HOME/sqlplus.vdollar" exec rlwrap -i -b '()=!<>&+-*|:;,' $FILE_LIST $ORACLE_HOME/bin/sqlplus $* |
【さらに追記】
こちらは補完機能はありませんでした。
rlwrap for Command Line History and Editing in SQL*Plus and RMAN on Linux
https://oracle-base.com/articles/linux/rlwrap