Table of Contents
This chapter describes the tbSQL utility and its usage.
tbSQL is an interactive utility provided by Tibero to process SQL statements. tbSQL utility can process SQL queries, Data Definition Language (hereafter DDL), and transactional SQL statements. It can also be used to create and execute PSM programs, and DBAs can execute commands to manage Tibero systems.
In addition, tbSQL provides many other functions, such as auto commit setting, OS command execution, output save, and script creation. The script function allows the user to conveniently create SQL statements, PSM programs, and tbSQL utility commands into a single script file.
tbSQL is one of the most frequently used utility in Tibero. It provides the following functions in addition to executing SQL statements.
Input, edit, save, and execute general SQL statements and tbSQL programs.
Configure and terminate a transaction.
Batch processing using a script.
Management of databases by a DBA.
Start and terminate a database.
Execute external utilities and programs.
Configure the tbSQL utility.
tbSQL is automatically installed and uninstalled with Tibero.
The following example illustrates how to execute tbSQL.
[Example 1.1] Executing tbSQL
$ tbsql tbSQL 6 TmaxData Corporation Copyright (c) 2008-. All rights reserved.
When tbSQL is successfully executed, the previous SQL prompt is displayed. Database users can enter and execute SQL statements at the prompt.
The following is the command syntax for executing tbSQL.
Usage
tbsql [[options]|[connect_string]|[start_script]]
options
Option | Description |
---|---|
-h, --help | Display the Help screen. |
-v, --version | Display the version information. |
-s, --silent | Do not output the start message and prompt. |
-i, --ignore | Do not execute the login script (tbsql.login). |
connect_string
connect_string contains the user account information for Tibero. It is specified as follows:
username[/password[@connect_identifier]]
The following are the connect_string options.
Option | Description |
---|---|
username | User name. It is not case-sensitive except when it is enclosed in double quotes (" "). |
password | User password. It is not case-sensitive except when it is enclosed in single quotes (' '). |
connect_identifier | DSN (Data Source Name) that contains database access information or the connection information of the set connection policy. |
start_script
start_script sets the script files to execute during tbSQL startup. It is specified as follows:
@filename[.ext] [parameter ...]
The following are the start_script options.
Option | Description |
---|---|
filename | File name. |
ext | File extension. If not set, the default value (SUFFIX system variable value) will be used. |
parameter | Substitution variable used in the file. |
When the SQL prompt appears after executing tbSQL, it is ready to connect to the database.
If there are any tasks that need to be processed before starting the database session, create the tbsql.login file. If this file can't be found in the current directory, it can be found in the directory specified in the environment variable, TB_SQLPATH.
The following shows how to connect to the database in tbSQL.
[Example 1.2] Connecting to Database
$ tbsql SYS/syspassword tbSQL 6 TmaxData Corporation Copyright (c) 2008-. All rights reserved. Connected. SQL>
In the previous example, username and password are entered at the UNIX shell prompt that is displayed after starting tbSQL.
Rules for entering the username and password are as follows:
Item | Description |
---|---|
Username | User name. It is not case-sensitive except when it is enclosed in double quotes (" "). |
Password | Password. It is not case-sensitive except when it is enclosed in single quotes (' '). |
If connect_identifier is omitted, as in the previous example, connection is made to the default database. To access a specific database, specify connect_identifier in one of the following ways.
DSN (Data Source Name)
Specify the name that is defined in tbdsn.tbr or Data Source (ODBC) in Windows.
The following is an example of a tbdsn.tbr file.
tibero6=( (INSTANCE=(HOST=192.168.36.42) (PORT=8629) (DB_NAME=tibero6) ) )
Connect to the database using the previous setting as follows:
$ tbsql tibero/tmax@tibero6
Connection information
Connection information can be manually specified using one of the following two methods (without using a tbdsn.tbr file).
Method 1
(INSTANCE=(HOST=host)(PORT=port)(DB_NAME=dbname))
Example:
$ tbsql 'tibero/tmax@(INSTANCE=(HOST=192.168.36.42)(PORT=8629)(DB_NAME=tibero6))'
Method 2
host:port/dbname
Example:
$ tbsql 'tibero/tmax@192.168.36.42:8629/tibero6'
The following example shows tbSQL utility execution.
$ tbsql tbSQL 6 TmaxData Corporation Copyright (c) 2008-. All rights reserved. SQL> CONNECT dbuser Enter password : dbuserpassword Connected to Tibero.
In the previous example, after starting tbSQL a connection is made to the database using the CONNECT command with the username 'dbuser'. tbSQL is a text-based user interface.
In this document, all SQL statements, PSM programs, tbSQL utility commands, with some exceptions, are written in upper case letters. Command parameters written in lower case letters are specified by the user.
The tbSQL interface that supports the following features:
When tbSQL SQL prompt is displayed.
At the SQL prompt, it is possible to enter SQL statements, PSM programs, and tbSQL utility commands.
Input can span over multiple lines.
SQL statements and PSM programs are not automatically executed at input, but tbSQL utility commands are executed immediately.
Case insensitive.
Input text is case insensitive, with some exceptions such as a string value in a SQL statement.
For example, the following two statements will produce the same results.
SQL> SET AUTOCOMMIT ON SQL> set autocommit on
Use the SET command to configure tbSQL. It can be used to configure various settings including SQL query result output format and transaction commit option.
The following is the syntax of the SET command.
SET [system_variable] [system_variable_value]
For detailed information, refer to “1.3. System Variables”.
To terminate tbSQL, enter the EXIT or QUIT command at the SQL prompt.
SQL> EXIT
For detailed information about the commands provided in tbSQL, refer to “1.6. Commands”.
This section describes the system variables in tbSQL. Use the SET command to configure the system variables, and the SHOW command to display the results.
Following are the system variables that can be configured with the SET command.
System Variables | Default Value | Description |
---|---|---|
AUTOCOMMIT | OFF | Option to enable the AUTOCOMMIT option. |
AUTOTRACE | OFF | Option to display the statistical or plan information for the current query. |
BLOCKTERMINATOR | "." (0x2E) | Character to indicate the end of a PSM statement input. |
COLSEP | " " (0x20) | Column separator character used in the query result. |
CONCAT | "." (0x2E) | Character that indicates the end of the substitution variable name. |
DDLSTATS | OFF | Option to show the statistical or plan information for the running DDL statement. |
DEFINE | "&" (0x26) | Character used to define a substitution variable. |
DESCRIBE | DEPTH 10 | Depth of the object specification shown by the DESCRIBE command. |
ECHO | OFF | Option to display queries as they are being executed when a script is executed by using @ or START command. |
EDITFILE | ".tbedit.sql" | Default value of a filename used with the EDIT command. |
ESCAPE | OFF | Escape character. |
EXITCOMMIT | ON | Option to commit when terminating the utility. |
FEEDBACK | 0 | Option to display the SQL statement result. |
HEADING | ON | File extension used when the extension is omitted. |
HEADSEP | "|" (0x7C) | Line-break character used in column headings. |
HISTORY | 50 | Size of the command history. |
INTERVAL | 1 | Interval at which each statement in the LOOP command is executed. |
LINESIZE | 80 | Length of a line on the screen. |
LONG | 80 | Number of the characters that can represent data that is longer than VARCHAR type. |
NEWPAGE | 1 | Number of empty lines added to the beginning of each page. |
NUMFORMAT | "" | Default column format for numeric data. |
NUMWIDTH | 10 | Default width for outputting numeric data. |
PAGESIZE | 24 | Number of lines to output on each page. |
PAUSE | OFF | Option to wait for user input before displaying the next page. |
RECSEP | WRAPPED | Where to display a row separator. |
RECSEPCHAR | " " (0x20) | Row separator character. |
ROWS | ON | Option to display query statement result. |
SERVEROUTPUT | OFF | Option to display the result of the DBMS_OUTPUT package. |
SQLPROMPT | "SQL> " | Prompt string (same as PROMPT). |
SQLTERMINATOR | ";" (0x3B) | Character for terminating a SQL statement. |
SUFFIX | "sql" | Default file extension. |
TERMOUT | ON | Option to display the result of executing commands in a script. |
TIME | OFF | Option to display the current time in the prompt. |
TIMEOUT | 3 | Timeout for a server response to a PING command. |
TIMING | OFF | Option to display the processing time with the SQL and PSM results. |
TRIMOUT | ON | Option to truncate whitespaces at the end of each line, every time SQL or PSM results are displayed. |
TRIMSPOOL | OFF | Option to truncate whitespaces at the end of each line while spooling. |
UNDERLINE | "-" (0x2D) | Character used to underline headers. |
VERIFY | ON | Option to display the command after replacing substitution variables with values. |
WRAP | ON | Option to wrap the output to the next line when it is too long. |
The following is an example of configuring system variables.
SET AUTOCOMMIT ON SET PAGESIZE 32 SET TRIMSPOOL ON
Executes commit after an INSERT, UPDATE, DELETE, MERGE, or PSM block is successfully executed.
The following is the syntax of AUTOCOMMIT.
Syntax
SET AUTO[COMMIT] {ON|OFF|n}
Item | Description |
---|---|
ON | Enable AUTOCOMMIT. |
OFF | Disable AUTOCOMMIT. (Default value) If set to OFF, the changes must be committed manually. |
n | Execute commit when n number of INSERTs, UPDATEs, DELETEs, MERGEs, or PSM blocks were successfully executed. If set to 0, AUTOCOMMIT is disabled (OFF). If set to 1, AUTOCOMMIT is enabled (ON). |
Shows the statistical or plan information for the current query. DBA or PLUSTRACE privileges are required to use AUTOTRACE. PLUSTRACE role includes the permissions required to use AUTOTRACE. A user with the DBA privileges can create the PLUSTRACE role and grant it to other users. The creation script is $TB_HOME/scripts/plustrace.sql.
The following is the syntax for AUTOTRACE.
Syntax
SET AUTOT[RACE] {ON|OFF|TRACE[ONLY]} [EXP[LAIN]] [STAT[ISTICS]] [PLANS[TAT]]
Input
Item | Description |
---|---|
ON | Display the statistical or plan information based on the query result and additional options. |
OFF | Do not display the statistical or plan information. (Default value) |
TRACE[ONLY] | Only display the statistical or plan information, without the query results, based on additional options. |
Options
The following options specify whether to show the statistical or plan information.
Option | Description |
---|---|
If unspecified, display both plan and statistical information. | |
EXP[LAIN] | Display the plan information. |
STAT[ISTICS] | Display the statistical information. |
PLANS[TAT] | Display query execution information (processing time, number of processed rows, execution count, etc.) by node. |
Specifies a character to indicate the end of a tbPSM statement input.
The following is the syntax for BLOCKTERMINATOR.
Syntax
SET BLO[CKTERMINATOR] {c|ON|OFF}
Item | Description |
---|---|
c | Character to indicate the end of a PSM program input. (Default value: period (.)) |
ON | Enable the PSM termination character. (Default value) |
OFF | Disable the PSM termination character. |
Specifies a column separator character to print between columns of the results.
The following is the syntax for COLSEP.
Syntax
SET COLSEP {text}
Item | Description |
---|---|
text | Column separator character string. (Default character: " ") |
Specifies a character that indicates the end of the name of a substitution variable.
The following is the syntax for COLSEP.
Syntax
SET CON[CAT] {c|ON|OFF}
Item | Description |
---|---|
c | Character that indicates the end of the substitution variable name. (Default character: ".") |
ON | Enable CONCAT. (Default value) |
OFF | Disable CONCAT. |
Specifies whether to show the statistical or plan information for the running DDL statement. To use this system variable, AUTOTRACE must also be enabled.
The following is the syntax for DDLSTATS.
Syntax
SET DDLSTAT[S] {ON|OFF}
Item | Description |
---|---|
ON | Enable DDLSTATS. |
OFF | Disable DDLSTATS. (Default value) |
Specifies the character used to define a substitution variable.
The following is the syntax for DEFINE.
Syntax
SET DEF[INE] {c|ON|OFF}
Item | Description |
---|---|
c | Character that indicates a substitution variable. (Default character: "&") |
ON | Enable DEFINE. (Default value) |
OFF | Disable DEFINE. |
Specifies the depth of the object specification shown by the DESCRIBE command.
The following is the syntax for DESCRIBE.
Syntax
SET DESCRIBE DEPTH {n}
Item | Description |
---|---|
n | Depth of object specification to ouput recursively. (Default value: 10) |
Specifies whether to display queries as they are being executed when a script is executed by using @ or START command
The following is the syntax for ECHO.
Syntax
SET ECHO {ON|OFF}
Item | Description |
---|---|
ON | Enable ECHO. |
OFF | Disable ECHO. (Default value) |
Specifies the default value of a filename used with the EDIT command. When the extension is omitted, the value set in SUFFIX is used.
The following is the syntax for EDITFILE.
Syntax
SET EDITF[ILE] filename[.ext]
Item | Description |
---|---|
filename[.ext] | Filename to use with the EDIT command. (Default value: .tbedit.sql) |
Specifies the escape character. If ESCAPE is enabled and the escape character is appended at the front of '&<character string>', it is not recognized as a substitution variable.
The following is the syntax for ESCAPE.
Syntax
SET ESC[APE] {c|ON|OFF}
Item | Description |
---|---|
c | Escape character. (Default value: "\") |
ON | Enable ESCAPE. |
OFF | Disable ESCAPE. (Default value) |
Specifies whether to commit when terminating the utility.
The following is the syntax for EXITCOMMIT.
Syntax
SET EXITC[OMMIT] {ON|OFF}
Item | Description |
---|---|
ON | Enable EXITCOMMIT. (Default value) |
OFF | Disable EXITCOMMIT. |
Specifies whether to display the SQL statement result.
The following is the syntax for FEEDBACK.
Syntax
SET FEED[BACK] {n|ON|OFF}
Item | Description |
---|---|
n | Minimum number of rows required to output the results. (Default value: 0) |
ON | Enable FEEDBACK. (Default value) |
OFF | Disable FEEDBACK. |
Specifies whether to display column headers for query results.
The following is the syntax for HEADING.
Syntax
SET HEA[DING] {ON|OFF}
Item | Description |
---|---|
ON | Enable HEADING. (Default value) |
OFF | Disable HEADING. |
Specifies the line-break character used in column headings.
The following is the syntax for HEADSEP.
Syntax
SET HEADS[EP] {c|ON|OFF}
Item | Description |
---|---|
c | Line-break character. (Default value: "|") |
ON | Enable HEADSEP. (Default value) |
OFF | Disable HEADSEP. |
Specifies the size of the command history.
The following is the syntax for HISTORY.
Syntax
SET HIS[TORY] {n}
Item | Description |
---|---|
n | Size of the command history. (Default value: 50) |
Specifies the interval for executing each statement in the LOOP command.
The following is the syntax for INTERVAL.
Syntax
SET INTER[VAL] {n}
Item | Description |
---|---|
n | Interval time in seconds. (Default value: 1) |
Specifies the length of a line on the screen. Minimum value is 1 and the maximum value depends on the OS.
The following is the syntax for LINESIZE.
Syntax
SET LIN[ESIZE] {n}
Item | Description |
---|---|
n | Length of a line on the screen. (Default value: 80) |
Specifies the output size of the CLOB, BLOB, NCLOB, LONG, or XML data type. Maximum length is 2 billion.
The following is the syntax for LONG.
Syntax
SET LONG {n}
Item | Description |
---|---|
n | Default output size for large object data types. (Default value: 80) |
Specifies the number of empty lines added to the beginning of each page.
The following is the syntax for NEWPAGE.
Syntax
SET NEWP[AGE] {1|n|NONE}
Item | Description |
---|---|
n | Number of empty lines. (Default value: 1) |
Specifies the default column format of numeric data. This applies numeric columns except those with FORMAT defined through the COLUMN command.
The following is the syntax for NUMFORMAT.
Syntax
SET NUMF[ORMAT] {fmt_str}
Item | Description |
---|---|
fmt_str | Default column format of numeric data. (Default value: "") For more information about the number type, refer to “1.7. Column Formats”. |
Specifies the default width for outputting numeric data. This value cannot exceed the size set in LINESIZE.
The following is the syntax for NUMWIDTH.
Syntax
SET NUM[WIDTH] {n}
Item | Description |
---|---|
n | Default width for outputting numeric data. (Default value: 10) |
Specifies the number of lines to output on each page.
The following is the syntax for PAGESIZE.
Syntax
SET PAGES[IZE] {n}
Item | Description |
---|---|
n | Number of lines per page. (Default value: 24) |
Specifies whether to wait for user input before displaying the next page.
The following is the syntax for PAUSE.
Syntax
SET PAU[SE] {ON|OFF}
Item | Description |
---|---|
ON | Enable PAUSE. |
OFF | Disable PAUSE. (Default value) |
Specifies where to print the row separator.
The following is the syntax for RECSEP.
Syntax
SET RECSEP {WR[APPED]|EA[CH]|OFF}
Item | Description |
---|---|
WRAPPED | Display a separator when a row is wrapped. (Default value) |
EACH | Display a separator following each row. |
OFF | Disable RECSEP. |
Specifies the row separator character to print after each line of the size, LINESIZE.
The following is the syntax for RECSEPCHAR.
Syntax
SET RECSEPCHAR {c}
Item | Description |
---|---|
c | Row separator. (Default value: " ") |
Specifies whether to display query statement result.
The following is the syntax for ROWS.
Syntax
SET ROWS {ON|OFF}
Item | Description |
---|---|
ON | Enable ROWS. (Default value) |
OFF | Disable ROWS. |
Specifies whether to display the result of the DBMS_OUTPUT package.
The following is the syntax for SERVEROUTPUT.
Syntax
SET SERVEROUT[PUT] {ON|OFF} [SIZE n]
Item | Description |
---|---|
ON | Enable SERVEROUTPUT. |
OFF | Disable SERVEROUTPUT. (Default value) |
n | SERVEROUTPUT buffer size. (Default value: 1000000) |
Specifies the prompt string.
The following is the syntax for SQLPROMPT.
Syntax
SET SQLP[ROMPT] {prompt_string}
Item | Description |
---|---|
prompt_string | Prompt string. (Default value: "SQL>"). If the string is enclosed in braces ({ }), it is recognized as an environment variable. For example, if '{ISQL_PROMPT}' is specified, the value of $ISQL_PROMPT is used as the prompt. The environment variable name is case sensitive. |
Specifies the character for terminating a SQL statement.
The following is the syntax for SQLTERMINATOR.
Syntax
SET SQLT[MINATOR} {c|ON|OFF}
Item | Description |
---|---|
c | Character that signifies the termination of a SQL statement. (Default value: ";") |
ON | Enable SQLTERMINATOR. |
OFF | Disable SQLTERMINATOR. |
Specifies the default file extension.
The following is the syntax for SUFFIX.
Syntax
SET SUF[FIX] {extension}
Item | Description |
---|---|
extension | Default file extension. (Default value: sql) |
Specifies whether to display the result of executing commands in a script.
The following is the syntax for TERMOUT.
Syntax
SET TERM[OUT] {ON|OFF}
Item | Description |
---|---|
ON | Enable TERMOUT. (Default value) |
OFF | Disable TERMOUT. |
Specifies whether to display the current time in the prompt.
The following is the syntax for TIME.
Syntax
SET TI[ME] {ON|OFF}
Item | Description |
---|---|
ON | Enable TIME. |
OFF | Disable TIME. (Default value) |
Specifies the timeout for a server response to a PING command.
The following is the syntax for TIMEOUT.
Syntax
SET TIMEOUT {n}
Item | Description |
---|---|
n | Timeout for a server response. The unit is second. (Default value: 3 seconds) |
Specifies whether to display the processing time with the SQL and PSM statement results.
The following is the syntax for TIMING.
Syntax
SET TIMI[NG] {ON|OFF}
Item | Description |
---|---|
ON | Enable TIMING. |
OFF | Disable TIMING. (Default value) |
Specifies whether to truncate whitespaces at the end of each line, every time SQL or PSM results are displayed.
The following is the syntax for TRIMOUT.
Syntax
SET TRIM[OUT] {ON|OFF}
Item | Description |
---|---|
ON | Enable TRIMOUT. (Default value) |
OFF | Disable TRIMOUT. |
Specifies whether to truncate to truncate whitespaces at the end of each line while spooling.
The following is the syntax for TRIMSPOOL.
Syntax
SET TRIMS[POOL] {ON|OFF}
Item | Description |
---|---|
ON | Enable TRIMSPOOL. |
OFF | Disable TRIMSPOOL. (Default value) |
Specifies the character used to underline headers.
The following is the syntax for UNDERLINE.
Syntax
SET UND[ERLINE] {c|ON|OFF}
Item | Description |
---|---|
c | Underline character. (Default value: "-") |
ON | Enable UNDERLINE. (Default value) |
OFF | Disable UNDERLINE. |
Specifies whether to display the command after replacing substitution variables with values.
The following is the syntax for VERIFY.
Syntax
SET VER[IFY] {ON|OFF}
Item | Description |
---|---|
ON | Enable VERIFY. (Default value) |
OFF | Disable VERIFY. |
tbSQL is mainly used for executing user entered SQL statements or PSM programs. This section describes the basic and additional functions of tbSQL.
A SQL statement, PSM program, or tbSQL command can be entered at the tbSQL command prompt. Each command can be entered in the same way.
The following describes how to enter each command.
How to enter a SQL statement:
SQL Statement
In general, a SQL statement is entered at the command prompt. One SQL statement can span over multiple lines. To cancel an entry, enter a blank line.
Line Feed
When entering a SQL statement over several lines, a line feed can be entered anywhere except within a string. For readability, it is recommended to change lines at the end of each clause.
Inserting Comments
Comments can be inserted in the middle of a SQL statement by using two dashes (--) and continues to the end of the line. An entire line can be a comment, or a comment can be placed in the middle of a line after a string.
Using Pre-saved Statements
Once a SQL statement is entered, it is saved in the SQL buffer of tbSQL. The saved SQL can be modified or used as is. If modified, it will be saved as a new SQL in the SQL buffer.
SQL statements and PSM programs are saved in the SQL buffer. Depending on the OS, the UP (↑) arrow or DOWN (↓) arrow key can be used to select the saved statement. One line of a saved SQL is displayed with each key press. This allows the user to retrieve all or part of the saved SQL statement from the buffer.
The following example illustrates how to enter a SQL statement in tbSQL.
SQL> SELECT ENAME, SALARY, ADDR FROM EMP -- this is a comment. WHERE DEPTNO = 5; SQL>
PSM program consists of multiple SQL or PSM statements. Each SQL statement is terminated with a semicolon (;). When the user starts to enter PSM program, tbSQL will be automatically switched to PSM program input mode. In the PSM program input mode, SQL statements are not executed until the entire program is entered.
The statements that trigger tbSQL to switch to PSM program input mode are anonymous blocks such as DECLARE and BEGIN, and those that create a procedure, function, and trigger (CREATE (OR REPLACE) PROCEDURE, FUNCTION, and TRIGGER).
PSM programs can be entered like SQL statements.
How to enter a PSM program:
PSM Program
A PSM program can span over multiple lines. To cancel a SQL statement entry, enter a blank line. To cancel a PSM program entry, enter the block terminator character (BLOCKTERMINATOR). By default, the character is set to a PERIOD (.). The block terminator character must be entered on a separate line by itself without any other strings.
Using Pre-saved Statements
Once a program is entered, it is saved in the SQL buffer for reuse.
Inserting Comments
Comments are entered in the same way as in SQL statements.
The following example illustrates how to enter an anonymous block in tbSQL.
SQL> DECLARE deptno NUMBER(2); BEGIN deptno := 5; UPDATE EMP SET SALARY = SALARY * 1.05 WHERE DEPTNO = deptno; -- this is a comment. END; . SQL>
In the previous example, there is a comment line and a period (.), which terminates the PSM program, below the END statement. The last line contains only the block terminator character (a period) without any other characters or strings.
For detailed information about using PSM, refer to "Tibero PSM Guide".
tbSQL utility commands are used to execute SQL or manage Tibero database. For more detailed information about tbSQL utility commands, refer to “1.6. Commands”.
There are 3 ways to execute a command from the command prompt in tbSQL.
Executing a PSM program or SQL statement saved in SQL buffer
SQL buffer saves only the last executed SQL statement or PSM program. To execute the SQL statement or tbPSM program, enter 'RUN' or '/' command.
Executing a SQL statement
Enter the statement and a semicolon (;) at the end to execute SQL statement.
Executing SQL statement and saving it in SQL buffer
To execute the SQL statement or PSM program and save it in the butter, enter the '/' command. The command must be on a separate line by itself like the aforementioned terminator character (.).
There is no separate tbSQL utility command for executing commands unlike SQL statement or PSM program. The commands are not saved in the SQL buffer, and each command is automatically executed as it is entered.
The following example illustrates how to execute a SQL statement that is saved in the SQL buffer.
SQL> SELECT ENAME, SALARY, ADDR FROM EMP -- this is a comment. WHERE DEPTNO = 5; ......Execution result (1)...... SQL> / ......Execution result (2)...... SQL>
At the first SQL prompt, a SQL statement is immediately executed when it is terminated with a semicolon (;). At the second SQL prompt, the '/' command executes the last SQL statement saved in the SQL buffer, which is the SQL entered at the first prompt. Hence, the execution result (1) and (2) will be the same.
The following example illustrates how to execute the previous SQL statement using the slash (/) command. In this case, a semicolon (;) is not entered at the end of the SQL statement.
SQL> SELECT ENAME, SALARY, ADDR FROM EMP -- this is a comment. WHERE DEPTNO = 5 / ......Execution result...... SQL>
This section describes the functions for inserting a comment, auto commit, executing OS command, and saving output, which are the most commonly used functions in tbSQL.
Comments can be inserted in the following two ways.
Using /* … */
As in C or C++ programing language, the parts enclosed between /* and */ are treated as a comment in tbSql.
A comment cannot be nested in another comment.
Using Double Dashes (--)
When double dashes (--) are encountered, they mark the beginning of a comment until the end of the line.
This comment can be placed anywhere as with /* … */, except on a line with a period that indicates the end of a PSM program.
Hence, the following script file will cause an error.
(PSM Program)
.-- wrong comment
RUN
A SQL execution does not update the database until the transaction is committed. A transaction usually consists of multiple SQL statements.
In tbSQL, the AUTOCOMMIT parameter can be set to ON or OFF. By default, it is set to OFF.
Use the SET AUTOCOMMIT command to set auto commit on or off. To check the current setting, use the SHOW AUTOCOMMIT command.
To execute an OS command in tbSQL, use the HOST command.
The following example illustrates how to list all script files with .sql extension. The '!' command can be used in place of the HOST command.
SQL> HOST dir *.sql ..... OS command execution result ..... SQL>
After executing an OS command, the tbSQL prompt is displayed again to accept other tbSQL commands.
If the HOST or '!' command is entered without additional commands, the tbSql interface switches to the OS command line interface. To return to tbSQL, enter EXIT.
SQL> ! $ dir *.sql ..... OS command execution result ..... $ EXIT SQL>
To save all inputs and outputs of tbSQL as a text file, use the SPOOL command. The SPOOL command saves all user-entered SQL statements or PSM programs, tbSQL utility commands, query results, program execution results, and tbSQL command prompts.
If you execute the SPOOL command, it will start saving from the next line. To stop the command, enter SPOOL OFF and any following lines are not saved.
The following example illustrates how to use the SPOOL command. If the specified file, save.txt, already exists, the existing file will be overwritten by the new file.
SQL> SPOOL save.txt Spooling is started. SQL> SELECT * FROM DUAL; DUMMY ----- X 1 row selected. SQL> SPOOL OFF Spooling is stopped: save.txt
The following is an example of the save.txt file from the previous example.
SQL> SELECT * FROM DUAL; DUMMY ----- X 1 row selected. SQL> SPOOL OFF
Any user-entered SQL statements, query results, and commands are saved in th file until SPOOL OFF command is executed.
This section describes the advanced functions of tbSQL including batch processing using a script and DBA functions for managing Tibero.
A script consists of SQL statements, PSM programs, and tbSQL utility commands used to perform batch processing. When the script is executed in tbSQL, the commands in the script are executed sequentially.
A script file can be created and edited externally and executed in tbSQL, or an external editor can be executed from tbSQL by specifying the editor to use.
The following example illustrates how to execute vi, an external editor, in tbSQL.
$ export TB_EDITOR=vi
To edit a script file using an external editor, use the EDIT command with the file name. The file extension can be omitted if the extension is same as the value set in the SUFFIX system variable.
The following example illustrates how to call an external editor to edit the script file, run.sql.
SQL> EDIT run
A SQL statement, PSM program, or tbSQL command can be added to a script file as follows:
Command Entry
A command can be entered similar to a command line entry, and can span over multiple lines.
Terminating a SQL Statement and PSM Program
A SQL statement must be terminated with a semicolon (;), and a PSM program must be terminated with a (.) on the last line.
Inserting a Comment
Comments can be added to a script file.
When a script is executed, the SQL statements in the script are executed immediately. A PSM program is executed with the RUN or '/' command.
The following example shows a script file that performs multiple operations on the table EMP. Blank lines are allowed between lines.
-- SQL statement SELECT ENAME, SALARY, ADDR FROM EMP WHERE DEPTNO = 5; UPDATE EMP SET SALARY = SALARY * 1.05 WHERE DEPTNO = 5; -- PSM program DECLARE deptno NUMBER(2); BEGIN deptno := 20; UPDATE EMP SET SALARY = SALARY * 1.05 WHERE DEPTNO = deptno; END; RUN -- Execute PSM program /* Reflect the final updates. */ COMMIT;
To execute a script file, use the START or @ command with the file name. The file extension can be omitted if the extension is the same as the SUFFIX system variable (sql).
The following example illustrates how to execute a script file, run.sql, using the two commands that produce the same results.
SQL> START run SQL> @run
One or more script files can be executed from within a script file by calling the START or @ command. Make sure not to create an infinite loop when executing a script file recursively.
The @ command can be executed when starting tbSQL to execute a script at startup. This is useful when executing a batch program from the OS.
The following example illustrates how to run a script file, run.sql, at tbSql startup.
$ tbsql dbuser/dbuserpassword @run
Or the redirect shell command can be used to execute the script as follows:
$ tbsql dbuser/dbuserpassword < run.sql
DBA functions can be executed in tbSQL by loggin into Tibero as a user with DBA privileges.
The following illustrates how to log in as a SYS user with DBA privileges.
$ tbsql sys/syspassword
The user can also connect to the database as a DBA after starting tbSQL by using the CONNECT command.
The following illustrates how to connect to the database as a DBA using the CONNECT command.
SQL> CONNECT sys/syspassword
A DBA can perform the following task in tbSQL:
TerminateTibero
Terminate Tibero using the TBDOWN tbSQL command.
tbSQL can restrict users from executing certain commands.
For this, tbSQL references the CLIENT_ACCESS_POLICY table created by the SYS user. DBA can define the access policy to grant privileges to execute commands to specific users.
tbSQL loads user information when the user connects to the database, and checks the privileges each time the user executes a command to allow/prohit its execution. The user information is released when the user disconnects from the database.
User privilege is not checked for SYS users.
The access control table can only be created by a SYS user by executing the $TB_HOME/scripts/client_policy.sql file.
User privileges will not be checked if the table does not exist or could not be created.
A detailed description of the CLIENT_ACCESS_POLICY is as follows:
CLIENT VARCHAR2(32) NOT NULL USERID VARCHAR2(128) ACTION VARCHAR2(256) POLICY VARCHAR2(64)
Item | Description |
---|---|
CLIENT | Client program name. This is case-sensitive and uses tbSQL |
USERID | USERID(s). Specify as follows and wilcard (%) is allowed.
|
ACTION | Command. |
POLICY | Access policy. Set to DISABLED. |
A record must be added to the CLIENT_ACCESS_POLICY to restrict access to tbSQL, SQL, or PSM commands. To allow access to these commands again, the record must be deleted.
CLIENT USERID ACTION POLICY -------- ------------ ---------------- ---------- tbSQL TIBERO HOST DISABLED tbSQL % INSERT DISABLED tbSQL PUBLIC UPDATE DISABLED
The following are the command lists:
tbSQL Commands
ACCEPT APPEND ARCHIVE CHANGE CLEAR COLUMN CONNECT DEFINE DEL DESCRIBE DISCONNECT EDIT EXECUTE EXIT EXPORT HELP (?) HISTORY HOST (!) INPUT LIST LOADFILE LOOP LS PASSWORD PAUSE PING PRINT PROMPT QUIT REMARK RESTORE RUN SAVE SET SHOW SPOOL START (@, @@) TBDOWN UNDEFINE VARIABLE WHENEVER
SQL Commands
ALTER ANALYZE AUDIT CALL COMMENT COMMIT CREATE DELETE DROP EXPLAIN FLASHBACK GRANT INSERT LOCK MERGE NOAUDIT PURGE RENAME REVOKE ROLLBACK SAVEPOINT SELECT SET CONSTRAINTS SET ROLE SET TRANSACTION TRUNCATE UPDATE
PSM Commands
BEGIN DECLARE
The following is an example of using the user access control function.
..... Connect as SYS user ..... SQL> CONNECT SYS ..... Configure Access Control ..... SQL> INSERT INTO CLIENT_ACCESS_POLICY VALUES ('tbSQL', 'TIBERO', 'SELECT', 'DISABLED'); ..... Connect as TIBERO user ..... SQL> CONNECT TIBERO SQL> SELECT * FROM DUAL; TBS-70082: The 'SELECT' command has been disabled.
tbSQL saves database access information (connect_string) in an encrypted file (wallet).
The database connection information used in tbSQL
After accessing a database in tbSQL, the user can create an encrypted file using the SAVE CREDENTIAL command.
The following illustrates how to encrypt the database connection information by setting ISQL_WALLET_PATH to the wallet.dat file in the current directory.
$ export ISQL_WALLET_PATH=./wallet.dat $ tbsql tbSQL 6 TmaxData Corporation Copyright (c) 2008-. All rights reserved. Can't login with the wallet file. Login the database and SAVE CREDENTIAL again. Enter Username: dbuser Enter Password: dbuserpassword Connected to Tibero. SQL> SAVE CREDENTIAL Complete to generate the wallet file.
In this example,
To resolve the error, reconnect to the database and create the './wallet.dat' file using the SAVE CREDENTIAL command.
The following illustrates how to encrypt the database connection information in the wallet.dat file of the current directory, without setting the environment variable of ISQL_WALLET_PATH.
$ tbsql tbSQL 6 TmaxData Corporation Copyright (c) 2008-. All rights reserved. SQL> CONN dbuser/dbuserpassword Connected to Tibero. SQL> SAVE CREDENTIAL "./wallet.dat" Complete to generate the wallet file.
Execute SAVE CREDENTIAL with the './wallet.dat' file to create the wallet by encrypting the database connection information.
Set the ./wallet.dat file created in the previous example to the ISQL_WALLET_PATH before starting tbSQL to be able to reuse the database connection information that was used before configuring the encrypted file.
The following illustrates how to access the database by using the file specified in ISQL_WALLET_PATH:
$ tbsql tbSQL 6 TmaxData Corporation Copyright (c) 2008-. All rights reserved. Connected to Tibero.
To use the encrypted file, it must be set in ISQL_WALLET_PATH. The encrypted file is only available in tbSQL.
To use the same file in another tbSQL instance, the encrypted file must be reconfigured using the aforementioned steps.
This function is not available in the Windows environment.
This section describes, in detail, the commands provided in tbSQL.
Following is the syntax for the tbSQL utility commands.
COM[MAND] param {choice1|choice2} [option] [arg]*
The following describes the special characters that define the command syntax:
Item | Description |
---|---|
Brackets ([ ]) | Optional argument. In the syntax, the [MAND], [option], and [arg] can be omitted. |
Curly braces ({ }) | Mutually exclusive argument where one is required. In the syntax, choice1 and choice2 are separated by (|) inside curly braces ({ }). One of the choices must be entered. |
Vertical bar (|) | OR operator. A separator for mutually exclusive arguments. |
Asterisk (*) | None or multiple argument values can be entered. In the syntax, [arg] with an asterisk (*) indicates that it can be excluded or entered multiple times. |
Italic letters | Must be replaced by another string depending on the command type. |
Case | Commands are not case-sensitive. |
The following are examples of valid commands.
COMMAND param choice1 COM param choice1 option COM param choice2 arg1 arg2 arg3
tbSQL includes commands for managing databases or processing SQL statements. The following describes the syntax, parameters, and example of each commands, in alphabetical order.
The following are the tbSQL commands.
Command | Description |
---|---|
! | Executes an OS command. Same as the HOST command. |
% | Re-executes the command saved in the history buffer. |
@, @@ | Executes a script file. Same as the START command. |
/ | Executes PSM programs or SQL statements that are saved in the SQL buffer. Same as the RUN command. |
ACCEPT | Receives user input and saves it in a specified substitution variable. |
ARCHIVE LOG | Displays redo log file information. |
CHANGE | Finds and replaces a specified pattern with a new pattern in the current line of the SQL buffer. |
CLEAR | Initializes or deletes the specified option. |
COLUMN | Specifies the display properties of a specified column. |
CONNECT | Connects to the database with a specified user ID. |
DEFINE | Defines or displays substitution variables. |
DEL | Deletes the line that is saved in the SQL buffer. |
DESCRIBE | Displays the column information of a specified object. |
DISCONNECT | Closes the connection to the current database. |
EDIT | Edits the contents of a SQL buffer or a certain file by using an external editor. |
EXECUTE | Executes a PSM statement. |
EXIT | Terminates tbSQL. Same as the QUIT command. |
EXPORT | Outputs SELECT statement results or table data to a file. |
HELP | Displays help. |
HISTORY | Displays command execution history. |
HOST | Executes an OS command. Same as the '!' command. |
INPUT | Adds a new line after the last line in the SQL buffer. |
LIST | Displays specified lines from the SQL buffer. |
LOADFILE | Saves a Tibero table in a format that can be recognized by Oracle SQL*Loader. |
LOOP | Infinitely repeats a statement. |
LS | Displays the database objects created by the current user. |
PASSWORD | Changes the user password. |
PAUSE | Pauses the execution until the user presses the <Enter> key. |
PING | Displays whether a specified database allows connections. |
Displays user-defined bind variables. | |
PROMPT | Displays a user-defined SQL or an empty line. |
QUIT | Terminates tbSQL utility. Same as the EXIT command. |
RESTORE | Restores the selected data from a file. |
RUN | Executes a PSM program or SQL statements that are saved in the SQL buffer. Same as the '/' command. |
SAVE | Saves the selected data to a file. |
SET | Sets the system variables of tbSQL. |
SHOW | Displays the system variables of tbSQL. |
SPOOL | Starts or terminates the process that saves all screen output to an external file. |
START | Executes a script file. Same as the @ command. |
TBDOWN | Terminates Tibero. |
UNDEFINE | Deletes one or more substitution variables. |
VARIABLE | Defines a user-defined bind variable. |
WHENEVER | Defines the actions to take when an error occurs. |
Executes an OS command in tbSQL. The HOST command can be used instead of this command.
The following is the syntax for the '!' command.
Syntax
! [command]
Option | Description |
---|---|
If only the '!' command is entered without an OS
command, the window will change to the OS command prompt
where multiple OS commands can be entered. To return to the tbSQL command prompt, enter the EXIT command. | |
command | OS command. |
Example
SQL> ! dir *.sql SQL> !
Re-executes the command stored in the tbSQL history buffer without re-entering it.
The following is the syntax for the '%' command.
Syntax
% number
Option | Description |
---|---|
number | Command number in the history buffer. |
Example
SQL> history 1: set serveroutput on 2: set pagesize 40 3: select 1 from dual; SQL> %3 1 ----------- 1 1 row selected.
Executes the script file. If the script file has the same file extension as the SUFFIX system variable, the extension can be omitted. tbSQL finds the specified script file in the current directory.
The system variable set using the SET command before executing the script remains in effect while executing the script. Use the EXIT or QUIT command in a script file to terminate tbSQL.
The START command can be used instead of the '@' command.
The following is the syntax for the '@' command.
Syntax
@ {filename}
Item | Description |
---|---|
filename | Script file name. |
Example
SQL> @ run SQL> @ run.sql
Executes PSM programs or SQL statements that are saved in the SQL buffer.
RUN command can be used instead of the '/' command.
The following is the syntax for the '/' command.
Syntax
/
Example
SQL> SELECT * FROM DUAL; ..... SQL statement execution result ..... SQL> / ..... The same result as above .....
Receives user input and saves it in a specified substitution variable. The specified value will automatically replace any string in a SQL statement or PSM program specified as &variable.
The following is the syntax for the ACCEPT command.
Syntax
ACC[EPT] variable [FOR[MAT] format] [DEF[AULT] default] [PROMPT statement|NOPR[OMPT]]
Input
Item | Description |
---|---|
variable | Substitution variable name. One will be created if it does not exist. |
Options
Option | Description |
---|---|
FOR[MAT] format | Format of the substitution variable. If the value does not match the format, an error occurs. |
DEF[AULT] default | Default value of the substitution variable. |
PROMPT statement | Display a prompt before receiving the value of a substitution variable from the user. |
NOPR[OMPT] | Wait for an input without displaying a prompt. |
Example
SQL> ACCEPT name PROMPT 'Enter name : ' Enter name : 'John' SQL> SELECT &name FROM DUAL; At line 1, column 8 old value : SELECT &name FROM DUAL new value : SELECT 'John' FROM DUAL 'JOHN' ------ John 1 row selected. SQL>
Displays redo log file information.
The following is the syntax for the ARCHIVE LOG command.
Syntax
ARCHIVE LOG LIST
Example
SQL> ARCHIVE LOG LIST
NAME VALUE
------------------------------- ------------------------------------------------
Database log mode Archive Mode
Archive destination /home/tibero/database/tibero/archive
Oldest online log sequence 300
Next log sequence to archive 302
Current log sequence 302
SQL>
Finds and replaces a specified pattern with a new pattern in the current line of the SQL buffer. Generally, the current line of the last executed SQL statement is the last line. Refer to the example below to change the current line.
The following is the syntax for the CHANGE command.
Syntax
C[HANGE] delim old [delim [new [delim [option]]]]
Input
Item | Description |
---|---|
delim | Delimiter excluding numbers. Characters used for a delimiter must not be included in either the old or new pattern. |
old | New pattern. This is not case-sensitive. Words, such as duala and ksc911, as well as ..., which indicates a random pattern, can be used. Refer to the following example. |
Options
Option | Description |
---|---|
delim | Delimiter excluding numbers. Characters used for delimiter must not be included in either old or new pattern. |
new | New pattern. |
option |
|
Example
Since the current line is always the last line by default, the DUAL on the second line is replaced with T.
SQL> SELECT * FROM DUAL; ..... SQL execution results ..... SQL> C/DUAL/T FROM T SQL>
To change the current line, enter a line number.
SQL> 5 5 WHERE ROWNUM < 5 AND
A random pattern can be specified by using ..., which can be placed in the front, back, or middle of a word.
SQL> CHANGE /RE...AND/RE ROWNUM >= 5 AND/ 5 WHERE ROWNUM >= 5 AND SQL> CHANGE /...AND/WHERE ROWNUM < 3/ 5 WEHRE ROWNUM < 3 SQL> CHANGE /WHE.../WHERE ROWNUM < 5 AND/ 5 WHERE ROWNUM < 5 AND
Use the 'a' option to replace any occurrences of the old pattern from the entire statement. The '*' character in the fist line is changed to the new pattern.
SQL> SELECT * FROM DUAL; ..... SQL execution results ..... SQL> C/*/'replaced'/a SELECT 'replaced' FROM DUAL; SQL>
Initializes or deletes the specified option.
The following is the syntax for the CLEAR command.
Syntax
CL[EAR] [option]
options
Option | Description |
---|---|
BUFF[ER] | Clear the SQL buffer. |
SCR[EEN] | Clear the screen. |
COL[UMNS] | Initialize the display properties of all columns. |
Example
SQL> CLEAR BUFFER SQL buffer is cleared SQL> CLEAR SCREEN SQL> CLEAR COLUMNS
Specifies the display properties of a specified column. When the column name is specified, only the display properties of the column is displayed. Otherwise, those of all columns are displayed.
The following is the syntax for the COLUMN command:
Syntax
COL[UMN] [name [option]]
Input
Item | Description |
---|---|
name | Column name. |
Options
Option | Description |
---|---|
CLE[AR] | Initialize the column's display properties. |
FOR[MAT] text | Set the column format. For more detailed information, refer to “1.7. Column Formats”. |
HEA[DING] text | Set the column heading. |
NEW_V[ALUE] variable | Set the variable to save the column value. |
WRA[PPED] | Wrap the text to the next line if the column data is too long. |
TRU[NCATED] | Truncate the data if the column data exceeds the limit. |
ON | Turn on the output property of the column. |
OFF | Turn off the output property of the column. |
Example
SQL> COLUMN SQL> COLUMN empno SQL> COLUMN empno CLEAR SQL> COLUMN empno FORMAT 999,999 SQL> COLUMN ename FORMAT A10 SQL> COLUMN sal HEADING the salary of this month SQL> COLUMN sal OFF SQL> COLUMN job WRAPPED SQL> COLUMN job TRUNCATED
Connects to the database with a specified user ID. If the user name or password is not specified, tbSQL prompts for the name or password.
The CONNECT command commits the last transaction, disconnects from the database, and then tries to reconnect. If the new connection attempt fails, the previous connection cannot be recovered.
The following is the syntax for the CONNECT command.
Syntax
CONN[ECT] {username[/password[@connect_identifier]]}
Input
Item | Description |
---|---|
username | User name. |
Options
Option | Description |
---|---|
password | Password of the user. |
connect_identifier | Database connection string. This option includes the IP, PORT, and DB_NAME information. It can be set in tbdsn.tbr of $TB_HOME/client/config directory, or Data Source (ODBC) in Windows. The latter is searched first. |
Example
SQL> CONNECT dbuser/dbuserpassword@db_id
Defines or displays substitution variables.
The following is the syntax for the DEFINE command.
Syntax
DEF[INE] [variable]|[variable = value]
Item | Description |
---|---|
When no substitution variable name is specified, all substitution variables are displayed. | |
variable | Substitution variable name. |
variable = value | Name and default value of the substitution variable. |
Example
SQL> DEFINE NAME ..... Outputs a substitution variable 'NAME'. ..... SQL> DEFINE NAME = 'SMITH' ..... Defines SMITH as a default value of the substitution variable..... SQL> DEFINE ..... Outputs all the substitution variables. .....
Deletes the line that is saved in the SQL buffer. If the line number is omitted, all lines will be deleted.
The following is the syntax for the DEL command.
Syntax
DEL [number|number number|number LAST|LAST]
Item | Description |
---|---|
number | Delete the line with the specified number. |
number number | Delete all lines in the specified range. |
number LAST | Delete all lines starting from the specified number to the last line. |
LAST | Delete the last line. |
Example
SQL> DEL 1 ..... Deletes the first line. ..... SQL> DEL 1 3 ..... Deletes all lines starting from the first line to the third line. ..... SQL> DEL 1 LAST ..... Deletes all lines starting from the first line to the last line. ..... SQL> DEL LAST ..... Deletes the last line. .....
Displays the column information of the specified object. An object can be a table, view, synonym, function, procedure, or package.
For tables and views, the column name, data type, constraint, index information, maximum length, precision, scale, etc. will be displayed.
For functions and procedures, parameter information (name, data type, IN/OUT) will be displayed. For packages, all details of the functions and procedures of the package will be displayed.
The column information about an object owned by a specified user can also be displayed. The name of the owner must be specified. Otherwise, the the current username will be used by default.
The following is the syntax for the DESCRIBE command.
Syntax
DESC[RIBE] [schema.]{object}
Item | Description |
---|---|
schema | Schema (or owner) that contains the target object. |
object | Object to display column information for. |
Example
SQL> DESCRIBE emp SQL> DESC scott.emp
Closes the connection to the current database. This command terminates the currently running transaction but does not terminate tbSQL.
When a transaction is terminated without being disconnected from the database, the transaction will continue to access to the database. For security, if a CONNECT command is included in a script file, it is recommended to execute the DISCONNECT command to terminate a transaction.
The following is the syntax for the DISCONNECT command.
Syntax
DISC[ONNECT]
Edits the contents of a SQL buffer or a certain file by using an external editor. An external editor can be specfied in the environment variable $TB_EDITOR.
If $TB_EDITOR is not set, this command references $EDITOR. If neither variables are set, vi editor is used. If the SQL buffer is empty, an error will be returned.
A file name can be specified without an extension if its extension is the default value. The default value of the SUFFIX system variable is .sql, and it can be changed using the SET command. tbSQL searches for the specified file in the current directory.
The following is the syntax for the EDIT command.
Syntax
ED[IT] [filename]
Item | Description |
---|---|
When EDIT command is executed without a file name, the contents saved in current SQL buffer will be opened for editing using the default file (.tbedit.sql). The default file will be deleted automatically when tbSQL terminates. | |
filename | Name of the file to edit (this is usually a script file name). |
Example
SQL> EDIT run.sql SQL> EDIT run SQL> ED
Processes a PSM statement, which includes only CALL statements and anonymous blocks. There must be a semicolon (;) at the end of the statement.
The following is the syntax for the EXECUTE command.
Syntax
EXEC[UTE] {statement}
Item | Description |
---|---|
statement | PSM statement. |
Example
SQL> EXECUTE begin dbms_output.put_line('success'); end; success PSM completed SQL> EXECUTE call proc1();
This command is also useful when allocating a value to a user-defined bind variable.
SQL> VAR x NUMBER; SQL> EXEC :x := 5; PSM completed SQL>
Terminates tbSQL. Commits all transactions being processed and terminates all connections to the database.
The following is the syntax for the EXIT command.
Syntax
EXIT [SUCCESS|FAILURE|WARNING|n|variable|:variable]
Item | Description |
---|---|
SUCCESS | Returns 0 to indicate a successful termination. |
FAILURE | Returns 1 to indicate a termination failure. |
WARNING | Returns 2 to indicate termination with warnings. |
n | Termination code of an integer value. Value range varies per OS. |
variable | Returns a user variable specified with the DEFINE command or a system variable like SQL.SQLCODE. The user variable must be set to a number. |
:variable | Sets the termination code using a bind variable specified with the VARIABLE command. The bind variable must be set to a number. |
COMMIT | Executes COMMIT before termination. |
ROLLBACK | Executes ROLLBACK before termination. |
Exports SELECT statement results or table data to a file with a format that tbLoader can recognize. Must use either a fixed or variable format that uses column and row separators.
The following is the syntax for the EXPORT command.
Syntax
EXP[ORT] {QUERY filename|TABLE [schema.]table} [variable_fmt|FIXED] variable_fmt: [FIELDS {TERM[INATED] BY {,|text}|ENCL[OSED] BY {"|text}}] [LINES TERM[INATED] BY {\n|text}]
Item | Description |
---|---|
filename | Name of the file to export. This name is used as the table name in the control file. |
[schema.]table | Name of the table to export. |
FIELDS ... | Column separator for variable format. |
LINES ... | Row separator for variable format. |
FIXED | Fixed format indicator. |
Example
The following example creates t.csv (data file) and t.ctl (control file).
SQL> EXPORT QUERY 't.csv' Ready to export to 't.csv' SQL> SELECT * FROM t; 10 rows exported.
Specify variable format as follows:
SQL> EXPORT QUERY 't.csv' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' SQL> EXPORT QUERY 't.csv' FIELDS ENCLOSED BY '*'
Outputs help for items that include a specified word.
The following is the syntax for the HELP command.
Syntax
H[ELP] [topic]
Item | Description |
---|---|
If not specified, all the commands available in tbSQL utility will be displayed. | |
topic | Search word to display help for. |
Example
SQL> HELP SET
Displays command execution history that is saved in the history buffer.
The following is the syntax for HISTORY command.
Syntax
HIS[TORY]
Example
SQL> HISTORY
..... Displays all commands. .....
This is same as the '!' command.
The following is the syntax for the HOST command.
Syntax
HO[ST] [command]
Item | Description |
---|---|
If only the HOST command is entered without an OS
command, the window will change to the OS command prompt
where multiple OS commands can be entered. To return to the tbSQL command prompt, enter the EXIT command. | |
command | OS command. |
Adds a new line after the last line in the SQL buffer.
The following is the syntax for INPUT command.
Syntax
I[NPUT] [statement]
Item | Description |
---|---|
If the statement option is omitted, multiple lines can be added to the last line in the buffer. | |
statement | SQL statement to add. |
Example
SQL> select * from dual; ..... Outputs result ..... SQL> LIST select * from dual SQL> INPUT where rownum < 2 select * from dual where rownum < 2 SQL>
The following is an example omitting the statement option. Unlike the previous example, the SQL statement will be executed as soon as it is entered.
SQL> select * from dual; ..... Outputs result ..... SQL> INPUT select * from dual ... Enter here. ...
Displays specified lines from the SQL buffer.
The following is the syntax for the LIST command.
Syntax
L[IST] [number|number number|number LAST|LAST]
Item | Description |
---|---|
Displays all the lines. | |
number | Displays the line that corresponds to the specified number. |
number number | Displays all lines from the first specified line to the second specified line. |
number LAST | Displays all lines from the first specified line to the last line. |
LAST | Displays the last line. |
Example
SQL> LIST 1 ..... Displays the first line. ..... SQL> LIST 2 3 ..... Displays all lines from the second line to the third line. ..... SQL> LIST 2 LAST .....Displays all lines from the second line to the last line. ...... SQL> LIST LAST .....Displays the last line. .....
Saves a Tibero table in a form that can be recognized by Oracle SQL*Loader.
The following is the syntax for LOADFILE command.
Syntax
LOAD[FILE] {filename}
Item | Description |
---|---|
filename | File name without a file extension. |
Example
Enter the following command to save the EMP table in the form that Oracle's SQL*Loader can recognize. This creates two files, emp.ctl and emp.dat.
SQL> LOADFILE emp SQL> select * from emp;
Infinitely repeats a statement. Enter <Ctrl>+C to terminate the loop.
The following is the syntax for the LOOP command.
Syntax
LOOP stmt
Item | Description |
---|---|
stmt | Statement to repeat. |
Example
SQL> LOOP select count(*) from v$session ..... SQL is executed every 1 second. ..... SQL> SET INTERVAL 10 SQL> LOOP ls ..... LS is executed every 10 seconds. .....
Displays the information about the database object, which is created by the current user, in a certain type or name.
The following is the syntax for the LS command.
Syntax
LS [object_type|object_name]
Item | Description |
---|---|
Outputs all the objects owned by the user. | |
object_type | One of:
|
object_name | Name of the object to display. The percent (%) sign can be used to indicate a temporary pattern. |
Example
SQL> LS NAME SUBNAME OBJECT_TYPE ------------------------------ ------------- -------------------- SYS_CON100 INDEX SYS_CON400 INDEX SYS_CON700 INDEX _DD_CCOL_IDX1 INDEX ......Omitted...... UTL_RAW PACKAGE DBMS_STATS PACKGE BODY TB_HIDDEN2 PACKGE BODY SQL> ..... Displays all objects. ..... SQL> LS TABLESPACE TABLESPACE_NAME ------------------------------ SYSTEM UNDO TEMP USR ..... Displays all objects of TABLESPACE type. ..... SQL> LS USER USERNAME ------------------------------ SYS ..... Inquires the users that are connecting to the system. .....
Changes the user password.
The following is the syntax for the PASSWORD command.
Syntax
PASSW[ORD] [username]
Item | Description |
---|---|
username | Username to change the password for. If not specified, the currently connected user is specified. |
Example
SQL> PASSWORD Changing password for 'TIBERO' Enter old password: ...Enter the current password... Enter new password: ...Enter a new password... Confirm new password: ...Re-enter the new password... Password changed successfully. SQL>
Holds the execution until the user presses <Enter> key. If a message is entered, it will be shown on the screen.
The following is the syntax for PAUSE command.
Syntax
PAU[SE] [message]
Item | Description |
---|---|
message | Message to display when the user presses the <Enter> key. |
Example
SQL> PAUSE please enter...
please enter...
..... Press the <Enter> key. .....
SQL>
Displays whether a specified database allows connections.
The following is the syntax for PING command.
Syntax
PING connect_identifier
Item | Description |
---|---|
connect_identifier | Name of the database to connect to. |
Example
SQL> PING tibero6 Server is alive. SQL>
Displays the value and name of user-defined bind variables.
The following is the syntax for the PRINT command.
Syntax
PRI[NT] [variable...]
Item | Description |
---|---|
Displays all the bind variables. | |
variable | List of the names of bind variables to display. |
Example
SQL> VARIABLE x NUMBER SQL> EXECUTE :x := 5; SQL> PRINT x x ---------- 5 SQL>
Displays a certain message or empty line.
The following is the syntax for the PROMPT command.
Syntax
PRO[MPT] [message]
Item | Description |
---|---|
Displays an empty line. | |
message | Message to show. |
Example
The following is an example of the externally written SQL file. The file name is PromptUsage.sql.
PROMPT >>> Test is started. CREATE TABLE T (c1 NUMBER); INSERT INTO T VALUES (1); PROMPT Value 1 is inserted. COMMIT; PROMPT <<< Test is ended.
The following illustrates the execution result of PromptUsage.sql.
SQL> @PromptUsage >>> Test is started. Table 'T' created. 1 row inserted. Value 1 is inserted. Commit succeeded. <<< Test is ended. File finished. SQL>
It is the same as the EXIT command.
The following is the syntax for the QUIT command.
Syntax
Q[UIT] [SUCCESS|FAILURE|WARNING|n]
Restores user selected data from a file.
The following is the syntax for the RESTORE command.
Syntax
REST[ORE] HIST[ORY] filename[.ext]
Item | Description |
---|---|
filename[.ext] | Name of the file to read from. If the file extension is omitted, the SUFFIX value is used. |
Example
SQL> RESTORE HISTORY history.sql
It is the same as the / command. However, this command displays the SQL statement saved in the SQL buffer.
The following is the syntax for the RUN command.
Syntax
R[UN]
Example
SQL> select 1 from dual; 1 ---------- 1 1 row selected. SQL> RUN 1 select 1 from dual 1 ---------- 1 1 row selected.
Encrypts the tbSQL utility's database access information and saves it in a file. For detailed information on this command, refer to “1.5.4. Encrypting Connection String”.
The following is the syntax for the SAVE CREDENTIAL command.
Syntax
SAVE CRED[ENTIAL] [filename] SAVE HIST[ORY] filename[.ext] [CRE[ATE]|REP[LACE]|APP[END]]
Item | Description |
---|---|
CREDENTIAL | Encrypts the database connection string. It the filename is omitted, it is saved in the file specified by ISQL_WALLET_PATH. |
HISTORY | Saves command history in the specified file. If the file extension is omitted, the SUFFIX value is used.
|
filename | File to save to. |
Example
SQL> SAVE CREDENTIAL SQL> SAVE CREDENTIAL "./wallet.dat" SQL> SAVE HISTORY history.sql SQL> SAVE HISTORY history.sql APPEND
Specifies the system variables of the tbSQL utility. The system variables specified by the SET command can be displayed by using the SHOW command. However, the changed system variable is valid only in the current session.
For a detailed description of each system variable, refer to “1.3. System Variables”.
The following is the syntax for SET command.
Syntax
SET {parameter} {value}
Item | Description |
---|---|
parameter | Name of tbSQL utility system variable. |
value | Value of tbSQL utility system variable. |
Example
SQL> SET AUTOCOMMIT ON
Displays the system variables of the tbSQL utility. Parameters can be used to select the information to be displayed. It is possible to display all the system variables.
The following is the syntax for SHOW command.
Syntax
SHO[W] {option}
option
The following table shows the items that can be entered in the option part and a description of each item.
Item | Description |
---|---|
system_parameter | Displays the tbSQL utility system variable which corresponds to the specified name. |
ALL | Outputs all the system variables of the tbSQL utility. |
ERROR | Displays PSM program errors which have occurred. |
PARAM[ETERS] [name] | Displays the database system variable that corresponds to the specified name. If the name is omitted, all the system variables will be displayed. |
RELEASE | Displays the release information of the tbSQL utility. |
Example
SQL> SHOW autocommit SQL> SHOW all SQL> SHOW error SQL> SHOW param db_name SQL> SHOW release
Saves all screen outputs to a file in the current directory. The HOST and ! commands are excluded.
The following is the syntax for the SPOOL command
Syntax
SPO[OL] [filename [APP[END]]|OFF]
Item | Description |
---|---|
When the SPOOL command is entered, the current process state of the SPOOL command will be displayed. | |
filename | Name of the file to save the output. |
APP[END] | Option to attach to the end of the output file. |
OFF | Stops saving output files. |
Example
SQL> SPOOL report.txt SQL> SPOOL OFF
It is the same as the @ command.
The following is the syntax for the START command.
Syntax
STA[RT] {filename}
Item | Description |
---|---|
filename | Script file name. |
Terminates Tibero. Users have four options to choose depending on the urgency. Some options require recovery process when rebooting the database.
To execute this command, access the database as SYSDBA or SYSOPER.
The following is the syntax for TBDOWN command.
Syntax
TBDOWN [NORMAL|POST_TX|IMMEDIATE|ABORT]
Item | Description |
---|---|
NORMAL | Waits until all the users terminate their access. (Default value) |
POST_TX | Waits until the transactions currently being processed are terminated. |
IMMEDIATE | Rolls back the transactions currently being processed, and then executes forced termination. |
ABORT | Terminates immediately without rolling back the transactions currently being processed. |
Example
SQL> TBDOWN SQL> TBDOWN ABORT
Deletes a substitution variable specified by the ACCEPT command.
The following is the syntax for UNDEFINE command.
Syntax
UNDEF[INE] [variable...]
Item | Description |
---|---|
If [variable...] is omitted, all substitution variables are deleted. | |
variable... | List of the substitution variable names. |
Example
SQL> UNDEFINE x SQL> UNDEFINE x y z
Defines user-defined bind variables that can be used in a PSM program or a SQL statement.
The following is the syntax for the VARIABLE command.
Syntax
VAR[IABLE] [variable [datatype]]
Item | Description |
---|---|
Displays all bind variables. | |
variable | Bind variable name. |
datatype | Options are:
|
Example
SQL> VARIABLE x NUMBER
SQL> EXEC :x := 1;
PSM completed.
SQL> SELECT :x FROM DUAL;
:x
----------
1
1 row selected.
SQL>
Defines the actions to be taken by tbSQL when an error occurs.
The following is the syntax for the WHENEVER command.
Syntax
WHENEVER {OSERROR|SQLERROR} {EXIT [SUCCESS|FAILURE|WARNING|n|variable|:variable] | CONTINUE [NONE|COMMIT|ROLLBACK]}
clause1
Item | Description |
---|---|
OSERROR | Performs the specified action for OS errors from the system on which tbSQL is running. |
SQLERROR | Performs the specified action for errors that occurs while executing SQL statements. This excludes tbSQL errors. |
clause2 (Default value: CONTINUE)
Item | Description |
---|---|
EXIT | Terminates the program when an error occurs. For return code, refer to the EXIT command. |
CONTINUE | Continue on to the next command even if an error occurs.
|
Example
SQL> whenever sqlerror exit failure rollback SQL> select 1 from no_such_table; TBR-8033: Specified schema object was not found. at line 1, column 16: select 1 from no_such_table $ echo exit code: $? exit code: 1 $
This section will describe how to specify the tbSQL utility's column format depending on the data type.
The column format of the tbSQL utility can be specified and displayed using the COLUMN command.
CHAR, NCHAR, VARCHAR, NVARCHAR types have the default value for the length of a database column. When the value of data is greater than the length of a column, the data can be cut. However, the character type column format can easily handle this problem.
The following is the syntax for specifying a character-type column format.
Syntax
COL[UMN] {name} FOR[MAT] A{n}
A can be replaced with a. n indicates the length of character type data.
Example
SQL> SELECT 'Tibero is the best choice' test FROM DUAL; TEST ------------------------- Tibero is the best choice 1 row selected. SQL> COL test FORMAT a10 SQL> SELECT 'Tibero is the best choice' test FROM DUAL; TEST ---------- Tibero is the best c hoice 1 row selected. SQL>
The following is the syntax for specifying a numeric-type column format.
Syntax
COL[UMN] {col_name} FOR[MAT] {fmt_str}
Input
Item | Description |
---|---|
col_name | Column name. |
fmt_str | Column formats described in the table below. |
fmt_str Format
The following table shows the formats that can be specified to the fmt_str.
Format | Example | Description |
---|---|---|
Comma (,) | 9,999 | Displays a comma (,) at the specified location. |
Period (.) | 9.999 | Displays a period (.) at the location to distinguish integer and decimal parts. |
$ | $9999 | Displays $ in the first place. |
0 | 0999, 9990 | Displays 0 in the last place. |
9 | 9999 | Displays the number according to the specified cipher (digit). |
B | B9999 | If the integer part is 0, it is replaced with a blank space. |
C | C9999 | Displays ISO currency symbol at the specified location. |
D | 9D999 | Displays a decimal character to separate the integer and decimal parts of a real number. |
EEEE | 9.99EEEE | Displays scientific notation. |
G | 9G999 | Displays a group separator at the specified location of the integer part. |
L | L9999 | Displays the local currency symbol at the specified location. |
MI | 9999MI | Displays a minus sign at the end of a negative number. Displays a blank space at the end of a positive number. |
PR | 9999PR | Displays a negative number surrounded by '<' and '>' (angle brackets), and positive number surrounded by blank spaces. |
RN | RN | Displays as uppercase roman numeral. |
rn | rn | Displays as lowercase roman numeral. |
S | S9999, 9999S | Displays the positive/negative sign at the first or last place. |
TM | TM | Displays the smallest number. |
U | U9999 | Displays dual currency symbol at the specified location. |
V | 99V999 | Displays the value multiplied by 10n. n is the number of 9 that comes after V. |
X | XXXX, xxxx | Displays in hexadecimal format. |
Example
SQL> COLUMN x FORMAT 999,999 SQL> SELECT 123456 x FROM DUAL; X -------- 123,456 1 row selected.