This section provides reference material for statements specific to ISQL.
This section does not include descriptions of standard FairCom DB SQL statements or statements specific to embedded c-tree SQL. For details on the syntax and semantics of those other FairCom DB SQL statements, refer to the FairCom DB SQL Reference Manual.
@ (Execute)
Syntax
@filename
Description
Executes the SQL statements stored in the specified SQL script file. The statements specified in the file are not added to the history buffer.
Arguments
filename
The name of the script file.
Notes
The GET, START, and @ (execute) statements are similar in that they all read SQL script files. Both GET and START read an SQL script file and append the first statement in it to the history buffer. However, the START statement also executes the script statement and accepts arguments that it substitutes for parameter references in the script statement. The @ (execute) statement, on the other hand, executes all the statements in an SQL script file but does not add any of the statements to the history buffer. The @ statement does not support argument substitution.
Example
The following example shows a simple ISQL script file.
Example ISQL script
connect to demodb;
set echo on ;
create table stores (item_no integer, item_name char(20));
insert into stores values (1001,chassis);
insert into stores values (1002,chips);
select * from stores where item_no > 1001;
set echo off ;
To execute the above statements stored in the file cmdfile, enter:
ISQL> @cmdfile
BREAK
Syntax
BREAK [ ON break_spec [ SKIP n ] ] ;
break_spec::
{ column_name [ , ... ] | ROW | PAGE | REPORT }
Description
The BREAK statement specifies at what point ISQL processes associated DISPLAY and COMPUTE statements. DISPLAY and COMPUTE statements have no effect until you issue a BREAK statement with the same break specification.
A break can be specified on any of the following events:
- Change in the value of a column
- Selection of each row
- End of a page
- End of a report
Only one BREAK statement can be in effect at a time. When a new BREAK statement is entered, it replaces the previous BREAK statement. The BREAK statement can specify one or more columns on which the break can occur.
The BREAK statement without any clauses displays the currently-set break, if any.
Arguments
break_spec
The events that cause an SQL query to be interrupted and the execution of the associated COMPUTE and DISPLAY statements. break_spec can be any of the following values:
| column_name | Causes a break when the value of the column specified by column_name changes. |
| ROW | Causes a break on every row selected by a SELECT statement. |
| PAGE | Causes a break at the end of each page. The end of a page is specified in the SET PAGESIZE statement. See “SET” for details on the SET statement. |
| REPORT | Causes a break at the end of a report or query. |
SKIP n
The optional SKIP clause can be used to skip the specified number of lines when the specified break occurs and before processing of any associated DISPLAY statements.
Examples
The following examples illustrate how various break settings and corresponding DISPLAY statements affect the display of the same query.
ISQL> break
no break specified
ISQL> select customer_name from customers; -- Default display
CUSTOMER_NAME
-------------
Sports Cars Inc.
Mighty Bulldozer Inc.
Ship Shapers Inc.
Tower Construction Inc.
Chemical Construction Inc.
Aerospace Enterprises Inc.
Medical Enterprises Inc.
Rail Builders Inc.
Luxury Cars Inc.
Office Furniture Inc.
10 records selected
ISQL> -- Set DISPLAY values for different breaks:
ISQL> display "Break on change in value of customer_name!" on customer_name;
ISQL> display "Break on every row!" on row;
ISQL> display "Break on page (page size set to 2 lines)" on page;
ISQL> display "Break on end of report!" on report;
ISQL> set pagesize 2
ISQL> break on customer_name
ISQL> select customer_name from customers;
CUSTOMER_NAME
-------------
Sports Cars Inc.
Break on change in value of customer_name!
Mighty Bulldozer Inc.
Break on change in value of customer_name!
Ship Shapers Inc.
Break on change in value of customer_name!
.
.
.
ISQL> break on row
ISQL> select customer_name from customers;
CUSTOMER_NAME
-------------
Sports Cars Inc.
Break on every row!
Mighty Bulldozer Inc.
Break on every row!
Ship Shapers Inc.
Break on every row!
.
.
.
ISQL> break on page
ISQL> select customer_name from customers;
CUSTOMER_NAME
-------------
Break on page (page size set to 2 lines)
CUSTOMER_NAME
-------------
Sports Cars Inc.
Break on page (page size set to 2 lines)
CUSTOMER_NAME
-------------
Mighty Bulldozer Inc.
Break on page (page size set to 2 lines)
.
.
.
ISQL> break on report
ISQL> select customer_name from customers;
CUSTOMER_NAME
-------------
Sports Cars Inc.
Mighty Bulldozer Inc.
Ship Shapers Inc.
Tower Construction Inc.
Chemical Construction Inc.
Aerospace Enterprises Inc.
Medical Enterprises Inc.
Rail Builders Inc.
Luxury Cars Inc.
Office Furniture Inc.
Break on end of report!
10 records selected
ISQL>
CLEAR
Syntax
CLEAR option ;
option::
HISTORY
| BREAK
| COLUMN
| COMPUTE
| DISPLAY
| TITLE
Description
The CLEAR statement removes settings made by the ISQL statement corresponding to option.
Argument
option
Which ISQL statement’s settings to clear:
- CLEAR HISTORY - Clears the ISQL statement history buffer.
- CLEAR BREAK - Clears the break set by the BREAK statement.
- CLEAR COLUMN - Clears formatting options set by any COLUMN statements in effect.
- CLEAR COMPUTE - Clears all the options set by the COMPUTE statement.
- CLEAR DISPLAY - Clears the displays set by the DISPLAY statement.
- CLEAR TITLE - Clears the titles set by the TITLE statement.
Examples
The following example illustrates clearing the DISPLAY and BREAK settings.
ISQL> DISPLAY -- See the DISPLAY settings currently in effect:
display "Break on change in value of customeer_name!" on customer_name
display "Break on every row!" on row
display "Break on page (page size set to 2 lines)" on page
display "Break on end of report!" on report
ISQL> CLEAR DISPLAY
ISQL> DISPLAY
No display specified.
ISQL> BREAK
break on report skip 0
ISQL> CLEAR BREAK
ISQL> BREAK
no break specified
ISQL>
COLUMN
Syntax
COLUMN [ column_name
[ FORMAT " format_string " ] | [ HEADING " heading_text " ] ] ;
Description
The COLUMN statement controls how ISQL displays a column’s values (the FORMAT clause) and specifies alternative column-heading text (the HEADING clause).
The COLUMN statement without any arguments displays the current column specifications.
Arguments
column_name
The name of the column affected by the COLUMN statement. If the COLUMN statement includes column_name but omits both the FORMAT and HEADING clauses, ISQL clears any formatting and headings in effect for that column. The formatting specified for column_name also applies to DISPLAY statements that specify the same column.
FORMAT " format_string "
Specifies a quoted string that formats the display of column values. Valid values for format strings depend on the data type of the column.
| Character | The only valid format string for character data types is of the form “An”, where n specifies the width of the column display. The A character must be upper case. |
| Numeric | Table: Numeric Format Strings for the COLUMN Statement on page 3-18 shows valid format strings for numeric data types. |
| Date-time | Table: Date-Time Format Strings for the COLUMN Statement on page 3-18 shows valid format strings for date-time data types. The format strings consist of keywords that SQL interprets and replaces with formatted values. Any other character in the format string are displayed as literals. The format strings are case sensitive. For instance, SQL replaces ‘DAY’ with all uppercase letters, but follows the case of ‘Day’. Note that the SQL scalar function TO_CHAR offers comparable functionality and is not limited to SQL statements issued within ISQL. See the c-treeSQL Reference Manual for details on TO_CHAR. |
COLUMN format strings also affect display values in DISPLAY statements that specify the same column or a COMPUTE value based on the column.
HEADING “heading_text ”
Specifies an alternative heading for the column display. The default is the column name.
Format String Details
Numeric Format Strings for the COLUMN Statement
| Character | Example | Description |
|---|---|---|
| 9 | 99999 | Number of 9s specifies width. If the column value is too large to display in the specified format, ISQL displays # characters in place of the value. |
| 0 | 09999 | Display leading zeroes. |
| $ | $9999 | Prefix the display with ‘$’. |
| B | B9999 | Display blanks if the value is zero. |
| , | 99,999 | Display a comma at position specified by the comma. |
| . | 99,999.99 | Display a decimal point at the specified position. |
| MI | 99999MI | Display ‘-’ after a negative value. |
| PR | 99999PR | Display negative values between ‘<’ and ‘>’. |
Date-Time Format Strings for the COLUMN Statement
| Character | Description |
|---|---|
| CC | The century as a 2-digit number. |
| YYYY | The year as a 4-digit number. |
| YYY | The last 3 digits of the year. |
| YY | The last 2 digits of the year. |
| Y | The last digit of the year. |
| Y,YYY | The year as a 4-digit number with a comma after the first digit. |
| Q | The quarter of the year as 1-digit number (with values 1, 2, 3, or 4). |
| MM | The month value as 2-digit number (in the range 01-12). |
| MONTH | The name of the month as a string of 9 characters (‘JANUARY’ to ‘DECEMBER ’) |
| MON | The first 3 characters of the name of the month (in the range ‘JAN’ to ‘DEC’). |
| WW | The week of year as a 2-digit number (in the range 01-52). |
| W | The week of month as a 1-digit number (in the range 1-5). |
| DDD | The day of year as a 3-digit number (in the range 001-365). |
| DD | The day of month as a 2-digit number (in the range 01-31). |
| D | The day of week as a 1-digit number (in the range 1-7, 1 for Sunday and 7 for Saturday). |
| DAY | The day of week as a 9 character string (in the range ‘SUNDAY’ to ‘SATURDAY’. |
| DY | The day of week as a 3 character string (in the range ‘SUN’ to ‘SAT’). |
| J | The Julian day (number of days since DEC 31, 1899) as an 8 digit number. |
| TH | When added to a format keyword that results in a number, this format keyword (‘TH’) is replaced by the string ‘ST’, ‘ND’, ‘RD’ or ‘TH’ depending on the last digit of the number. |
| AMPM | The string ‘AM’ or ‘PM’ depending on whether time corresponds to forenoon or afternoon. |
| A.M.P.M. | The string ‘A.M.’ or ‘P.M.’ depending on whether time corresponds to forenoon or afternoon. |
| HH12 | The hour value as a 2-digit number (in the range 00 to 11). |
| HHHH24 | The hour value as a 2-digit number (in the range 00 to 23). |
| MI | The minute value as a 2-digit number (in the range 00 to 59). |
| SS | The seconds value as a 2-digit number (in the range 00 to 59). |
| SSSSS | The seconds from midnight as a 5-digit number (in the range 00000 to 86399). |
| MLS | The milliseconds value as a 3-digit number (in the range 000 to 999). |
Examples
The following examples are based on a table, ORDERS, with columns defined as follows:
ISQL> table orders
COLNAME NULL ? TYPE LENGTH
------- ------ ---- ------
order_id NOT NULL INT 4
customer_id INT 4
steel_type CHAR 20
order_info CHAR 200
order_weight INT 4
order_value INT 4
order_state CHAR 20
ISQL displays the order_info column, at 200 characters, with lots of blank space preceding the values:
ISQL> select order_info from orders where order_value < 1000000
ORDER_INFO
----------
Solid Rods 5 in. diameter
1 record selected
You can improve formatting by using the character format string to limit the width of the display:
ISQL> column ORDER_INFO format "A28" heading "Details"
ISQL> select order_info from orders where order_value < 1000000;
ORDER_INFO
----------
Solid Rods 5 in. diameter
1 record selected
ISQL> -- Illustrate some options with numeric format strings.
ISQL> -- No column formatting:
ISQL> select order_value from orders where order_value < 1000000;
ORDER_VALUE
-----------
110000
1 record selected
ISQL> -- Format to display as money, and use different heading:
ISQL> column order_value format "$999,999,999.99" heading "Amount"
ISQL> select order_value from orders where order_value < 1000000;
AMOUNT
------
$110,000.00
1 record selected
The following examples use the single-value system table, SYSCALCTABLE, and the sysdate scalar function, to illustrate some date-time formatting. The sysdate function returns today’s date.
ISQL> select sysdate from syscalctable; -- No formatting
SYSDATE
-------
05/07/1998
ISQL> column sysdate format "Day"
ISQL> select sysdate from syscalctable
SYSDATE
-------
Thursday
1 record selected
ISQL> column sysdate format "Month"
ISQL> select sysdate from syscalctable
SYSDATE
-------
May
1 record selected
ISQL> column sysdate format "DDth"
ISQL> select sysdate from syscalctable
SYSDATE
-------
7th
1 record selected
Note: If the select-list of a query includes column titles, they override formatting specified in COLUMN statements for those columns. The following example illustrates this behavior.
ISQL> select fld from syscalctable; -- No formatting
FLD
---
100
1 record selected
ISQL> column fld heading "column title" -- Specify heading in COLUMN statement
ISQL> select fld from syscalctable;
COLUMN TITLE
------------
100
1 record selected
ISQL> select fld "new title" from syscalctable; -- Specify title in select list
NEW TITLE
---------
100
1 record selected
COMPUTE
Syntax
COMPUTE
[ { AVG | MAX | MIN | SUM | COUNT }
OF column_name
IN variable_name
ON break_spec ] ;
break_spec::
{ column_name | ROW | PAGE | REPORT }
Description
Performs aggregate function computations on column values for the specified set of rows, and assigns the results to a variable. DISPLAY statements can then refer to the variable to display its value.
COMPUTE statements have no effect until you issue a BREAK statement with the same break_spec.
Issuing the COMPUTE statement without any arguments displays the currently-set COMPUTE specifications, if any.
Arguments
AVG | MAX | MIN | SUM | COUNT
The function to apply to values of column_name. The functions AVG, MAX, MIN, and SUM can be used only when the column is numeric. The function COUNT can be used for any column type.
column_name
The column whose value is to be computed. The column specified in column_name must also be included in the select list of the query. If column_name is not also included in the select list, it has no effect.
variable_name
Specifies the name of the variable where the computed value is stored. ISQL issues an implicit DEFINE statement for variable_name and assigns the variable a value of zero. During query processing, the value of variable_name changes as ISQL encounters the specified breaks.
break_spec
Specifies the set of rows after which ISQL processes the COMPUTE statement. A COMPUTE statement has no effect until you issue a corresponding BREAK statement. See the description of the BREAK statement in "BREAK" for details.
Examples
The following example computes the number of items ordered by each customer.
ISQL> break on customer_name
ISQL> display col 5 "Number of orders placed by", customer_name, "=", n_ord on customer_name
ISQL> compute count of order_id in n_ord on customer_name;
ISQL> select c.customer_name, o.order_id from customers c, orders o
where o.customer_id = c.customer_id;
CUSTOMER_NAME ORDER_ID
------------- --------
Sports Cars Inc. 1
Sports Cars Inc. 2
Number of orders placed by Sports Cars Inc.
= 2
Mighty Bulldozer Inc. 3
Mighty Bulldozer Inc. 4
Number of orders placed by Mighty Bulldozer Inc.
= 2
.
.
.
DEFINE
Syntax
DEFINE [ variable_name = value ] ;
Description
The DEFINE statement defines a variable and assigns an ASCII string value to it. When you refer to the defined variable in DISPLAY statements, ISQL prints the value.
The DEFINE statement is useful if you have scripts with many DISPLAY statements. You can change a single DEFINE statement to change the value in all of the DISPLAY statements that refer to the variable.
Issuing the DEFINE statement without any arguments displays any currently-defined variables, including those defined through the COMPUTE statement.
Arguments
variable_name
Specifies the name by which the variable can be referred to.
value
The ASCII string that is assigned to the variable. Enclose value in quotes if it contains any non-numeric values.
Example
The following example defines a variable called nestate and assigns the value “NH” to it.
ISQL> DEFINE nestate = "NH" ;
DISPLAY
Syntax
DISPLAY { [ col_position ] display_value } [ , ... ] ON break_spec ;
col_position::
{ COL column_number | @ column_name }
display_value::
{ "text string" | variable | column_name }
break_spec::
{ column_name | ROW | PAGE | REPORT }
Description
The DISPLAY statement displays the specified text, variable value, and/or column value after the set of rows specified by break_spec. DISPLAY statements have no effect until you issue a BREAK statement with the same break_spec.
Issuing the DISPLAY statement without any arguments displays the currently set DISPLAY specifications, if any.
Arguments
col_position
An optional argument that specifies the horizontal positioning of the associated display value. There are two forms for the argument:
| COL column_number | Directly specifies the column position of the display value as an integer(1 specifies column 1, 2 specifies column 2, and so on.). |
| @column_name | Names a column in the select list of the SQL query. ISQL aligns the display value with the specified column. |
If the DISPLAY statement omits col_position, ISQL positions the display value at column 1.
display_value
The value to display when the associated break occurs:
| “text string” | If the display value is a text string, ISQL simply displays the text string. |
| variable | If the display value is a variable, ISQL displays the value of the variable when the associated break occurs. The variable argument refers to a variable named in a COMPUTE or DEFINE statement that executes before the query. If variable is undefined, ISQL ignores it. |
| column_name | If the display value is a column name, ISQL displays the value of the column when the associated break occurs. The column specified in column_name must also be included in the select list of the query. If column_name is not also included in the select list, it has no effect. If a COLUMN statement specifies a format for the same column, the formatting also affects the DISPLAY statement. |
break_spec
Specifies the set of rows after which ISQL processes the DISPLAY statement. A DISPLAY statement has no effect until you issue a corresponding BREAK statement. See the description of the BREAK statement in "BREAK" for details of break specifications.
Examples
The following set of examples compute the number of orders placed by each customer and displays the message Number of orders placed by, followed by the customer name and the count of orders.
ISQL> break on customer_name
ISQL> display col 5 "Number of orders placed by", customer_name, "=", n_ord on customer_name
ISQL> compute count of order_id in n_ord on customer_name;
ISQL> select c.customer_name, o.order_id from customers c, orders o
where o.customer_id = c.customer_id;
CUSTOMER_NAME ORDER_ID
------------- --------
Sports Cars Inc. 1
Sports Cars Inc. 2
Number of orders placed by Sports Cars Inc.
= 2
Mighty Bulldozer Inc. 3
Mighty Bulldozer Inc. 4
Number of orders placed by Mighty Bulldozer Inc.
= 2
Ship Shapers Inc. 5
Ship Shapers Inc. 6
Ship Shapers Inc. 7
Number of orders placed by Ship Shapers Inc.
= 3
Tower Construction Inc. 8
Tower Construction Inc. 9
Tower Construction Inc. 10
Number of orders placed by Tower Construction Inc.
= 3
If the select-list of a query includes column titles, they override DISPLAY statements that include variable or column_name display values for those columns:
ISQL> display col 5 "test display. Sum of fld is", tmp on fld;
ISQL> compute sum of fld in tmp on fld;
ISQL> break on fld
ISQL> select fld from syscalctable; -- This works:
FLD
---
100
test display. Sum of fld is 100
1 record selected
ISQL> select fld "column title" from syscalctable; -- DISPLAY is disabled:
COLUMN TITLE
------------
100
1 record selected
EDIT
Syntax
E[DIT] [stmt_num];
Description
The EDIT statement invokes a text editor to edit the specified statement from the statement history buffer. If the statement number is not specified, the last statement in the history buffer is edited. When you exit the editor, ISQL writes the buffer contents as the last statement in the history buffer.
By default, ISQL invokes the vi editor on UNIX and the MS-DOS editor on Windows. You can change the default by setting the EDITOR environment variable:
- On UNIX, set the environment variable at the operating system command level:
setenv EDITOR /usr/local/bin/gmacs
- On Windows, set the environment variable in the initialization file DHSQL.INI in the (%WINDIR%) directory:
EDITOR = c:\msoffice\winword.exe
Examples
The following example uses the ! (shell) command to show the currently-set value of the EDITOR environment variable in the UNIX environment (it shows that it is set to invoke the GNU emacs editor). Then, the example uses the EDIT command to read in the fifth statement in the history buffer into an editing buffer.
ISQL> ! printenv EDITOR
/usr/local/bin/gmacs
ISQL> EDIT 5;
The following example edits the last statement in the history buffer:
ISQL> select * from systable; -- bad table name!
*
error(-20005): Table/View/Synonym not found
ISQL> EDIT -- invoke an editor to correct the error
.
.
.
ISQL> list -- corrected statement is now the current statement:
select * from systables
ISQL> run -- run the corrected statement
.
.
.
EXIT or QUIT
Syntax
EXIT
Description
The EXIT statement terminates the ISQL session.
Related Statements
QUIT and EXIT are synonymous. There is no difference in their effect.
GET
Syntax
G[ET] filename;
Description
The GET statement reads the first SQL statement stored in the specified script file.
Arguments
filename
The name of the script file. ISQL reads the file until it encounters a semicolon ( ; ) statement terminator. It appends the statement to the history buffer as the most-recent statement.
Notes
- Execute the statement read by GET using the RUN statement.
- The GET, START, and @ (execute) statements are similar in that they all read SQL script files. Both GET and START read an SQL script file and append the first statement in it to the history buffer. However, the START statement also executes the script statement and accepts arguments that it substitutes for parameter references in the script statement. The @ (execute) statement, on the other hand, executes all the statements in an SQL script file but does not add any of the statements to the history buffer. The @ statement does not support argument substitution.
Example
Once you refine a query to return the results you need, you can store it in an SQL script file. For example, the file query.sql contains a complex query that joins several tables in a sample database.
Use the GET and RUN statements to read and execute the first statement in query.sql:
ISQL> GET query.sql
SELECT customers.customer_name,
orders.order_info,
orders.order_state,
lot_staging.lot_location,
lot_staging.start_date
FROM customers,
orders,
lots,
lot_staging
WHERE ( customers.customer_id = orders.customer_id ) and
( lots.lot_id = lot_staging.lot_id ) and
( orders.order_id = lots.order_id ) and
( ( customers.customer_name = 'Ship Shapers Inc.' ) AND
( lot_staging.start_date is not NULL ) AND
( lot_staging.end_date is NULL ) )
ISQL> RUN
SELECT customers.customer_name,
orders.order_info,
orders.order_state,
lot_staging.lot_location,
lot_staging.start_date
FROM customers,
orders,
lots,
lot_staging
WHERE ( customers.customer_id = orders.customer_id ) and
( lots.lot_id = lot_staging.lot_id ) and
( orders.order_id = lots.order_id ) and
( ( customers.customer_name = 'Ship Shapers Inc.' ) AND
( lot_staging.start_date is not NULL ) AND
( lot_staging.end_date is NULL ) )
CUSTOMER_NAME ORDER_INFO
------------- ----------
ORDER_STATE LOT_LOCATION START_DATE
----------- ------------ ----------
Ship Shapers Inc. I Beams Size 10
Processing Hot Rolling 12/26/1994
1 record selected
HELP
Syntax
HE[LP] {COMMANDS|CLAUSES};
HE[LP] ;
Description
The HELP statement displays the help information for the specified statement or clause.
Notes
- HELP COMMANDS displays a list of statements for which help text is available.
- HELP CLAUSES display a list of clauses for which help text is available.
- HELP statement with no clauses display the help text for the HELP statement.
Example
The following HELP statement will give a brief description of the SELECT statement.
ISQL> HELP SELECT;
HISTORY
Syntax
HI[STORY];
Description
The HISTORY statement lists the statements in the statement history buffer, along with an identifying number.
Notes
- ISQL maintains a list of statements typed by the user in the statement history buffer. The SET HISTORY statement sets the size of the history buffer.
- The statements LIST, EDIT, HISTORY, and RUN are not added to the history buffer.
- Use HISTORY to obtain the statement number for a particular statement in the history buffer that you want to execute. Then, use the RUN statement with the statement number as an argument to execute that statement. Or, use LIST statement with the statement number as an argument to make the statement the current statement, which can then be executed using RUN without an argument.
Example
The following example illustrates usage of the HISTORY statement.
ISQL> HISTORY -- Display statements in the history buffer
1 start start_ex.sql Ship
2 SELECT customer_name FROM customers
WHERE customer_name LIKE 'Ship%'
3 select tbl from systables where tbltype = 'T'
ISQL> RUN 2 -- Run the query corresponding to statement 2
SELECT customer_name FROM customers
WHERE customer_name LIKE 'Ship%'
CUSTOMER_NAME
-------------
Ship Shapers Inc.
1 record selected
ISQL> HI -- In addition to executing, statement 2 is now the current statement
1 start start_ex.sql Ship
2 SELECT customer_name FROM customers
WHERE customer_name LIKE 'Ship%'
3 select tbl from systables where tbltype = 'T'
4 SELECT customer_name FROM customers
WHERE customer_name LIKE 'Ship%'
ISQL> LIST 3 - Display statement 3 and copy it to the end of the history list
select tbl from systables where tbltype = 'T'
ISQL> history -- Statement 3 is now also the current statement
1 start start_ex.sql Ship
2 SELECT customer_name FROM customers
WHERE customer_name LIKE 'Ship%'
3 select tbl from systables where tbltype = 'T'
4 SELECT customer_name FROM customers
WHERE customer_name LIKE 'Ship%'
5 select tbl from systables where tbltype = 'T'
HOST or SH or !
Syntax
{ HOST | SH | ! } [host_command];
Description
The HOST (or SH or !) statement executes a host operating system command without terminating the current ISQL session.
Arguments
host_command
The operating system command to execute. If host_command is not specified, ISQL spawns a sub-shell from which you can issue multiple operating system commands. Use the exit command to return to the ISQL> prompt.
Example
Consider a file in the local directory named query.sql. It contains a complex query that joins several tables in a sample database. From within ISQL You can display the contents of the file with the ISQL ! (shell) statement:
ISQL> -- Check the syntax for the UNIX 'more' command:
ISQL> host more
Usage: more [-dfln] [+linenum | +/pattern] name1 name2 ...
ISQL> -- Use 'more' to display the query.sql script file:
ISQL> ! more query.sql
SELECT customers.customer_name,
orders.order_info,
orders.order_state,
lot_staging.lot_location,
lot_staging.start_date
FROM customers,
orders,
lots,
lot_staging
WHERE( customers.customer_id = orders.customer_id ) and
( lots.lot_id = lot_staging.lot_id ) and
( orders.order_id = lots.order_id ) and
( ( customers.customer_name = 'Ship Shapers Inc.' ) AND
( lot_staging.start_date is not NULL ) AND
( lot_staging.end_date is NULL ) ) ;
ISQL> -- Spawn a subshell process to issue multiple OS commands:
ISQL> sh
.
.
.
IF [ NOT ] EXISTS
Syntax
{IF [NOT] EXISTS} | {IF_EXISTS} | {IF_NOT_EXISTS} (<query>)
{BEGIN
<list of statements>
END} | { <statement> }
[ELSE
{BEGIN
<list of statements>
END} | { <statement> } ]
Conditional expressions can be nested. The following example checks for the existence of a table and creates it if it does not exist. The nested condition updates an existing table if it is required.
Example
IF NOT EXISTS (SELECT * FROM systables where tbl = 'custmast')
BEGIN
CREATE TABLE custmast (name CHAR(10), custid INTEGER IDENTITY (1,1), balance MONEY, modtime TIMESTAMP);
END
ELSE
BEGIN
IF NOT EXISTS (SELECT * FROM syscolumns where tbl='custmast' AND col='modtime')
BEGIN
ALTER TABLE custmast ADD (modtime TIMESTAMP);
END
ELSE
BEGIN
SELECT * FROM custmast;
END
END
COMMIT WORK;
The following keywords have been added to the ISQL lexicon to support conditional expressions:
- IF
- IF_EXISTS
- IF_NOT_EXISTS
- BEGIN
- ELSE
- END
Statements that use these keywords as identifiers should enclose them in double quotes.
INDEXES
Syntax
I[NDEXES] [ tablename ] ;
The INDEX statement with no argument displays a list of all the user indexes in the database that are owned by the current user.
With the tablename argument, the INDEX statement displays a brief description of the indexes defined on the specified table.
The index list is sorted by table name and index name in that order.
Example
The following example uses the index list command to display lists of indexes defined on user tables.
ISQL> INDEXES
INDEXNAME TABLENAME ID OWNER TYPE ORDER COMPRESSION METHOD
--------- --------- --- ----- ---- ----- ------------ ------
sys_001_000000041 dept 33 admin U A N B
dno_idx01 emp 35 admin D A N B
sys_001_000000042 emp 34 admin U A N B
ISQL> INDEXES emp ;
INDEXNAME TABLENAME ID OWNER TYPE ORDER COMPRESSION METHOD
--------- --------- --- ----- ---- ----- ------------ ------
deptno_idx01 emp 36 admin D A N B
name_idx01 emp 34 admin D A N B
name_idx02 emp 35 admin D A N B
sys_001_000000041 emp 33 admin U A N B
LIST
Syntax
L[IST] [ stmt_num ];
Description
The LIST statement displays the statement with the specified statement number from the statement history buffer and makes it the current statement by adding it to the end of the history list.
If LIST omits stmt_num, it displays the last statement in the history buffer.
Example
The following example uses the LIST statement to display the 5th statement in the history buffer (select CUSTOMER_NAME from customers) and copy it to the end of the history list. It then executes the now-current statement using the RUN statement:
ISQL> history
1 title
2 title top "fred" skip 5
3 title
4 help title
5 select customer_name from customers
6 display "Display on page break!"
7 display "Test page break display" on page
8 select customer_name from customers
9 select customer_name from customers
10 clear title
ISQL> list 5
select customer_name from customers
ISQL> run
select customer_name from customers
CUSTOMER_NAME
-------------
Sports Cars Inc.
Mighty Bulldozer Inc.
Ship Shapers Inc.
Tower Construction Inc.
Chemical Construction Inc.
Aerospace Enterprises Inc.
Medical Enterprises Inc.
Rail Builders Inc.
Luxury Cars Inc.
Office Furniture Inc.
10 records selected
ISQL>
QUIT or EXIT
Syntax
Q[UIT]
Description
The QUIT statement terminates the current ISQL session.
Related Statements
QUIT and EXIT are synonymous. There is no difference in their effect.
RUN
Syntax
R[UN] [stmt_num];
Description
The RUN statement executes the statement with the specified statement number from the statement history buffer and makes it the current statement by adding it to the end of the history list.
If RUN omits stmt_num, it runs the current statement.
Example
The following example runs the fifth statement in the history buffer.
ISQL> HISTORY
1 title
2 title top "TEST TITLE" skip 5
3 title
4 help title
5 select customer_name from customers
6 display "Display on page break!"
7 display "Test page break display" on page
ISQL> RUN 5
select customer_name from customers
CUSTOMER_NAME
-------------
Sports Cars Inc.
Mighty Bulldozer Inc.
Ship Shapers Inc.
Tower Construction Inc.
Chemical Construction Inc.
Aerospace Enterprises Inc.
Medical Enterprises Inc.
Rail Builders Inc.
Luxury Cars Inc.
Office Furniture Inc.
10 records selected
ISQL>
SAVE
Syntax
S[AVE] filename;
Description
The SAVE statement saves the last statement in the history buffer in filename. The GET and START statements can then be used to read and execute the statement from a file.
If filename does not exist, ISQL creates it. If filename does exist, ISQL overwrites it with the contents of the last statement in the history buffer.
Example
ISQL> ! more test.SQL
test.sql: No such file or directory
ISQL> select customer_name, customer_city from customers;
CUSTOMER_NAME CUSTOMER_CITY
------------- -------------
Sports Cars Inc. Sewickley
Mighty Bulldozer Inc. Baldwin Park
Ship Shapers Inc. South Miami
Tower Construction Inc. Munising
Chemical Construction Inc. Joplin
Aerospace Enterprises Inc. Scottsdale
Medical Enterprises Inc. Denver
Rail Builders Inc. Claymont
.
.
.
ISQL> save test.sql
ISQL> ! ls -al test.sql
-rw-r--r-- 1 ADMIN 51 May 1 18:21 test.sql
ISQL> ! more test.sql
select customer_name, customer_city from customers
ISQL>
SET
Syntax
SET set_option ;
set_option ::
HISTORY number_statements
| PAGESIZE number_lines
| LINESIZE number_characters
| COMMAND LINES number_lines
| REPORT { ON | OFF }
| ECHO { ON | OFF }
| PAUSE { ON | OFF }
| TIME { ON | OFF }
| DISPLAY COST { ON | OFF }
| AUTOCOMMIT { ON | OFF }
| TRANSACTION ISOLATION LEVEL isolation_level
| CONNECTION { database_name | DEFAULT }
| SET INDEX CHECK { ON | OFF }
Description
The SET statement changes various characteristics of an interactive c-treeSQL session.
Arguments
HISTORY
Sets the number of statements that ISQL will store in the history buffer. The default is 1 statement and the maximum is 250 statements.
PAGESIZE number_lines
Sets the number of lines per page. The default is 24 lines. After each number_lines lines, ISQL executes any DISPLAY ON PAGE statements in effect and re-displays column headings. The PAGESIZE setting affects both standard output and the file opened through the SPOOL statement.
LINESIZE
Sets the number of characters per line. The default is 80 characters. The LINESIZE setting affects both standard output and the file opened through the SPOOL statement.
COMMAND LINES
Sets the number of lines to be displayed. The default is 1.
REPORT ON | OFF
SET REPORT ON copies only the results of SQL statements to the file opened by the SPOOL filename ON statement. SET REPORT OFF copies both the SQL statement and the results to the file. SET REPORT OFF is the default.
ECHO ON | OFF
SET ECHO ON displays SQL statements as well as results to standard output. SET ECHO OFF suppresses the display of c-treeSQL statements, so that only results are displayed. SET ECHO ON is the default.
PAUSE ON | OFF
SET PAUSE ON prompts the user after displaying one page of results on the screen. SET PAUSE ON is the default.
TIME ON | OFF
SET TIME ON displays the time taken for executing a database query statement. SET TIME OFF disables the display and is the default.
DISPLAY COST ON | OFF
SET DISPLAY COST ON displays the values the c-treeSQL optimizer uses to calculate the least-costly query strategy for a particular c-treeSQL statement.
The UPDATE STATISTICS statement updates the values displayed by SET DISPLAY COST ON. SET DISPLAY COST OFF suppresses the display and is the default.
AUTOCOMMIT ON | OFF
SET AUTOCOMMIT ON commits changes and starts a new transaction immediately after each SQL statement is executed. SET AUTOCOMMIT OFF is the default. SET AUTOCOMMIT OFF requires that you end transactions explicitly with a COMMIT or ROLLBACK WORK statement.
Note: Be careful using the automatic commit logic when working with cursors. When automatic commit is enabled, the logic will execute a commit operation after each database access, which will close any open cursor. If you receive an error ‑20039 (Open for non-select statement) then most likely your cursor has been closed.
TRANSACTION ISOLATION LEVEL isolation_level
Specifies the isolation level. Isolation levels specify the degree to which one transaction can modify data or database objects being used by another concurrent transaction. The default is 3. See the SET TRANSACTION ISOLATION LEVEL statement in the c-treeSQL Reference Manual for more information on isolation levels.
CONNECTION { database_name | DEFAULT}
Sets the active connection to database_name or to the default connection. See the description of the CONNECT statement in the c-treeSQL Reference Manual for details on connections.
SET INDEX CHECK { ON | OFF}
Turns "index strict mode" on or off (defaults to off).
When "on", queries fail with error -21047 if they take advantage of an index marked as “bad” during import because it has either 1) a null key exclusion activated, or 2) one or more segments with incompatible case (e.g., has UREGSEG enabled).
When "off," the query executes as usual. The idea is to provide a simple mechanism to instruct the SQL engine whether to consider the use of an index that is not "compatible" with SQL due to either null key or UREGSEG settings. Set to “on” to instruct the SQL engine to ignore indexes that have either (or both) of these afflictions, thereby eliminating the possibility of incorrect query results.
Notes
SET REPORT and SET ECHO are similar:
- SET REPORT affects the SPOOL file only, and ON suppresses statement display
- SET ECHO affects standard output only, and OFF suppresses statement display
Other statements control other characteristics of an interactive SQL session:
- The editor invoked by the EDIT statement is controlled by the value of the environment variable EDITOR.
- The file to which interactive c-treeSQL writes output is controlled by the SPOOL filename ON statement.
Examples
ISQL> -- Illustrate PAGESIZE
ISQL> DISPLAY "Here's a page break!" ON PAGE
ISQL> SET PAGESIZE 4
ISQL> BREAK ON PAGE;
ISQL> SELECT TBL FROM SYSTABLES;
TBL
---
sys_chk_constrs
Here's a page break!
TBL
---
sys_chkcol_usage
sys_keycol_usage
Here's a page break!
.
.
.
ISQL> SET DISPLAY COST ON
ISQL> -- Select from the one-record SYSCALCTABLE table:
ISQL> SELECT * FROM SYSCALCTABLE;
Estimated Cost Values :
-----------------------
COST : 8080
CARDINALITY : 200
TREE SIZE : 3072
FLD
---
100
SHOW
Syntax
SHOW [ show_option | SPOOL ] ;
show_option ::
HISTORY
| PAGESIZE
| LINESIZE
| COMMAND LINES
| REPORT
| ECHO
| PAUSE
| TIME
| DISPLAY COST
| AUTOCOMMIT
| TRANSACTION ISOLATION LEVEL
| CONNECTION
Description
The SHOW statement displays the values of the various settings controlled by corresponding SET and SPOOL statements. If the SHOW statement omits show_option, it displays all the ISQL settings currently in effect.
See "SET", "SPOOL", and "EDIT" for details on the settings displayed by the SHOW statement.
Example
ISQL> SHOW
ISQL ENVIRONMENT
____________________
EDITOR ..................... : vi
HISTORY buffer size ........ : 50 PAUSE ..................... : ON
COMMAND LINES .............. : 10 TIMEing command execution.. : OFF
SPOOLing ................... : ON LINESIZE .................. : 78
REPORTing Facility ......... : ON PAGESIZE .................. : 72
Spool File ................. : spool_file
AUTOCOMMIT ................. : OFF ECHO commands ............. : ON
TRANSACTION ISOLATION LEVEL. : 0 (Snapshot)
DATABASE CONNECTIONS
_______________________
DATABASE CONNECTION NAME IS DEFAULT ? IS CURRENT ?
-------- --------------- ------------ -----------
salesdb conn_1 No Yes
SPOOL
Syntax
SPOOL filename [ON] ;
SPOOL OFF ;
SPOOL OUT ;
Description
The SPOOL statement writes output from interactive SQL statements to the specified file.
Arguments
filename ON
Opens the file specified by filename and writes the displayed output into that file. The filename cannot include punctuation marks such as a period (.) or comma (,).
OFF
Closes the file opened by the SPOOL ON statement.
OUT
Closes the file opened by the SPOOL ON statement and prints the file. The SPOOL OUT statement passes the file to the system utility statement pr and the output is piped to lpr.
Example
To record the displayed output into the file called STK, enter:
ISQL> SPOOL STK ON ;
ISQL> SELECT * FROM customer ;
ISQL> SPOOL OFF ;
START
Syntax
ST[ART] filename [ argument ] [ ... ] ;
Description
The START statement executes the first SQL statement stored in the specified script file.
Arguments
filename
The name of the script file. ISQL reads the file until it encounters a semicolon ( ; ) statement terminator.
argument ...
ISQL substitutes the value of argument for parameter references in the script. Parameter references in a script are of the form &n, where n is an integer. ISQL replaces all occurrences of &1 in the script with the first argument value, all occurrences of &2 with the second argument value, and so on. The value of argument must not contain spaces or other special characters.
Notes
- In addition to executing the first statement in the script file, the START statement appends the statement (after any argument substitution) to the history buffer.
- The GET, START, and @ (execute) statements are similar in that they all read SQL script files. Both GET and START read an SQL script file and append the first statement in it to the history buffer. However, the START statement also executes the script statement and accepts arguments that it substitutes for parameter references in the script statement. The @ (execute) statement, on the other hand, executes all the statements in an SQL script file but does not add any of the statements to the history buffer. The @ statement does not support argument substitution.
Example
ISQL> -- Nothing in history buffer:
ISQL> history
History queue is empty.
ISQL> -- Display a script file with the ! shell statement. The script's SQL ISQL> -- statement uses the LIKE predicate to retrieve customer names
ISQL> -- beginning with the string passed as an argument in a START statement:
ISQL> ! more start_ex.sql
SELECT customer_name FROM customers
WHERE customer_name LIKE '&1%';
ISQL> -- Use the START statement to execute the SQL statement in the script
ISQL> -- start_ex.sql. Supply the value 'Ship' as a substitution argument:
ISQL> START start_ex.sql Ship
CUSTOMER_NAME
-------------
Ship Shapers Inc.
1 record selected
ISQL> -- ISQL puts the script statement, after argument substitution,
ISQL> -- in the history buffer:
ISQL> history
1 ! more start_ex.sql
3 START start_ex.sql Ship
4 SELECT customer_name FROM customers
WHERE customer_name LIKE 'Ship%'
TABLE
Syntax
T[ABLE] [ tablename ] ;
Description
The TABLE statement with no argument displays a list of all the user tables in the database that are owned by the current user.
With the tablename argument, the TABLE statement displays a brief description of the columns in the specified table.
Examples
You can use the TABLE statement to see the structure of system tables. Unless you are logged in as the c-treeSQL database administrator (the user ADMIN, by default), you need to qualify the system table name with the administrator user name, as in the following example:
ISQL> table ADMIN.systables
COLNAME NULL ? TYPE LENGTH
------- ------ ---- ------
id NOT NULL INT 4
tbl NOT NULL VARCHAR 32
creator NOT NULL VARCHAR 32
owner NOT NULL VARCHAR 32
tbltype NOT NULL VARCHAR 1
tblpctfree NOT NULL INT 4
segid NOT NULL INT 4
has_pcnstrs NOT NULL VARCHAR 1
has_fcnstrs NOT NULL VARCHAR 1
has_ccnstrs NOT NULL VARCHAR 1
has_ucnstrs NOT NULL VARCHAR 1
tbl_status NOT NULL VARCHAR 1
rssid NOT NULL INT 4
The following example uses the TABLE command to detail the structure of the tables used in examples throughout this chapter.
ISQL> table - List the sample tables
TABLENAME
---------
customers
lot_staging
lots
orders
quality
samples
ISQL> table customers
COLNAME NULL ? TYPE LENGTH
------- ------ ---- ------
customer_id NOT NULL INT 4
customer_name CHAR 50
customer_street CHAR 100
customer_city CHAR 50
customer_state CHAR 10
customer_zip CHAR 5
ISQL> table orders
COLNAME NULL ? TYPE LENGTH
------- ------ ---- ------
order_id NOT NULL INT 4
customer_id INT 4
steel_type CHAR 20
order_info CHAR 200
order_weight INT 4
order_value INT 4
order_state CHAR 20
ISQL> table lots
COLNAME NULL ? TYPE LENGTH
------- ------ ---- ------
lot_id NOT NULL INT 4
order_id NOT NULL INT 4
lot_units INT 4
lot_info CHAR 200
ISQL> table lot_staging
COLNAME NULL ? TYPE LENGTH
------- ------ ---- ------
lot_id INT 4
lot_location CHAR 20
start_date DATE
end_date DATE
issues CHAR 200
ISQL> table quality
COLNAME NULL ? TYPE LENGTH
------- ------ ---- ------
lot_id NOT NULL INT 4
purity DOUBLE 8
p_deviation DOUBLE 8
strength DOUBLE 8
s_deviation DOUBLE 8
comments CHAR 200
ISQL> table samples
COLNAME NULL ? TYPE LENGTH
------- ------ ---- ------
lot_id INT 4
samples INT 4
comments CHAR 200
ISQL>
TITLE
Syntax
TITLE [
[ TOP | BOTTOM ]
[ [ LEFT | CENTER | RIGHT | COL n ] " text " ] [ ... ]
[ SKIP n ]
] ;
Description
The TITLE statement specifies text that ISQL displays either before or after it processes a query. TITLE with no arguments displays the titles currently set, if any.
Arguments
TOP | BOTTOM
Specifies whether the title is to be printed at the top or bottom of the page. The default is TOP.
LEFT | CENTER | RIGHT | COL n
Specifies the horizontal alignment of the title text: LEFT aligns the text to the left of the display; CENTER centers the text; RIGHT aligns the text to the right (with the right-most character in the column specified by the SET LINESIZE statement). COL n displays the text starting at the specified column (specifying COL 0 is the same as LEFT).
The default is LEFT.
" text "
The text to be displayed.
SKIP n
Skips n lines after a TOP title is printed and before a BOTTOM title is printed. By default, ISQL does not skip any lines.
Examples
The following example shows the effect of specifying a top title without a bottom title, then both a top and bottom title.
ISQL> TITLE "fred"
ISQL> select * from syscalctable;
fred
FLD
---
100
1 record selected
ISQL> TITLE BOTTOM "flintstone"
ISQL> select * from syscalctable;
fred
FLD
---
100
flintstone
1 record selected
The TITLE statement can specify separate positions for different text in the same title:
ISQL> CLEAR TITLE
ISQL> TITLE TOP LEFT "Align on the left!" CENTER "Centered text" RIGHT "Right aligned text!"
ISQL> select * from syscalctable;
Align on the left! Centered text Right aligned text!
FLD
---
100
1 record selected