Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SQL Plus - Previous Commands

1 view
Skip to first unread message

Chris A

unread,
Mar 28, 2002, 8:03:10 AM3/28/02
to
I'm using SQLPlus (on the command line) under Linux.

How can I execute previous commands without re-typing them. Usually under
*nix, I can press the UP Arrow key to toggle previous statements.

Thanks,
Chris


damorgan

unread,
Mar 28, 2002, 11:21:38 AM3/28/02
to
Press the slash key "/" followed by "Enter".

Daniel Morgan

Christophe JAUBERT

unread,
Mar 28, 2002, 4:06:02 PM3/28/02
to
| I'm using SQLPlus (on the command line) under Linux.
|
| How can I execute previous commands without re-typing them. Usually under
| *nix, I can press the UP Arrow key to toggle previous statements.

As it has been said, '/'
And if you want to change something in the buffer, to avoid you to type
again the whole line, just do :

c/old_string/new_string/
and / to re-execute...

...and it's done ! :-)

--
CJ
Marseille, FRANCE

(remove '_nospam' for replying)

R. Ramsey

unread,
Mar 28, 2002, 5:19:35 PM3/28/02
to
"Chris A" <can...@oxspring.com> wrote in message news:<mxEo8.4584$Vm5.34424@NewsReader>...

press the '/' key followed by the 'Enter' key

Pablo Sanchez

unread,
Mar 28, 2002, 6:53:53 PM3/28/02
to

"damorgan" <damo...@exesolutions.com> wrote in message
news:3CA34315...@exesolutions.com...

> Press the slash key "/" followed by "Enter".
>

If you know emacs, run it within an emacs shell and you can ESC-p/n to
walk up and down the history tree. Very cool.
--
Pablo Sanchez, High-Performance Database Engineering
www.hpdbe.com
Available for short-term and long-term contracts


Galen Boyer

unread,
Mar 29, 2002, 11:30:12 PM3/29/02
to
On Thu, 28 Mar 2002, pa...@dev.null wrote:
>
> "damorgan" <damo...@exesolutions.com> wrote in message
> news:3CA34315...@exesolutions.com...
>> Press the slash key "/" followed by "Enter".
>>
>
> If you know emacs, run it within an emacs shell and you can ESC-p/n to
> walk up and down the history tree. Very cool.

sql.el is sqlplus piggybacking on the shell mode. Comes with the main
Emacs distribution.

Has all the shell mode power you are alluding to along with some
particulars for sql. One of them being able to put a buffer in sql-mode
and typing C-c C-r to send region. I stay in the sqlplus buffer mainly
cause the editing of that buffer is great. I code sql in another
buffer, hop to the sqlplus buffer, hit xf for explain, then x to run the
explain file. Once the plan looks good, I M-p M-p to get the previous
code back and execute it.

In the spirit of Emacs sharing, here are my abbreviations enabled for
sql modes. These sure do make the "all-the-time" SQL much less time
consuming.

(define-abbrev sql-mode-abbrev-table "ss" "select * from" nil)
(define-abbrev sql-mode-abbrev-table "sc" "select count(*) from" nil)
(define-abbrev sql-mode-abbrev-table "scd" "select count(distinct" nil)
(define-abbrev sql-mode-abbrev-table "sd" "select distinct" nil)
(define-abbrev sql-mode-abbrev-table "d" "desc" nil)
(define-abbrev sql-mode-abbrev-table "c" "count(*)" nil)
(define-abbrev sql-mode-abbrev-table "s" "select" nil)
(define-abbrev sql-mode-abbrev-table "f" "from" nil)
(define-abbrev sql-mode-abbrev-table "g" "group by" nil)
(define-abbrev sql-mode-abbrev-table "o" "order by" nil)
(define-abbrev sql-mode-abbrev-table "w" "where" nil)
(define-abbrev sql-mode-abbrev-table "tt" "truncate table" nil)
(define-abbrev sql-mode-abbrev-table "ct" "create table" nil)
(define-abbrev sql-mode-abbrev-table "ii" "insert into" nil)
(define-abbrev sql-mode-abbrev-table "ei" "execute immediate" nil)

(require 'tempo)

;; Dynamically build "select blah,count(*) from tbl group by blah;"
(tempo-define-template
"select-count-group-by" ;; template name
'((p "Table Selected From: " tsf 'NOINSERT)
(p "Fields To Group On: " fgo 'NOINSERT)
"SELECT "
(s fgo)
",count(*) " n>
"from "
(s tsf) n>
" group by "
(s fgo)
";"))

(define-abbrev sql-mode-abbrev-table "scg" "" 'tempo-template-select-count-group-by)

(define-abbrev sql-mode-abbrev-table "xf" "explain plan for" nil)
(define-abbrev sql-mode-abbrev-table "x" "@explain" nil)

(define-abbrev sql-mode-abbrev-table "do" "dbms_output.put_line()" nil)

(define-abbrev sql-mode-abbrev-table "ash" "alter session set HASH_AREA_SIZE=" nil)
(define-abbrev sql-mode-abbrev-table "ass" "alter session set SORT_AREA_SIZE=" nil)
(define-abbrev sql-mode-abbrev-table "ast" "alter session set timed_statistics=;" nil)
(define-abbrev sql-mode-abbrev-table "asst" "alter session set sql_trace=")
(define-abbrev sql-mode-abbrev-table "asev" "alter session set events '10046 trace name context forever, level 12';")

(define-abbrev sql-mode-abbrev-table "sl" "set linesize")
(define-abbrev sql-mode-abbrev-table "st" "set timing")

--
Galen deForest Boyer
Sweet dreams and flying machines in pieces on the ground.

Avi Abrami

unread,
Mar 31, 2002, 12:36:55 AM3/31/02
to

Hi Chris,
If I understand you correctly, then you want to be able to recall
any and all of your previously entered SQL statements from within
an SQL*Plus seesion, correct?

As far as I know, it is only possible to recall the last entered
SQL statement since SQL*Plus only has a single buffer that only
holds the last entered SQL statement. I have seen this behaviour
on Solaris, HP-UX and AIX.

There may be different behaviour on platforms other than these,
I don't know.

The other responders have indicated to you how to recall the last
entered SQL statement (from within SQL*Plus). What they failed to
mention was:

1. type "l" (the letter "ell") to display the last entered SQL
statement

2. type "edit" to start up the default editor to enable editing
of the last entered SQL statement.

All of this is explained in the SQL*Plus Users Guide which is
available from:

http://technet.oracle.com

Good Luck,
Avi.

0 new messages