tech_memo / ORACLE / SQLPlus


tech_memo/ORACLE

プラグイン

rlwrap

  • 履歴参照や、矢印キーが利用可能になる。
    rlwrap sqlplus
  • sqlplusでパイプ+シェルコマンドを利用できるようにする
    rlwrap -z"pipeto" sqlplus
    • https://yoku0825.blogspot.jp/2015/12/sqlplusrlwrap.html
    • ただし、このままだと、||による文字列連結ができなくなるので、以下のパッチを適用したほうがよい。
      *** /usr/share/rlwrap/filters/pipeto.orig       2010-01-03 21:42:16.000000000 +0900
      --- /usr/share/rlwrap/filters/pipeto    2015-12-08 10:58:54.817411488 +0900
      ***************
      *** 53 ****
      !   ($input, undef, $pipeline) =  /([^|]*)(\|(.*))?/;
      --- 53,54 ----
      !   ($input, $pipeline) =  /(.+)?\s+\|\s+(.*)?/;
      !   $input= $_ unless $input;

rlwrap_ext

DATE型、TIMESTAMP型データのフォーマット変更

  • セッションレベルで変更
    • DATE型
      ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY/MM/DD HH24:MI:SS';
    • TIMESTAMP型
      ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYY/MM/DD HH24:MI:SS';

SQL*Plusシステム変数一覧


システム変数のデフォルト値変更

  • $ORACLE_HOME/sqlplus/admin/glogin.sql に記述する
    --
    -- Copyright (c) 1988, 2005, Oracle.  All Rights Reserved.
    --
    -- NAME
    --   glogin.sql
    --
    -- DESCRIPTION
    --   SQL*Plus global login "site profile" file
    --
    --   Add any SQL*Plus commands here that are to be executed when a
    --   user starts SQL*Plus, or uses the SQL*Plus CONNECT command.
    --
    -- USAGE
    --   This script is automatically run
    --
    set lines 200