SQL*Plus Tricks Vol 2

sqlplus

In my post “SQL*Plus Tricks Vol 1” I mentioned the feature to edit your last SQL command using your preferred editor.

Here is another possibility.

Trick 5

(see trick 1 to 4 in my previous post “SQL*Plus Tricks Vol 1“)

You can modify a specific line in your last sql command without using an editor.

SQL> l
  1  select file#, status, bytes/1024/1024 mb
  2  from v$datafile
  3* order by bytes
SQL> 2
  2* from v$datafile
SQL> c /datafile/datafile_header/
  2* from v$datafile_header
SQL> l
  1  select file#, status, bytes/1024/1024 mb
  2  from v$datafile_header
  3* order by bytes
SQL> r
  1  select file#, status, bytes/1024/1024 mb
  2  from v$datafile_header
  3* order by bytes
     FILE# STATUS   MB
---------- ------- ----------
         6 ONLINE     5
         9 ONLINE 11,25
        53 ONLINE 36,25
[...]

OK, let’s have a look at this output.

Step by Step:

SQL> l
  1  select file#, status, bytes/1024/1024 mb
  2  from v$datafile
  3* order by bytes

“l” prints the SQL command which is currently in the buffer. You can see the “” next to line 3. This “” is important because it highlights the current line. The current line is always the last line. You will see this in the next step.

SQL> 2
  2* from v$datafile

I changed the current line to line 2.

SQL> c /datafile/datafile_header/
  2* from v$datafile_header

“c” is the command to search and replace a string in the current line.

The syntax is: c /<search pattern>/<replace with>/

Afterwards I simply list (“l”) the sql before I run it with shortcut “r”.

That’s IT.

Advertisements

One thought on “SQL*Plus Tricks Vol 2

Add yours

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: