JBSql  1.0

A freeware enhanced Oracle SQL*Plus© replacement.

Created by Jorgen Bosman 2001-2002

 

 

1 Introduction

 

This program is for those of you who like the command-line interface of Oracle's SQL*Plus©,

but are tired of the limited screen output and editing capabilities.

 

This program is intended to keep the familiar command-line interface for rapid typing of

sql statements, but allows you to get a better query result overview and have better

text editing and command history capabilities.

 

This program is intended to be largely compatible with Oracle's SQL*Plus©, but not all

features have been implemented yet, and some may never be implemented...

 

Please check my website regularly for newer versions, because it's under constant development.

You can also contact me if you want to be notified when I upload a new version.

 

2 Installation

 

Installation is very easy, just extract jbsql.exe from the zip file and place it anywhere you want to.

To run it, you need to have the Oracle 8i client (or higher) installed on your pc and your Primary Oracle Home

must be pointing to the Oracle 8i home. Alternatively, you can extract the jbsql.exe to your %ORACLE_HOME%\bin

directory, then you don't have to worry about your Oracle Homes.

 

To start jbsql, just double-click the jbsql.exe file...

 

If you get errors like 'symbol xxx not found in oci32.dll', then you don't have the Oracle 8i home as your primary Oracle home. Use the Oracle Home Selector to change it.

 

If you get "ORA-24315: illegal attribute type" every time you get another Oracle error, then  you don't have the Oracle 8i home as your primary Oracle home. Use the Oracle Home Selector to change it.

 

3 Logging on

 

When you start jbsql, you will be prompted to log on to a database:

 

 

Just enter your database user name, password and database and click "OK".

This should be sufficient for most connections.

 

If you want access as SYSDBA or SYSOPER, select it from the dropdown list instead of NORMAL.

(Note that startup, shutdown and recover database is not supported!)

 

Your last 10 usernames and databases are remembered. You can quickly reuse them by selecting them from the drop-down list.

 

You can also quickly access a database that's not in your tnsnames.ora by filling in the hostname:port:SID in the database field.

e.g.: dbserver:1521:ORCL

This method only works for tcp/ip connections.

 

You can also use / as username and nothing as a password to connect using your NT username.

If you leave the database empty, then you are connected to your local database or to the database

where your LOCAL environment/registry variable is pointing to.

 

You can also give the connectstring as a command-line parameter. This way you can create a shortcut to your favourite database.

e.g.: jbsql.exe scott/tiger@dbserver

 

You can also specify an command to run when you are logged in, for example to run a sql script. Just specify the command on the commandline just after the connectstring.

e.g.: jbsql.exe scott/tiger@db @c:\temp\script.sql
or jbsql.exe scott/tiger "select 'Instance '||instance_name||' on host '||host_name instance from v$instance;"

 

4 Commands

 

4.1 Introduction

 

 

You can enter commands at the "SQL>" prompt. Oracle commands should be terminated by a ; or / character.

JBSql commands must not be terminated, but it's no error if they are terminated.

When you execute a query, the query results are displayed at the bottom in a listview. You can resize columns and scroll

through the records.

 

4.1 Oracle commands

 

You can execute all known standard Oracle DML and DDL commands, such as select, update, delete, insert, create, drop, alter ...

For most DDL commands, jbsql will tell you what it's doing and what it has done. All Oracle commands should be terminated with

the ; or / character.

 

For an overview of all sql statements, see http://otn.oracle.com (sql reference)

4.2 JBSql Commands

exec[ute] stored_procedure;

The execute command allows you to execute a stored procedure/function/package. 
This is identical to BEGIN stored_procedure; END;

exit

Quits JBSql

dir
ls

Shows a list of all user objects

r
/

Repeats the previous command

ed[it] [file]

Starts an external editor containing the previous command. Or when you specify a file name, it starts the editor with the specified file.

desc[ribe] object

Shows a description of the specified database object (tables, views, procedures, ...)

show err[or] [object_type object_name]

Shows the PL/SQL errors in the last created/compiled object, or the errors for the specified object.

show par[ameter] name

Shows the initialization parameters that contain name

@script [parameter1] [parameter2] ...

Runs the commands inside the specified sql script. If no extension is given, .sql is assumed.
To specify a script inside a directory that contains spaces, surround the script with " "
e.g.: @"c:\program files\jbsql\tst.sql"
If the scripts accepts parameters (&1, &2, ...), you can specify them after the script name.

@@script [parameter1] [parameter2] ...

Runs the commands inside the specified sql script. If no extension is given, .sql is assumed.
To specify a script inside a directory that contains spaces, surround the script with " "
e.g.: @"c:\program files\jbsql\tst.sql"
If the scripts accepts parameters (&1, &2, ...), you can specify them after the script name.
The double @@ looks for sql scripts inside the same directory as the calling script. So it should be
used from within another script.

spool file|off

Writes all following sql output to the specified file

off, turns off spooling and closes the file.

set option value|on|off [option value|on|off ...]

Gives a value to an option (see Options for a list of options)
You can specify multiple options at once and options may be abbreviated. If the starting characters match exactly one option, then that option is set.
set without parameters shows an overview of current option values

define variable[=value]

Gives a value to a variable. This variable can be used inside scripts by using &variable or &&variable.
If you do not specify =value, then the current value is shown.

undef[ine] variable

Removes the specified variable

acc[ept] variable [num[ber]|char|date] [for[mat] format] [def[ault] default] [prompt text|nopr[ompt]] [hide]

Prompts the user to enter a value for a variable.

Refer to the following list for a description of each term or clause:

variable
NUM[BER]
CHAR
DATE
FOR[MAT]
DEF[AULT]
PROMPT text
NOPR[OMPT]
HIDE

conn[ect] username/password[@database] [as sysdba|sysoper|normal]

Creates a connection to a database with the specified credentials. If you do not specify a password, then you will be prompted for a password. For the database, you can also specify host:port:SID or host:SID or host:port for quick connections to a database.

disc[onnect]

Disconnects the current sessiom from the database. You cannot execute any sql commands anymore until you use the connect command again.

prompt [text]

Prints the given text to the console window.

tune

Puts the last executed command inside the sql analyzer window.

5 Options

5.1 Introduction

You can set various options to control the behaviour of jbsql. Options are persistent, you don't have to enter them again when you start jbsql.

All options can be configured with a dialog box and via the 'set' command.
The dialog box can be opened via the Tools->Options menu.

The list on the left shows all possible options, when you select an option, the current value is displayed on the right hand side, along with a description of the option. For boolean options (true or false), a checkbox is displayed whether or not you want to show this option on the main window's toolbar or not for easy access to this option.

5.2 Overview

allow_newline

If set, pressing Enter inside a sql statement inserts a newline. If not set, then the statement is executed.

arraysize

Specifies how many records are fetched at once. If the amount of memory that's needed to hold the records exeeds the maxmem option, then the arraysize is automatically reduced for the executed statement.

autocomplete

Specifies wheter or not autocomplete should be active when you press TAB.

autotrace

When autotrace is enabled, the execution plan is displayed in the sql analyzer window before each statement is executed and statistics about the statement are displayed after the query in the console.

commandhistory

Specifies how many previous commands are kept in memory.

directory

Specifies the startup directory for jbsql. This makes it easier to type the location of sql scripts, you only have to type the location relative to the startup directory.

editor

Specifies what editor to use with the 'edit' command.

edit_filename

Specifies what filename to create with the 'edit' command

feedback

If set, then a result is shown each time a statement is successfully processed.

heading

Should headings be printed when output to screen is enabled or spooling is on?

listview

Specifies wheter query output should appear in the listview table at the bottom or not.

long

Specifies how many characters are read from LONG, LONG RAW, BLOB, CLOB and BFILE colums.

max_scripts

Specifies the maximum number of nested scripts. This is to prevent recursive scripts.

maxlines

Specifies how many lines are buffered in the console window.

maxmem

Specifies the maximum memory usage for queries, if arraysize*record_size > maxmem then the arraysize is automatically adjusted to fit into the maximum memory usage.

prompt

Specifies the text to use as console prompt.

savehistory

Saves the command history to a file when you exit jbsql and reads them back in when you start jbsql

scan

Scan scripts for & characters, which denotes variables and ask for variable values.

screen

Is output from queries to the console on?

serveroutput

Displays output generated by dbms_output after completion of a sql statement.

sound

Play a sound when long running queries are finished.

soundfile

Specified the sound file to play.

soundtime

Specifies the time (in seconds) after which a sound should be played..

timing

If enabled, displays elapsed time information for each sql statement.

verify

If enabled, displays old and new values for replaced && variables in a script.

6 Extra features

6.1 Command recall

You can press 'arrow up' inside the console to get the previous commands back. You can use 'arrow down' to scroll between the previous commands. The previous commands are also persistent between jbsql sessions if the 'savehistory' option is enabled.

6.2 Inline editing

While you are typing a command of when you have recalled a command, you can use the 'arrow left', 'arrow right', 'home','end', 'Page Up and 'Page down' key to navigate the cursor to another position. When you're not at the end of a command and you have a multi-line command, then you can also use the 'arrow up' and 'arrow down' key to navigate to a previous line or next line inside the command.

'Home' moves the cursor to the beginning of the current line of the current command.
'End' moves the cursor to the end of the current line of the current command.
'Page Up' moves the cursor to the beginning of the command.
'Page Down' moves the cursor to the end of the command.
'Ctrl-Left' moves the cursor to the start of the previous word.
'Ctrl-Right' moves the cursor to the start of the next word.

When you're inside a command, you can insert text or use the 'del' and 'backspace' key to delete text.

When the 'allow_newline' option is on, then you can insert a new line inside the command by pressing the 'enter' key. The command is only executed when the cursor at the end of the command.

When the 'allow_newline' option is off, then pressing 'enter' will always execute the command, no matter where the cursor is. You can insert a new line in the command by pressing 'Shift-Enter'.

You can also position the cursor by clicking with the mouse at the desired position inside the current command.

6.3 Autocompletion

When you are typing a sql statement, you can press the 'tab' key to find a list of closest matches to the word that you are typing. If more that one match is found, a popup list is displayed with all possible choices. If only one match is found, then the word is automatically completed without bringing up the popup list.

The autocompletion is context sensitive, this means that is knows for example that after the 'from' word, it is likely that you want to type a table name or a view name, so it searches a list of table and view names. It does not do complete sql parsing, so it does not correlate column names after the 'where' word with table names after the 'from' word unless you give those tables an alias and also specify the alias after the where keyword. Just try it out and see what happens, most of the time, the correct list is shown, but sometimes it may not be what you expect.

Autocomplete also works for specifying script names after the @ command. It completes directory and file names.

6.4 Mouse

JBSql has got (just like SQL*Plus), rectangular selection. This means that you can select text inside the console, not line by line, but in a rectangular fashion. It also has the same quick-paste feature as SQL*Plus. This means that when you press the right mouse button after you have selected a piece of text and also while the left button is still down, the selected text is pasted at the current cursor location.

6.5 Copy-Paste

You can copy selected text from the console using Ctrl-C or Ctrl-Insert and paste text inside the console window by using Ctrl-V, or Shift-Insert.

6.6 Quick Exit

You can quickly exit jbsql by pressing Ctrl-D

6.7 Interruptable statements

You can cancel a running statement by pressinc Ctrl-X or selecting 'Cancel' from the Query menu. It may take a while before the statement is cancelled.

6.8 Multithreading

While a statement is executing, the rest of the application still responds to user input. For example, you can still select text or change an option while a query is executing. The same yields while the 'edit' command is running or when a script is running.

6.9 User friendly feedback

For most sql statements, jbsql will tell you what it's doing: parsing, executing, fetching, ...

For most create/alter statements, it will tell you which table/index/... it is creating and has created. This is most useful in scripts that contain many create/alter or drop statements. This way you can easily track errors in your scripts.

7 SQL Analyzer

The SQL Analyzer helps you to tune your sql statements. At the top, you can enter your sql statement.

If autotrace is on or if you enter the tune command, the last executed command is put at the top.

The hint listbox contains most known hints. When you select a hint from the list, a short explaination is displayed at the bottom.

Depending on the hint, the table and index list is displayed. From these lists, you can select the table name(s) and index name(s). When you have selected a hint/table/index, the sql statement is updated with the new hint. Some hints require one or more table names as parameter and some hints also require one or more index names. Remember that if you have table aliases in your sql statement, then you have to use the same aliases in your hint instead of the table name.

When you press the 'Explain plan' button, the sql statement is analyzed and the execution plan is displayed in the tree in the middle. Remember that if there's a syntax error inside the hint, Oracle doesn't complain about it.

When you press the 'Execute' button, the sql statement is copied to the console and the statement is executed. This way you can see how fast the statement executes.

8 Schema Browser

With this tool, you can see the DDL create statements for most database objects.

The top three listboxes let you choose the database object. First select the desired schema name, then the object type and then the object name. When you change the schema, the other listboxes are updated with data from the chosen schema. When you change the object type, the object name list is updated with all the object names from the chosen schema and objec type. When you have selected an object name, the DDL create statement is shown in the text window below. When you have selected a table, then it also shows the DDL create statement for the indexes and constraints on that table.

9 Export

You can export the currently selected data to a file. This feature is available from the file menu.

9.1 CSV format

When you export to CSV (Comma Separated Values) format, the delimiter is a ; character and all fields are enclosed by a " character. If there is a " inside the exported data, then to consecutive " characters are put in the csv file. All fields are exported as text and as they are shown in the list view.

9.2 XML format

You can also export the selected data to a XML file. The format of the xml file is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<ROWS>
  <ROW num="1">
    <COLUMN1>value1</COLUMN1>
    <COLUMN2>value2</COLUMN2>
    ...
  </ROW>
  ...
</ROWS>

9.3 SQL format

You can also export the selected data as a SQL insert script. This will generate sql insert statements for each row. This generated script may not always work, for example if you have a complex query. It will probably work best if you have just done select * from some_table;

10 Change history

V1.1.0.0 27/05/2003:

V1.0.2.8 27/05/2003:

V1.0.2.7 26/05/2003:

V1.0.2.6 01/03/2003:

V1.0.2.5 30/01/2003:

V1.0.2.4 27/01/2003:

V1.0.2.3 13/01/2003:

V1.0.2.2 28/11/2002:

V1.0.2.1 24/09/2002:

V1.0.2.0 22/09/2002:

V1.0.1.5 17/09/2002:

V1.0.1.4 30/07/2002:

V1.0.1.3 13/05/2002:

V1.0.1.2 02/05/2002:

V1.0.1.1 02/05/2002:

V1.0.1.0 01/05/2002:

V1.0.0.6 25/04/2002:

V1.0.0.5 17/04/2002:

V1.0.0.4 04/03/2002:

V1.0.0.3 23/02/2002:

V1.0.0.2 19/02/2002:

V1.0.0.1 07/02/2002:

V1.0.0.0 28/01/2002:

22/01/2002:

20/01/2002:

16/01/2002:

10/01/2002:

02/01/2002:

11/06/2001:

07/06/2001:

08/05/2001:

03/05/2001:

01/05/2001:

10 Contact

You can contact me for any questions, bugs, enhancement requests, congratulations, postcards… at the following coordinates:
If you want to thank me, please have a look at my goodies whishlist!

jorgen.bosman@pandora.be (home)
jbosma@ferranti.be (work)

Home address:
Jorgen Bosman
Groot Hagelkruis 179F
2030 Antwerpen
Belgium


You can always find the latest version (and other tools) at:
http://users.pandora.be/jbosman/applications.html

The direct download link for jbsql is:
http://users.pandora.be/jbosman/jbsql.zip

This is Freeware!