SQL*Plus s Forgotten History



Similar documents
Opening a Command Shell

Introduction to the Oracle DBMS

Cygwin: getting the setup tool

linux20 (R12 Server) R Single Node SID - TEST linux1 (10gAS Server) Oracle 10gAS ( ) with OID SID - asinf server name

MySQL Backups: From strategy to Implementation

Oracle Backup and Recover 101. Osborne Press ISBN

Apache 2.0 Installation Guide

Installing (1.8.7) 9/2/ Installing jgrasp

MyOra 3.0. User Guide. SQL Tool for Oracle. Jayam Systems, LLC

1. Installation Instructions - Unix & Linux

Toad for Data Analysts, Tips n Tricks

Setting up SQL Translation Framework OBE for Database 12cR1

Oracle Tools and Bindings with languages

Oracle SQL*PLUS (For , Fall 2006) Prepared by: Mr. Nkulu Nkasa

MyOra 3.5. User Guide. SQL Tool for Oracle. Kris Murthy

SWsoft Plesk 8.2 for Linux/Unix Backup and Restore Utilities. Administrator's Guide

Setting up PostgreSQL

Oracle Database Express Edition

Backing Up Your System With rsnapshot

SWsoft Plesk 8.3 for Linux/Unix Backup and Restore Utilities

Mercury User Guide v1.1

INASP: Effective Network Management Workshops

LAE Enterprise Server Installation Guide

Configuring MailArchiva with Insight Server

INSTALLATION INSTRUCTIONS FOR THE STUDENT SAMPLE SCHEMA

IBM i Version 7.2. Systems management Advanced job scheduler

2Creating Reports: Basic Techniques. Chapter

Steps for running C-program

MyOra 4.5. User Guide. SQL Tool for Oracle. Kris Murthy

STATISTICA VERSION 10 STATISTICA ENTERPRISE SERVER INSTALLATION INSTRUCTIONS

User Manual - Help Utility Download MMPCT. (Mission Mode Project Commercial Taxes) User Manual Help-Utility

Creating a Java application using Perfect Developer and the Java Develo...

An Introduction to the Linux Command Shell For Beginners

PMOD Installation on Linux Systems

PrimeRail Installation Notes Version A June 9,

Merging Labels, Letters, and Envelopes Word 2013

CA Workload Automation Agent for Microsoft SQL Server

Creating a DUO MFA Service in AWS

CA Workload Automation Agent for Databases

Integrating Network Appliance Snapshot and SnapRestore with VERITAS NetBackup in an Oracle Backup Environment

Backing up and restoring HP Systems Insight Manager 6.0 or greater data files in a Windows environment

Online Backup Client User Manual

PuTTY/Cygwin Tutorial. By Ben Meister Written for CS 23, Winter 2007

Improved document archiving speeds; data enters the FileNexus System at a faster rate! See benchmark test spreadsheet.

Suite. How to Use GrandMaster Suite. Exporting with ODBC

Signiant Agent installation

11. Oracle Recovery Manager Overview and Configuration.

RecoveryVault Express Client User Manual

Bitrix Site Manager ASP.NET. Installation Guide

Installing IBM Websphere Application Server 7 and 8 on OS4 Enterprise Linux

Microsoft Windows PowerShell v2 For Administrators

Oracle server: An Oracle server includes an Oracle Instance and an Oracle database.

DEPLOYMENT GUIDE Version 1.1. Deploying the BIG-IP LTM System with Citrix XenDesktop

Installation Guide for Basler pylon 2.3.x for Linux

Setting up the Oracle Warehouse Builder Project. Topics. Overview. Purpose

Source Code Management for Continuous Integration and Deployment. Version 1.0 DO NOT DISTRIBUTE

This appendix describes the following procedures: Cisco ANA Registry Backup and Restore Oracle Database Backup and Restore

Online Backup Linux Client User Manual

Online Backup Client User Manual

SEAGATE BUSINESS NAS ACCESSING THE SHELL. February 1, 2014 by Jeroen Diel IT Nerdbox

OmniDB - User s Guide

Web Testing, Java Testing, Server Monitoring. AppPerfect Installation Guide

Document Conventions... 2 Technical Requirements Logging On... 3 Logging Off Main Menu Panel... 4 Contents Panel... 4 Document Panel...

Installing the ASP.NET VETtrak APIs onto IIS 5 or 6

Lab 1: Introduction to C, ASCII ART and the Linux Command Line Environment

HP-UX Essentials and Shell Programming Course Summary

Online Backup Client User Manual

Basic C Shell. helpdesk@stat.rice.edu. 11th August 2003

Network Security EDA /2012. Laboratory assignment 4. Revision A/576, :13:02Z

Installing and Configuring SQL Express 2008 R2 for Supply Chain Guru

WebIOPi. Installation Walk-through Macros

Mobile: Getting Started with Workday for ipad

CLC Server Command Line Tools USER MANUAL

ArpViewer Manual Version Datum

1. Product Information

Online Backup Client User Manual Linux

Oracle Database 11g: SQL Tuning Workshop

Integration Service Database. Installation Guide - Oracle. On-Premises

Extending Remote Desktop for Large Installations. Distributed Package Installs

Database Programming with PL/SQL: Learning Objectives

My Oracle Support Portal

Command Line - Part 1

Configuring and Integrating Oracle

GETTING STARTED WITH FLEXI-CLOUD

Novell Identity Manager

Linux command line. An introduction to the Linux command line for genomics. Susan Fairley

Internet Explorer 7. Getting Started The Internet Explorer Window. Tabs NEW! Working with the Tab Row. Microsoft QUICK Source

LRGS Client Getting Started Guide

ez Publish Extension for Oracle(R) database 2.0 ez Publish Extension Manual

<odesi> Survey Example Canadian Community Health Survey (CCHS)

Welcome to GAMS 1. Jesper Jensen TECA TRAINING ApS This version: September 2006

The full setup includes the server itself, the server control panel, Firebird Database Server, and three sample applications with source code.

Eclipse.org CDT and Cygwin: A Tutorial on Installation and Functionality

Oracle Database: Develop PL/SQL Program Units

Zenoss Resource Manager ZenUp Installation and Administration

About the HealthStream Learning Center

Manual for Configuring Cisco Any Connect Secure Mobility Client in Linux Red Hat

Transcription:

SQL*Plus s Forgotten History Harald van Breederode Senior Principal DBA Instructor Oracle University NL You use SQL*Plus on a daily basis to perform various DBA activities but wonder why the SQL*Plus command history is restricted to the last command in the command buffer You wish for less cumbersome SQL statement command line editing, and for a command history that persists across SQL*Plus sessions In this edition of OU Expert s Corner we will demonstrate a cure for SQL*Plus amnesia, and provide full command line editing support using a program called rlwrap What is rlwrap RLWRAP is a readline wrapper program written by Hans Lub from The Netherlands that provides command line tools with history and editing support It is designed to run on Unix based systems including Oracle Enterprise Linux and works as a wrapper around the GNU readline library, which is also used in the familiar Linux Bash shell One may also use rlwrap on Windows systems using the Cygwin toolset, but that is outside the scope of this article Downloading rlwrap The quickest way to download rlwrap is to navigate to googlecom, enter rlwrap nl and hit the I am feeling lucky button This should open the rlwrap homepage http://utopiaknowarenl/~hlub/uck/rlwrap/ where one may download the rlwrap distribution file (called rlwrap-030targz at the time of writing this article) Installing rlwrap After the rlwrap compressed tar file is downloaded one must compile and install this extremely useful utility This involves four steps listed below 1 The first step is to uncompress and untar the file using the tar command: Oracle> tar xzf rlwrap-030targz Note: Red font denotes data entered at the terminal in all code examples 1

2 The next step is to change the current working directory to the rlwrap source code tree directory and run the configure command in order to adjust the source code tree to the specifics of the machine s operating system: Oracle> cd rlwrap-030 Oracle> /configure checking build system type i686-pc-linux-gnu checking host system type i686-pc-linux-gnu <output omitted> Now do: make (or gmake) to build rlwrap make check for instructions how to test it make install to install it 3 Next, the rlwrap source code tree is ready to be compiled using the make command: Oracle> make make all-recursive make[1]: Entering directory `/fs02/home/oracle/rlwrap-030' Making all in doc <output omitted> make[2]: Leaving directory `/fs02/home/oracle/rlwrap-030' make[1]: Leaving directory `/fs02/home/oracle/rlwrap-030' 2

4 The final step is to install the program that was just compiled using make install The root user must execute this step, because it installs rlwrap into the so-called local bin directory Oracle> sudo make install Making install in doc <output omitted> make[2]: Leaving directory `/fs02/home/oracle/rlwrap-030' make[1]: Leaving directory `/fs02/home/oracle/rlwrap-030' Note: If root access is prohibited copy the rlwrap to a personal bin directory instead Invoking SQL*PLUS with rlwrap Now that the download, compilation and installation are complete, rlwrap is ready for use Instead of invoking SQL*Plus in the usual manner, it is invoked as an argument of rlwrap as follows: Oracle> rlwrap sqlplus / as sysdba Note: rlwrap may be used in this manner for any program that lacks command line editing and history functionality This includes both other Oracle command line utilities and any other non-oracle utilities Automating SQL*PLUS with rlwrap To automate the invocation of sqlplus under control of rlwrap, one may define an alias as follows: Oracle> alias sqlplus -bash: alias: sqlplus: not found Oracle> alias sqlplus='rlwrap sqlplus' Oracle> alias sqlplus alias sqlplus='rlwrap sqlplus' 3

The first alias command checks for the existence of an alias for sqlplus The second command defines such an alias, and the third command returns the alias definition Note: To automate the definition of this alias at login, add the second command above to $HOME/bashrc file The appearance and behaviour of SQL*Plus are unaffected by this utility except for new editing and history capabilities provided by executing it through rlwrap: 1 The command line may be edited by navigating left or right with the arrow keys and overtyping 2 One may retrieve previous commands with the up and down arrow keys and then edit them, submit them or both See the example below 3 All commands are saved in the command history for both the current session and from the previous sessions Here is an example: SQL> select count(*) from dba_users; COUNT(*) ---------- 12 SQL> create user harald identified by prutser; User created -- Press up arrow and rlwrap recalls the previous statement SQL> create user harald identified by prutser; -- Press up arrow again to retrieve the one before that SQL> select count(*) from dba_users; 4

Some important additional features of rlwrap are: 1 Incremental Search 2 Custom Vocabulary 3 Application Specific History They are described in the following sections 1 Incremental Search Retrieval of previous commands using the up arrow key may be time consuming and error prone so rlwrap provides an incremental search feature to locate previous commands more easily Key CTRL+R followed by a string uniquely identifying the required statement or command The search is performed incrementally on the fly, and the most recently issued command matching the search string is displayed Each additional character entered refines the search, hence the term incremental search If the first match displayed is not the desired command or statement, key CTRL+R again and rlwrap will display the next most recent match for the same string This may be repeated until the end of the reverse history is reached or until the required command is found Here is an example: SQL> select count(*) from dba_users; COUNT(*) ---------- 12 SQL> create user harald identified by prutser; User created -- Press CTRL+R to perform an incremental search SQL>(reverse-i-search)`': -- While typing user rlwrap shows us the best match so far SQL> (reverse-i-search)`user : create user harald identified by prutser; -- Press CTRL+R again and rlwrap displays the next match SQL>(reverse-i-search)`user : select count(*) from dba_users; 5

2 Custom Vocabulary To enable faster typing, rlwrap supports a custom vocabulary feature by loading all words in the $HOME/<application>_completions file which if used, should contain vocabulary specific to the particular application To use this feature the following steps are required: 21 Capture the required keywords to the completion file 22 Manually add keywords if required 23 Copy the completion file to the correct location 24 Begin using Custom Vocabulary for Completion 21 Capture the SQL Keywords to the Completion File The creation of a completion file with a list of all reserved SQL words will save typing time for DBAs who work in command line A sample SQL script to do the capture looks as follows: set pages 0 set trimspool on set feedback off set echo off set heading off set termout off spool reserved_words select lower(keyword) from v$reserved_words where keyword like ' %' order by 1; spool off Note: The WHERE clause in the above SELECT statement filters out short reserved words which can be typed quickly and which do not benefit from the completion process 6

The generated file will contain keywords as follows: abort access create create_stored_outlines sequence sequential 22 Manually add keywords if required One may add words to the completion file for SQL*Plus commands, initora parameters, V$ view names, data dictionary view names, supplied PL/SQL Package names, or any other keywords specific to Oracle which are useful to DBAs 23 Copy the completion file to the correct location Copy the spooled reserved_words file to $HOME/sqlplus_completions to enable custom vocabulary for SQL 24 Using the completion file Once loaded, use of the TAB key after entering the first few characters of a word causes rlwrap to perform word completion based on the vocabulary in the file This may be very useful in Oracle as SQL*Plus and SQL have many word specific to the database environment If two or more words satisfy the search after using the TAB key, rlwrap will expand the word as much as possible and then sound a beep Keying TAB again, will display a list of possible completions for the characters already entered, and by typing one or more additional characters rlwrap should be able to complete the intended word 7

Here is an example of completion: SQL> cre -- Type cre SQL> cre <TAB> -- TAB expands cre to create SQL> create SQL> create seq -- Type seq SQL> create seq <TAB> -- TAB expands seq to seqen SQL> create sequen <TAB> -- TAB beeps SQL> create sequen <TAB> -- TAB lists possible expansions sequence sequential SQL> create sequenc Type a c SQL> create sequenc <TAB> -- TAB expands sequenc to sequence SQL> create sequence 3 Application Specific History Under the covers, command line input from terminals is handled by rlwrap, allowing command history to be accessed and editing to be done, after which rlwrap passes the results to SQL*Plus Command history is stored by default in an application specific history file in the home directory called <application>_history, where <application> is the name of the application controlled by rlwrap Thus $HOME/sqlplus_history is the name of the rlwrap command history file for SQL*Plus Conclusion Using rlwrap improves productivity by helping DBAs avoid the re-typing of commands in command line tools such as SQL*Plus, RMAN, LSNRCTL and other DBA utilities The auto-completion feature, whereby rlwrap completes reserved words or file names, helps to improve typing speed As rlwrap is built on top of the GNU readline library it can be completely personalized For more information see the readline manual page For the additional help on rlwrap, read the rlwrap manual page with man rlwrap 8