Add SQL edit feature into Oracle SQL*Plus. This improves your SQL life!

Make Oracle SQL*Plus command-line better

Improve SQL*Plus command-line environment

When we execute SQL in SQL*Plus tool, we can edit only previous SQL. If we typed a word in SQL, we need to write SQL from scratch. That is pain.

In order to solve the issue, I would like to introduce a better way to improve command-line life in SQL*Plus. As the following video, we can edit SQL in SQL*Plus tool.



Install socat command

In order to use the command-line editing feature like the video in SQL*Plus, we need to install "socat" command.

If you use RedHat or CentOS, we can install the socat package as follows.
$ sudo yum install socat

Using comand-line edit feature in SQL*Plus

Once we installed the socat command, we just need to type the following command. It asks us to enter username and password, then we are connected to database.

$ socat READLINE EXEC:'sqlplus',pty,setsid,ctty

If we need to put username and password into sqlplus command, we just need to add username and password as follows.
$ socat READLINE EXEC:'sqlplus username/password',pty,setsid,ctty

Once we are connected to database, please execute SQL, then press arrow keys (Up, Down, Left, Right), so that we can edit SQL and can see SQL history.

By utilizing this way, our SQL*Plus life should be much better than ever.


Once we are connected to database, please execute SQL, then press arrow keys (Up, Down, Left, Right), so that we can edit SQL and can see SQL history.

By utilizing this way, our SQL*Plus life should be much better than ever.


Keep SQL execution history

We added SQL editing feature into SQL*Plus, but once we disconnected from database, all SQL execution history is wiped out, but we can keep SQL execution history by utilizing the following command.
$ socat READLINE,history=$HOME/.sqlplus_history EXEC:'sqlplus',pty,setsid,ctty

Let's execute a couple of SQL statements in SQL*Plus, then look at $HOME/.sqlplus_history file, so that we can see all SQL statements we executed.