Skip to content
This repository has been archived by the owner on Apr 5, 2019. It is now read-only.

Executing Statements

Alexandru Tica edited this page Feb 5, 2014 · 6 revisions

The most common way to execute a statement is from an SQL buffer. The default key for running statements in Vorax is <Leader>e. "e" stands for Execute.

Let's suppose you have the following commands loaded into an SQL buffer:

set serveroutput on
begin
  dbms_output.put_line('Test');
end;
/
select 'Abc' from dual;

You have the following options to run each of the above statements:

  • move the cursor on the statement you want to execute and press <Leader>e. Vorax will try to automatically figure out what is the statement under cursor, regardless it's an SQL command, a PLSQL statement or a SQLPLUS command.
  • visual select the statement(s) to be executed and run the selection with the same <Leader>e mapping.
  • if you want to execute the entire SQL buffer you may also use the VORAXExecBuffer command or the <Leader>be or @ key mapping. be stands for Buffer Exec.

Note: The default mapping, of course, is configurable.

If you need to quickly run some queries, you may also use the "Scratch" SQL buffer Vorax provides. The keymap is <Leader>ss which stands for "Sql Scratch". When you finish, it's up to you if you save this buffer or not, but if you do, it is saved by default in g:vorax_homedir folder. You may open as many SQL scratch buffers as you want.

In addition, you may use:

:VORAXExec <command>

This last method may prove to be convenient when you don't want to open a SQL buffer.

If the statement to be executed contains substitution variables then you will be requested to enter the values for them. As soon as the "prompt" message is displayed into the output window, you have to press <Enter> to let Vorax know that a substitution variable value needs to be provided. This happens into a special input field, at the bottom of the Vim window.

If the running command is taking too long to complete you may cancel it using the default <Esc> mapping. How the statement is cancelled is depending on the OS under which Vorax is running:

  • on UNIX flavors, an INT signal is sent to the "slave" SQLPLUS process. This is like a <C-c> in the terminal window. From this point is up to the SQLPLUS process to tell the server to cancel the query. Vorax will simply wait for a confirmation that the statement was successfully cancelled. During this time, Vorax will display Cancelling... Press "K" to abort the session. Some statements needs a lot of time to be cancelled, especially because of the involved UNDO data which has to be applied during the rollback phase. Others, even they don't change data, involves other obscure complex cancellation tasks which take time. So, if you want to simply abort the session, you may press "K" and the SQLPLUS process will be killed. The session on the server might still be running until, eventually, the server will figure out that there's no client on the other end of the "wire".
  • on WINDOWS, a running statement cannot be cancelled without killing the SQLPLUS process. This is a bug/limitation of the SQLPLUS on Windows. As soon as Oracle will fix Bug 8890996: ENH: CONTROL-C SHOULD NOT EXIT WINDOWS CONSOLE SQLPLUS, Vorax will be able to handle more nicely the cancel operation on this platform. So, on Windows, when the user asks for a cancellation of a running statement, by default, Vorax will display a warning message and it will ask the user to confirm that he really want to abort his session. If the g:vorax_auto_connect variable is 1, then Vorax will automatically reconnect using the last credentials used in the VORAXConnect command.

Another way of executing statements in Vorax is using the "sandbox" mode. This usually applies to external SQL scripts. Have you ever executed such a script which messed up your Sqlplus environment because it had all sort of weird options set which weren't reset to their original values at the end of the script? Well, that's something I really don't like, so Vorax provides the "sandbox" mode in which, just before starting the script to be run, all current Sqlplus options are saved and, as soon as the script finishes, they are restored as they were before. You may run a command/script in "sandbox" mode using the default key mapping <Leader>E.

Talking about scripts, did you know Vorax integrates nice with NERDTree? You can navigate to the SQL script you want to execute and press @, directly in the file explorer provided by NERDTree. This functionality applies to any SQL script or any file with an extension specified in g:vorax_plsql_associations variable. All scripts run via NERDTree are executed using the "sandbox" mode.