Table of Contents
This chapter describes the tbSQL utility and its usage.
tbSQLis an interactive utility provided by Tibero to process SQL statements. This tbSQL utility can process SQL queries, Data Definition Language (hereafter DDL), and SQL statements related to transactions. It can also be used to create and execute PSM programs, and DBAs can execute commands to manage the Tibero system.
Besides these basic functions, tbSQL provides many other functions such as; setting auto commit, executing commands that are related to the OS, saving output, writing scripts, etc. The script writing function enables you to create many SQL statements, PSM programs, and tbSQL utility commands into a single script file. It is a very convenient function.
Among the Tibero utilities, tbSQL is one of the most frequently used utilities. tbSQL provides the following functions in addition to executing SQL statements.
Input, edit, save, and execute general SQL statements and tbSQL programs.
Set 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 utility is installed automatically when installing the Tibero. If you remove Tibero, tbSQL utility will also be removed.
The following example illustrates how to execute the tbSQL utility.
[Example 1.1] Executing tbSQL utility
$ tbsql tbSQL 5 SP1 Copyright (c) 2001-2011 TmaxData Corporation. All rights reserved. SQL>
When tbSQL is executed normally, a SQL prompt as shown above will appear. Database users can execute SQL statements to this prompt.
The following is the syntax of commands that execute the tbSQL utility.
tbsql [[options]|[connect_string]|[start_script]]
The following options are valid entries for the options parameter.
Option | Description |
---|---|
-h, --help | Shows the Help screen. |
-v, --version | Shows the version. |
-s, --silent | Does not show the start message and prompt on the screen. |
-i, --ignore | Does not show the log-on script (tbsql.logon). |
connect_string contains the user account information for Tibero. It is specified as follows:
username[/password[@connect_identifier]]
The following options are valid entries for the connect_string parameter.
Option | Description |
---|---|
username | Specifies a user name. It is not case-sensitive; however, when the username is inserted in double quotes(" "), it is case sensitive. |
password | Specifies a user password. It is case-sensitive. |
connect_identifier | Specifies the DSN (Data Source Name) which contains access information of the database. |
start_script sets the script files that will be executed when tbSQL utility starts. It is specified as follows:
@filename[.ext]
The following options are valid entries for the start_script parameter.
Option | Description |
---|---|
filename | Name of the file. |
ext | Extension of the file. If extension is not specified, the default value, set in FILEEXT system variable, will be used. |
When the SQL prompt appears after executing the tbSQL utility, users can access the database.
If there are any tasks that should be processed before starting the database session, write 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.
See the following for the method of accessing a database using the tbSQL utility.
[Example 1.2] Accessing Database by using the tbSQL Utility
$ tbsql SYS/syspassword tbSQL 5 SP1 Copyright (c) 2001-2011 TmaxData Corporation. All rights reserved. Connected. SQL>
In the previous example, a username and password are entered at the UNIX shell prompt, when tbSQL starts.
Rules for entering a username and password are as follows:
Item | Description |
---|---|
Username | Specifies a user name. It is not case-sensitive; however, when the user name is inserted in double quotes (" "), it is case sensitive. |
Password | Specifies a password. It is case-sensitive. |
If connect_identifier is omitted, similar to [Example 1.2], the default database is accessed. To access a specific database, specify connect_identifier in one of the following methods.
DSN (Data Source Name)
Specify a name that is defined in tbdsn.tbr or Data Source (ODBC) in Windows.
The following is an example of tbdsn.tbr.
tibero5=( (INSTANCE=(HOST=192.168.36.42) (PORT=8629) (DB_NAME=tibero5) ) )
The following is an example of using a tbdsn.tbr file.
$ tbsql tibero/tmax@tibero5
Connection specifications
Connection information can be manually specified with the following two methods (without using a tbdsn.tbr file).
Method 1
(INSTANCE=(HOST=host)(PORT=port)(DB_NAME=dbname))
The following is an example.
$ tbsql 'tibero/tmax@(INSTANCE=(HOST=192.168.36.42)(PORT=8629) (DB_NAME=tibero5))'
Method 2
host:port/dbname
The following is an example.
$ tbsql 'tibero/tmax@192.168.36.42:8629/tibero5'
The following example shows the execution of a tbSQL utility.
$ tbsql tbSQL 5 SP1 Copyright (c) 2008, 2009, 2011, 2012 TmaxData Corporation. All rights reserved. SQL> CONNECT dbuser Enter password : dbuserpassword Connected to Tibero. SQL>
In the previous example, after executing tbSQL utility, it accesses the database using the username 'dbuser' and the CONNECT command. The tbSQL utility receives the input in text format, and displays the result when the user requests it.
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.
tbSQL utility is executed by an interface that has the following features.
When tbSQL utility is executed normally, a SQL prompt is displayed.
At the SQL prompt, it is possible to input SQL statements, PSM programs, and tbSQL utility commands.
It can be entered over several lines.
SQL statements and PSM programs are not executed when they are entered. However, a tbSQL utility command is executed when it is entered.
Case insensitive.
All interfaces are case insensitive, with some exceptions, such as a string data in SQL statements.
For example, the following two statements will execute identically.
SQL> SET AUTOCOMMIT ON SQL> set autocommit on
To set the configuration environment of the tbSQL utility, the SET command is used. By using the SET command, users can configure the output format of a SQL query result, the transaction commit option, etc.
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 the tbSQL utility, enter the EXIT or QUIT command at the SQL prompt.
SQL> EXIT
For detailed information about the commands provided from tbSQL utility, refer to “1.6. Command ”.
This section describes the system variables of the tbSQL utility. Use the SET command to configure values for the system variables of the tbSQL utility, and use the SHOW command to display the results.
Following table is the summary of system variables that can be configured for the SET command.
System Variables | Default Value | Description |
---|---|---|
AUTOCOMMIT | OFF | Specifies the status of the AUTOCOMMIT option. |
AUTOTRACE | OFF | Specifies whether to display the statistical or plan information for the query being processed. |
BLOCKTERMINATOR | "." (0x2E) | Specifies a character to indicate the end of a PSM statement input. |
COLSEP | OFF | Specifies a column separator character string to be printed between the selected columns. |
CONCAT | "." (0x2E) | Specifies a character that indicates that a character string is appended to a substitution variable. |
DDLSTATS | OFF | Specifies whether to show the statistical or plan information for the DDL statement being processed. |
DEFINE | "&" | Specifies the character to be used when defining a substitution variable. |
ECHO | OFF | Specifies whether to list each query in a script file as it is being executed using an @ or the START command. |
EDITFILE | ".tbedit.sql" | Specifies the default value of a filename that is to be used with the EDIT command. |
ESCAPE | OFF | Specifies the escape character. |
EXITCOMMIT | ON | Specifies whether to commit when terminating a utility. |
FEEDBACK | 0 | Specifies whether to display the SQL statement result on the screen. |
FILEEXT | "sql" | Specifies the file extension to be used when the extension is omitted. |
FILEPATH | "" | Specifies the file path to be used when the path is omitted. |
HEADING | ON | Specifies whether to display column headers when displaying query execution results. |
HISTORY | 50 | Specifies the size of the command history. |
LINESIZE | 80 | Specifies the length of a line shown on the screen. |
LONG | 80 | Specifies the length of the CLOB type data to be displayed. |
NUMFORMAT | "" | Specifies the default column format of number type data. |
NUMWIDTH | 10 | Specifies the size of numeric data that is displayed from the DBMS_OUTPUT package. |
PAGESIZE | 24 | Specifies the number of lines to display on each output page. |
PAUSE | OFF | Specifies whether to wait for user input before displaying the next page. |
SERVEROUTPUT | OFF | Specifies whether to display the result of the DBMS_OUTPUT package. |
SQLPROMPT | "SQL> " | Specifies the prompt character string on the screen (same as PROMPT). |
SQLTERMINATOR | ";" (0x3B) | Specifies a character for terminating an SQL statement. |
TERMOUT | ON | Specifies whether to display the result of executing a command, using a script, on the screen. |
TIME | OFF | Specifies whether to display the current time at the prompt. |
TIMEOUT | 3 | Specifies how long to wait for a server response to a PING command. (Unit: seconds) |
TIMING | OFF | Specifies whether to display the processing time when the SQL and PSM statements are displayed. |
TRIMOUT | ON | Specifies whether to truncate spaces at the end of each line, every time execution results of SQL, PSM statements are displayed. |
TRIMSPOOL | OFF | Specifies whether to truncate spaces at the end of each line, every time execution results of SQL, PSM statements are spooled. |
VERIFY | ON | Specifies whether to display the details of a SQL command before and after replacing substitution variables with values. |
WRAP | ON | Specifies whether to display the rest of the results on the following line, or only display up to the LINESIZE, when the displayed result is longer than the specified LINESIZE. |
The following illustrates how to specify the system variables.
SET AUTOCOMMIT ON SET PAGESIZE 32 SET TRIMSPOOL ON
Specifies the automatic commit option after processing SQL statements, e.g. INSERT, DELETE, UPDATE, etc.
The following is the syntax of AUTOCOMMIT.
syntax
SET AUTO[COMMIT] {ON|OFF}
Item | Description |
---|---|
ON | Enables AUTOCOMMIT. |
OFF | Disables AUTOCOMMIT. This is the default value. When it is set to OFF, you must commit changes manually. |
Shows the statistical or plan information for a query being processed. DBA or PLUSTRACE permissions are required to use AUTOTRACE. PLUSTRACE contains the authorities required for AUTOTRACE. A user with the DBA authority can generate the PLUSTRACE authority and can 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] {OFF|ON|TRACE[ONLY]} [EXP[LAIN]] [STAT[ISTICS]] [PLANS[TAT]]
Item | Description |
---|---|
OFF | Does not display the statistical or plan information. This is the default value. |
ON | Displays the statistical or plan information based on the result and additional options. |
TRACE[ONLY] | Does not display the query result and displays the statistical or plan information based on the result and additional options. |
The following options specify whether to show the statistical or plan information.
Option | Description |
---|---|
If unspecified, displays both plan and statistical information. | |
EXP[LAIN] | Displays the plan information. |
STAT[ISTICS] | Displays the statistical information. |
PLANS[TAT] | Displays process information (process time, the number of processed rows, process count, etc.) of queries by node. |
Specifies a character to indicate the end of tbPSM statement input.
The following is the syntax for BLOCKTERMINATOR.
Syntax
SET BLO[CKTERMINATOR] {c|ON|OFF}
Item | Description |
---|---|
c | Specifies a character to indicate the end of a PSM program input. The default value is ".". |
ON | Enables a PSM termination character. |
OFF | Disables a PSM termination character. |
Specifies a column separator character to be printed between the selected columns.
The following is the syntax for COLSEP.
Syntax
SET COLSEP {text}
Item | Description |
---|---|
text | Specifies a column separator character string. The default character is " ". |
Specifies a character that indicates that a character string is appended to a substitution variable.
The following is the syntax for CONCAT.
Syntax
SET CON[CAT] {c|ON|OFF}
Item | Description |
---|---|
c | Specifies a character that indicates that a character string is appended to a substitution variable. The default character is ".". |
ON | Enables CONCAT. |
OFF | Disables CONCAT. |
Specifies whether to show the statistical or plan information of the DDL statement being processed. To use this system variable, AUTOTRACE must also be activated.
The following is the syntax for DDLSTATS.
Syntax
SET DDLSTAT[S] {OFF|ON}
Item | Description |
---|---|
OFF | Enables DDLSTATS. This is the default value. |
ON | Disables DDLSTATS. |
Specifies the character to be used when defining a substitution variable.
The following is the syntax for DEFINE.
Syntax
SET DEF[INE] {OFF|ON}
Item | Description |
---|---|
c | Specifies a character that indicates a substitution variable. The default character is "&". |
OFF | Disables DEFINE. |
ON | Enables DEFINE. This is the default value. |
Specifies whether to list each query in a script file as it is being executed using an @ or the START command.
The following is the syntax for ECHO.
Syntax
SET ECHO {OFF|ON}
Item | Description |
---|---|
OFF | Disables ECHO. This is the default value. |
ON | Enables ECHO. |
Specifies the default value of a filename that is to be used with the EDIT command. When omitting the extension, use the value specified in FILEEXT.
The following is the syntax for EDITFILE.
Syntax
SET EDITF[ILE] filename[.ext]
Item | Description |
---|---|
filename[.ext] | Filename that is to be used with the EDIT command. By default, it is set to .tbedit.sql. |
Specifies the character used as the escape character. After enabling ESCAPE, if the specified escape character is attached in 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 | The escape character. |
ON | Enables ESCAPE. |
OFF | Disables ESCAPE. This is the default value. |
Specifies whether to commit when terminating a utility.
The following is the syntax for EXITCOMMIT.
Syntax
SET EXITC[OMMIT] {ON|OFF}
Item | Description |
---|---|
ON | Enables EXITCOMMIT. This is the default value. |
OFF | Disables EXITCOMMIT. |
Specifies whether to display the SQL statement result on the screen.
The following is the syntax for FEEDBACK.
Syntax
SET FEED[BACK] {ON|OFF}
Item | Description |
---|---|
ON | Enables FEEDBACK. This is the default value. |
OFF | Disables FEEDBACK. |
Specifies the file extension to be used when the extension is omitted.
The following is the syntax for FILEEXT.
Syntax
SET FILEE[XT] {file_extension}
Item | Description |
---|---|
file_extension | File extension to be used by default, initially set to .sql. |
Specifies the file path to be used when the path is omitted.
The following is the syntax for FILEPATH.
Syntax
SET FILEP[ATH] {file_path}
Item | Description |
---|---|
file_path | File path to be used by default, initially set to the current directory. |
Specifies whether to display column headers when displaying query execution results.
The following is the syntax for HEADING.
Syntax
SET HEA[DING] {ON|OFF}
Item | Description |
---|---|
ON | Enables HEADING. This is the default value. |
OFF | Disables HEADING. |
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. By default, it is set to 50. |
ON | Enables HISTORY. This is the default value. |
OFF | Disables HISTORY. |
Specifies the length of a line shown 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 shown on the screen. By default, it is set to 80. |
Specifies the display 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 data. By default, it is set to 80. |
Specifies the default column format of number type data. This applies to number type columns, not to columns with FORMAT defined by the COLUMN command.
The following is the syntax for NUMFORMAT.
Syntax
SET NUMF[ORMAT] {fmt_str}
Item | Description |
---|---|
fmt_str | The default column format of number type data. The default value is "". For more information about the number type, refer to “1.7. Column Format ”. |
Specifies the size of result to display. This value must not exceed the size specified in LINESIZE.
The following is the syntax for NUMWIDTH.
Syntax
SET NUM[WIDTH] {n}
Item | Description |
---|---|
n | Default output length of data that is generated from DBMS_OUTPUT package. By default, it is set to 10. |
Specifies the number of lines to print on each output page from the tbSQL utility.
The following is the syntax for PAGESIZE.
Syntax
SET PAGES[IZE] {n}
Item | Description |
---|---|
n | Number of lines per page. By default, it is set to 24. |
Specifies whether to wait for user input before displaying the next page.
The following is the syntax for PAUSE.
Syntax
SET PAUSE {ON|OFF}
Item | Description |
---|---|
ON | Enables PAUSE. |
OFF | Disables PAUSE. This is the default value. |
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 | Enables SERVEROUTPUT. |
OFF | Disables SERVEROUTPUT. This is the default value. |
n | Specifies the SERVEROUTPUT buffer size. The default value is 1000000. |
Specifies the prompt character string on the screen.
The following is the syntax for SQLPROMPT.
Syntax
SET SQLP[ROMPT] {prompt_string}
Item | Description |
---|---|
prompt_string | Character string to be used as a prompt. The default value is 'SQL>'. If the character string is wrapped by 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. By default, it is set to ";". |
ON | Enables SQLTERMINATOR. |
OFF | Disables SQLTERMINATOR. |
Specifies whether to display the result of command, executed using a script, on the screen.
The following is the syntax for TERMOUT.
Syntax
SET TERM[OUT] {ON|OFF}
Item | Description |
---|---|
ON | Enables TERMOUT. This is the default value. |
OFF | Disables TERMOUT. |
Specifies whether to display the current time on the prompt.
The following is the syntax for TIME.
Syntax
SET TI[ME] {ON|OFF}
Item | Description |
---|---|
ON | Enables TIME. |
OFF | Disables TIME. This is the default value. |
Specifies the period of time to wait for a server response to a PING command.
The following is the syntax for TIMEOUT.
Syntax
SET TIMEOUT {n}
Item | Description |
---|---|
n | Period of time to wait for a server response. The unit is second. By default, it is set to 3 seconds. |
Specifies whether to display the processing time when the SQL and PSM statements are displayed.
The following is the syntax for TIMING.
Syntax
SET TIMI[NG] {ON|OFF}
Item | Description |
---|---|
ON | Enables TIMING. |
OFF | Disables TIMING. This is the default value. |
Specifies whether to truncate spaces at the end of each line, every time execution results of SQL, PSM statements are displayed.
The following is the syntax for TRIMOUT.
Syntax
SET TRIM[OUT] {ON|OFF}
Item | Description |
---|---|
ON | Enables TRIMOUT. This is the default value. |
OFF | Disables TRIMOUT. |
Specifies whether to truncate spaces at the end of each line, every time execution results of SQL, PSM statements are spooled.
The following is the syntax for TRIMSPOOL.
Syntax
SET TRIMS[POOL] {ON|OFF}
Item | Description |
---|---|
ON | Enables TRIMSPOOL. |
OFF | Disables TRIMSPOOL. This is the default value. |
Specifies whether to display the details of a SQL command before and after replacing substitution variables with values.
The following is the syntax for VERIFY.
Syntax
SET VER[IFY] {ON|OFF}
Item | Description |
---|---|
ON | Enables VERIFY. This is the default value. |
OFF | Disables VERIFY. |
When the result is longer than the specified LINESIZE, it specifies whether to display the rest of the result on the following line, or only display up to the LINESIZE.
The following is the syntax for WRAP.
Syntax
SET WRA[P] {ON|OFF}
Item | Description |
---|---|
ON | Enables WRAP. This is the default value. |
OFF | Disables WRAP. |
tbSQL utility is mainly used for executing SQL statement or PSM program that is entered manually. This section will first explain how to use the basic functions, and then the other functions.
SQL statement, PSM program, and tbSQL utility command are the three commands that can be entered in a command prompt of the tbSQL utility. To enter each command, users can use similar methods.
The following item explains about how to enter each command.
How to enter SQL statement.
General SQL Statement Entry
In general, a SQL statement is entered in the prompt of tbSQL utility. One SQL statement can be entered over several lines. To stop SQL statement entry, users should enter a blank line.
Changing Lines
When entering a SQL statement over several lines, users can change the lines at any place they want, except the string. Usually, it is preferred to cut the statement at the clause, because it is easy to read and modify.
Inserting Comments
Users can insert comments in the middle of SQL statement. Comment is inserted by using two minus signs (--) and continues to the end of the line. Comment can form a line by itself. It can also be placed behind a string in the middle of a line.
Using the Previously Saved Statements
Once a SQL statement is entered, it is saved in the SQL buffer of tbSQL utility. Therefore, users can use the saved statement when entering the same or similar SQL statement. When changing the saved SQL statement, it will be treated as a new statement thus be saved in the SQL buffer.
In the SQL buffer, a SQL statement or PSM program is saved. Depending on the OS, keyboard's UP (↑) key or DOWN (↓) key can be used to select the saved statement. One line of statement appears every time the key is pressed. Therefore, users can call not only one but all SQL statements saved in the buffer.
The following example illustrates how to enter a SQL statement in tbSQL utility.
SQL> SELECT ENAME, SALARY, ADDR FROM EMP -- this is a comment. WHERE DEPTNO = 5; SQL>
PSM program is consisted of multiple SQL statements or PSM statements. Each SQL statement is finished with a semicolon (;). When users start entering the PSM program, tbSQL utility will be automatically converted to PSM program input mode. In the PSM program input mode, SQL statements will not be executed after SQL statements are all entered.
The following statements are the ones that convert tbSQL utility to PSM program input mode. One is anonymous block such as DECLARE, BEGIN, etc., and the other is CREATE (OR REPLACE) PROCEDURE, FUNCTION, and TRIGGER that create procedure, function, and trigger.
Method of entering PSM programs is similar to the way of entering SQL statements.
How to enter PSM programs.
General PSM Program Entry
PSM programs can be entered over several lines. To stop SQL statement entry, users should enter a blank line. However, to cancel PSM program entry, users should enter a character (BLOCKTERMINATOR) that indicates the termination of block. By default, the character is set to PERIOD (.). The block termination character should be entered in a line alone. There should be no other string in the corresponding line.
Using the Previously Saved Statements
Entered program is saved in the SQL buffer thus can be used again.
Inserting Comments
Comments are entered in the same way as those of SQL statements.
The following example illustrates how to enter an anonymous block in tbSQL utility.
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 example above, you will be able to see an inserted comment line and also a period (.) under the END statement which terminates the PSM program entry. The last line contains only the block termination character (in this example, it is a period) without any other character or string.
For the detailed information about PSM usage, refer to "Tibero PSM Guide".
tbSQL utility command contains the commands to perform SQL or manage Tibero database. For more detailed information about tbSQL utility command, refer to “1.6. Command ”.
There are 3 ways to execute a command that is entered in command prompt of the tbSQL utility.
Executing PSM program or SQL statement saved in a SQL buffer
SQL buffer has only one of the latest SQL statements or PSM programs. To execute this SQL statement or tbPSM program, enter RUN or / command.
Executing a SQL statement
Enter the whole statement and put a semicolon (;) at the end to execute SQL statement.
Executing SQL statement at the same time it is saved in SQL buffer
To execute the SQL statement or PSM program at the same time it is saved, enter the / command. At this time, / command should exist alone in a line just like the period (.) tbSQL command does not provide any special command to execute a SQL statement or a PSM program. It is not saved in the SQL buffer. tbSQL utility command is executed at the same time it is entered.
tbSQL command does not provide any special command to execute a SQL statement or a PSM program. It is not saved in the SQL buffer. tbSQL utility command is executed at the same time it is entered.
The following example illustrates how to execute a SQL statement that is saved in SQL buffer.
SQL> SELECT ENAME, SALARY, ADDR FROM EMP -- this is a comment. WHERE DEPTNO = 5; ......Execution result ①...... SQL> / ......Execution result ②...... SQL>
In the first SQL prompt, SQL statement is entered and then the entry is finished with a semicolon (;) to be executed right away. In the second SQL prompt, the / command is entered to execute the SQL statement saved in SQL buffer. SQL buffer has the latest SQL statement thus the SQL statement entered in the first SQL prompt will be executed. Consequently, execution result ① and ② will have the same output.
The following example illustrates how to execute the above SQL statement using slash (/) command. Users should not add a semicolon (;) 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 the output. These are the most commonly used functions in the tbSQL utility.
Comments can be inserted in the following two ways.
Using /* … */
Users can use /* … */ in the same way as it is used in C or C++ programing language. tbSQL utility will treat the parts enclosed by /* and */ as a comment.
This comment cannot be nested. In other words, /* … */ cannot contain another /* … */ inside.
Using Two Minus Signs (--)
When two minus signs (--) are used, tbSQL utility will treat those from (--) to the end of the corresponding line as a comment.
This comment can be placed anywhere using /* … */, except the line which has a period to indicate termination of PSM program entry.
Therefore, the script file as below will cause an error.
(PSM Program)
.-- wrong comment
RUN
The content submitted in a SQL statement does not update the database until the transaction is committed. One transaction usually consists of several SQL statements.
In the tbSQL utility, users can specify the AUTOCOMMIT parameter to ON or OFF. By default, it is set to OFF.
The SET AUTOCOMMIT command is used to specify whether to perform the commit automatically or not. To check the current setting, use SHOW AUTOCOMMIT command.
To execute the OS command when tbSQL utility has started, enter HOST command.
The following example illustrates how to list all script files with .sql extension. Users can use the ! command instead of the HOST command.
SQL> HOST dir *.sql
..... OS command execution result .....
SQL>
After executing the OS command, another tbSQL utility prompt will appear. Users can continue to enter other tbSQL utility commands.
If you omit the statement that comes after HOST or ! command, the OS command prompt will appear. To return to tbSQL utility, enter EXIT.
SQL> !
$ dir *.sql
..... OS command execution result .....
$ EXIT
SQL>
To save all the content that is entered in and generated from the tbSQL utility, as a text file, use the SPOOL command. The SPOOL command is used to save the user-entered SQL statement or PSM program, tbSQL utility command, query result, program execution result, and tbSQL prompt.
If you execute the SPOOL command, it will start saving from the next line. To stop this function, enter SPOOL OFF. The lines following the SPOOL OFF command will not be saved.
The following example illustrates how to use the SPOOL command. If the save.txt file, which is used in SPOOL command, already exists, the new file will replace the old file and the old file will disappear.
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 shows the contents saved in save.txt file from the example above.
SQL> SELECT * FROM DUAL; DUMMY ----- X 1 row selected. SQL> SPOOL OFF
The user-entered SQL statement, query result, and commands up to the SPOOL OFF command, are saved in the file.
This section describes the advanced functions of the tbSQL utility. One of the functions is 'batch processing' performed using a script, and the other is processing DBA functions for managing the Tibero system.
The Script is a group of SQL statements, PSM programs, and tbSQL utility commands used to perform batch processing. When the script is executed in the tbSQL utility, all the commands in the script will be executed in order.
A Script file can be created and edited externally, and then executed in the tbSQL utility. Or users can execute tbSQL utility first and then create and edit the script by calling an external editor. When users call an external editor, they can specify which editor to use.
The following example illustrates how to use vi using an external editor.
$ export TB_EDITOR=vi
To edit a certain script file using an external editor, use the EDIT command. Users should specify the file name by using the EDIT command. The file extension can be omitted if the extension is the same as the FILEEXT system variable.
The following example illustrates how to call an external editor to edit the script file, run.sql.
SQL> EDIT run
Users can enter a SQL statement,PSM program, and tbSQL command into a script file using the following methods:
General Entry
The method is almost same as that for entering a command prompt in the tbSQL utility. It can be entered over several lines.
Terminating a SQL Statement and PSM Program
SQL statements must have a semicolon (;) at the end of the statement. PSM programs must have a period (.) in the last line.
Inserting a Comment
Comments can be inserted into the script file.
When a script is executed, SQL statements will be executed immediately. A PSM program will be executed after entering the RUN or / command.
The following example shows a script file which performs several tasks in the table EMP. Blank space is 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. When using these commands, you should specify a file name. The file extension can be omitted if the extension is the same as FILEEXT system variable (sql).
The following example illustrates how to execute a script file, run.sql. The results will be the same.
SQL> START run SQL> @run
One or more script files can be executed in a single script file. Script file can contain START or @ command. Make sure not to have an infinite loop when executing a script file recursively.
When @ command is used to start the tbSQL utility, a script file is created and started at the same time. This is useful when executing a batch program in the OS.
The following example illustrates how to run a script file, run.sql, at the same time as the tbSQL utility is started.
$ tbsql dbuser/dbuserpassword @run
Or a redirection shell command can be used to run a script:
$ tbsql dbuser/dbuserpassword < run.sql
Users can process DBA functions with tbSQL utility. To do so, login to Tibero as a user who has the DBA authority.
The following example illustrates how to log in as a SYS user who has DBA authority.
$ tbsql sys/syspassword
You can connect to a database as a DBA even after starting the tbSQL utility. Users should use the CONNECT command. Connect to the database as a user who has DBA authority.
The following example illustrates how to connect to the database as a DBA using the CONNECT command.
SQL> CONNECT sys/syspassword
What the DBA function can do with the tbSQL utility.
Terminating Tibero
A user who has DBA authority can terminate Tibero using TBDOWN, the tbSQL command.
Replacing a User-Entered Value
A token that starts with & in a query will be replaced by what the user entered. This function is very useful when you are repeatedly using a query, where only some part of the query changes.
The tbSQL utility saves database access information(connect_string) with the wallet.dat file
The information in the database, which the tbSQL
After accessing a database using the tbSQL utility, the user can create an encrypted file using the SAVE CREDENTIAL command.
The following example illustrates how to encrypt the database information by specifying ISQL_WALLET_PATH to have a wallet.dat file in the current directory.
$ export ISQL_WALLET_PATH=./wallet.dat $ tbsql tbSQL 5 SP1 Copyright (c) 2008, 2009, 2011, 2012 TmaxData Corporation. 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.
ISQL_WALLET_PATH is specified before executing tbSQL
Users should connect to the database again and create a ./wallet.dat file using SAVE CREDENTIAL command.
The following example illustrates how to encrypt information from databases accessed by the user in the wallet.dat file of the current directory, without setting the environment variable of ISQL_WALLET_PATH.
$ tbsql tbSQL 5 SP1 Copyright (c) 2008, 2009, 2011, 2012 TmaxData Corporation. All rights reserved. SQL> CONN dbuser/dbuserpassword Connected to Tibero. SQL> SAVE CREDENTIAL "./wallet.dat" Complete to generate the wallet file.
When a ./wallet.dat file is specified by using SAVE CREDENTIAL, the information from the database will be encrypted and a ./wallet.dat will be created.
By specifying the ./wallet.dat file, which is created in the ISQL_WALLET_PATH before the tbSQL utility is executed, the user can use the information in the database, before the encrypted file is created.
The following example illustrates how to access a database by using the file specified in ISQL_WALLET_PATH.
$ tbsql tbSQL 5 SP1 Copyright (c) 2008, 2009, 2011, 2012 TmaxData Corporation. All rights reserved. SQL> CONN dbuser/dbuserpassword Connected to Tibero.
To use the encrypted file the ISQL_WALLET_PATH must be specified. The encrypted file is only available in the tbSQL utility. To use the same file in other tbSQL utilities, a user should create an encrypted file first. This function is not available in the Windows environment.
This section will describe, in detail, the commands that are provided in the tbSQL utility.
Following example shows the syntax for the tbSQL utility commands.
COM[MAND] param {choice1|choice2} [option] [arg]*
The following table shows the syntax descriptions.
Item | Description |
---|---|
Brackets ([ ]) | The contents in brackets ([]) can be executed even though
they are not entered. The (MAND) part, option, and arg may be excluded in the command prompt. |
Curly braces ({ }) | The contents in curly braces ({}) must be entered to be executed. In the example above, choice1 and choice2 are divided by a vertical bar (|) within curly braces ({ }). Either of the two must be included in the command prompt. |
Vertical bar (|) | It is used as an OR operator. When two items are divided by a vertical bar (|), it means either of the two will be selected. |
Asterisk (*) | Contents that have asterisk (*) sign may be excluded or can
be included many times in the command prompt. In the example above, [arg] has an asterisk (*) sign, thus it may be excluded or can be included many times. |
Italic letters | Contents that are written in italic letters should be replaced by another string, depending on the command. |
Case | Commands are not case-insensitive. |
The following is an example of valid commands.
COMMAND param choice1 COM param choice1 option COM param choice2 arg1 arg2 arg3
tbSQL utility command has the commands that are necessary to manage databases or process SQL statements. The commands are listed in alphabetical order. And the descriptions will be written in the order; syntax, parameter, and example.
The following table shows the commands that are used in tbSQL utility.
Command | Description |
---|---|
% | Reruns the command stored in a history buffer. |
! | Executes the OS commands. It is the same as HOST command. |
@, @@ | Executes the script file. It is the same as START command. |
/ | Executes PSM programs or SQL statements that are saved in the SQL buffer. It is the same as RUN command. |
ACCEPT | Receives the user input and specifies the attribute of a substitution variable. |
CHANGE | Searches for a pattern character in the current line of the SQL buffer and then changes it to the given character. |
CLEAR | Initializes or deletes the specified option. |
COLUMN | Specifies the output property of the column. |
CONNECT | Accesses to database with a certain user's ID. |
DEFINE | Defines or displays substitution variables. |
DEL | Deletes the line which is saved in a SQL buffer. |
DESCRIBE | Displays the column information of 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 | Processes a single PSM statement. |
EXIT | Terminates tbSQL utility. It is the same as QUIT command. |
HELP | Displays the Help. |
HISTORY | Displays the history of the executed commands. |
HOST | Executes the OS commands. It is the same as ! command. |
INPUT | Adds a new line under the last line in the SQL buffer. |
LIST | Displays the contents saved in the SQL buffer onto the screen. |
LOADFILE | Saves the Tibero table in the form that can be recognized by Oracle SQL*Loader. |
LS | Outputs the database objects created by the current user. |
PAUSE | Holds the execution until the user presses <Enter> key. |
PING | Displays whether a specified database allows connections. |
Displays user-defined bind variables. | |
PROMPT | Displays the user defined SQL statement or empty line on the screen. |
QUIT | Terminates tbSQL utility. It is the same as EXIT command. |
RUN | Executes PSM program or SQL statement that are saved in the SQL buffer. It is the same as the / command. |
SAVE CREDENTIAL | Encrypts tbSQL utility's database access information and saves it in a file. |
SET | Specifies the system variables of tbSQL utility. |
SHOW | Displays the system variables of tbSQL utility. |
SPOOL | Starts or terminates the process which saves all the contents shown in the screen in an external file. |
START | Executes a script file. It is the same as @ command. |
TBDOWN | Terminates Tibero. |
UNDEFINE | Deletes one or more substitution variables. |
VARIABLE | Defines a bind variable. |
WHENEVER | Defines the actions to be taken when an error occurs. |
Reruns the command stored in the tbSQL utility history buffer. The commands do not need to be re-entered.
The following is the syntax for % command.
Syntax
% number
Option | Description |
---|---|
number | The command number stored 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 OS commands in tbSQL utility. The HOST command can be used instead of ! command.
The following is the syntax for ! command.
Syntax
! [command]
Option | Description |
---|---|
If only the ! command is entered without any OS
command, users will go out to the command prompt and be
able to enter OS commands many times. To return to the tbSQL utility the EXIT command should be entered. | |
command | It is an OS command. |
Example
SQL> ! dir *.sql SQL> !
Executes the script file. If the script file has the same file extension that is registered in FILEEXT system variables, the name of the script file can be specified without an extension. The tbSQL utility finds the specified script file from a directory that is specified by the FILEPATH system variable.
The System variable specified by the SET command before the script file is executed, is still valid while executing the script file. Enter the EXIT or QUIT command in a script file to terminate the tbSQL utility.
The START command can be used instead of the @ command.
The following is the syntax for @ command.
Syntax
@ {filename}
Item | Description |
---|---|
filename | Name of the script file. |
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 the user input and specifies the attribute of a substitution variable. The specified substitution variable will be substituted automatically if there is any SQL statement which user entered, or a word which matches the &variable in a PSM program.
The following is the syntax for the ACCEPT command.
Syntax
ACC[EPT] variable [PROMPT statement|NOPR[OMPT]]
Item | Description |
---|---|
variable | Name of the substitution variable to be saved. If the variable doesn't exist, create new one. |
The following table shows the description of ACCEPT command options.
Option | Description |
---|---|
PROMPT statement | Displays the prompt on the screen before receiving the value of a substitution variable from a user. |
NOPR[OMPT] | Does not display prompt. It just waits for a user to enter a value. |
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>
Searches for the first old pattern in the current line of a statement in a SQL buffer, and then converts it to a new pattern. 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 CHANGE command.
Syntax
C[HANGE] delim old [delim [new [delim [option]]]]
Item | Description |
---|---|
delim | Delimiter without a number. Character used for a delimiter must not be included in either the old or new pattern. |
old | The pattern to be changed. It is case insensitive. Not only general words (for example, dual, ksc911, etc.) but also ..., which indicates a temporary pattern, can be used. Refer to the example below. |
The following table shows the description of CHANGE command options.
Option | Description |
---|---|
delim | Delimiter without a number. Character used for delimiter must not be included in either old or new pattern. |
new | New pattern. |
option |
|
Current line always shows the last line as default thus the DUAL at second line will be converted to T.
SQL> SELECT * FROM DUAL; ..... SQL execution result ..... SQL> C/DUAL/T FROM T SQL>
To change the current line, a line number should be entered.
SQL> 5 5 WHERE ROWNUM < 5 AND
... can be used to indicate a temporary pattern. And this ... can be placed in the front, back, and middle.
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
When an option is specified, all the given patterns in the whole statement will be converted. * in the fist line will be converted to string.
SQL> SELECT * FROM DUAL; ..... SQL execution result ..... SQL> C/*/'replaced'/a SELECT 'replaced' FROM DUAL; SQL>
Initializes or deletes the specified option.
The following is the syntax for CLEAR command.
Syntax
CL[EAR] [option]
Option | Description |
---|---|
option |
|
Example
SQL> CLEAR BUFFER SQL buffer is cleared SQL> CLEAR SCREEN SQL> CLEAR COLUMNS
Specifies the output property of the column. When the column name is specified, property of the relevant column will be displayed. When the column name is not specified, all the registered columns will be displayed.
The following is the syntax for COLUMN command.
Syntax
COL[UMN] [name [option]]
Item | Description |
---|---|
name | Name of the column to specify. |
option |
|
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
Accesses a Tibero using another user's ID. If a user name or password is not entered, tbSQL utility will display a prompt and ask the information (name or password).
When the CONNECT command is used, it will commit the previous transaction, cancel the previous access, and then try to access again. Even if the new access fails, the previous access will not be recovered.
The following is the syntax for the CONNECT command.
Syntax
CONN[ECT] {username[/password[@connect_identifier]]}
Item | Description |
---|---|
username | Name of the user. |
Following table shows the syntax for the CONNECT command options.
Option | Description |
---|---|
password | Password of the user. |
connect_identifier | Access information to access the database. This option is specified in tbdsn.tbr of $TB_HOME/client/config directory. It consists of IP, PORT, and DB_NAME information. In Windows, the option can be specified in Data Sources (ODBC), which is searched first. |
Example
SQL> CONNECT dbuser/dbuserpassword@db_id
Defines or displays bind 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 the substitution variables are displayed. | |
variable | The name of the substitution variable to specify. |
variable = value | The default name of the substitution variable. |
Example
SQL> DEFINE NAME ..... Defines a substitution variable 'NAME'. ..... SQL> DEFINE NAME = 'SMITH' ..... Specifies SMITH as a default value of the substitution variable..... SQL> DEFINE ..... Displays 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 number|LAST]
Item | Description |
---|---|
number | Deletes the line that corresponds to the specified number. |
number number | Deletes all lines from the first specified line to the second specified line. |
number LAST | Deletes all lines from the first specified line to the last line. |
LAST number | Deletes all lines from the last line to the specified line. |
LAST | Deletes the last line. |
Example
SQL> DEL 1 ..... Deletes the first line. ..... SQL> DEL 1 3 ..... Deletes all lines from the first line to the third line. ..... SQL> DEL 1 LAST ..... Deletes all lines from the first line to the last line. ..... SQL> DEL LAST ..... Deletes the last line. .....
Displays the column information of the specified object. Objects can be table, view, synonym, function, procedure, or package.
For tables and views, the system will display the column name, data type, constraint, index information, maximum length, precision, scale, etc.
For functions and procedures, parameter information (name, data type, IN/OUT) will be displayed. For packages, all details of the function and procedure that belong to the relevant package will be displayed.
The column information of the object owned by other users can also be displayed. Make sure to specify the name of the owner. If the owner's name is not specified, the information of the current user will displayed 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. |
The following table describes the items that can be entered in the DESCRIBE command.
Item | Description |
---|---|
object | Object that will display the column information. |
Example
SQL> DESCRIBE emp SQL> DESC scott.emp
Closes the connection to the current database. The transaction in progress will be committed, but tbSQL utility will not be terminated.
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.
Syntax
DISC[ONNECT]
Edits the contents of a SQL buffer or a certain file by using an external editor. Users can choose an external editor to use by specifying the environment variable $TB_EDITOR.
If $TB_EDITOR is not registered, refer to the environment variable $EDITOR. And if $EDITOR is not registered either, use vi editor to edit. If a SQL buffer is empty, an error will be returned.
A file name can be specified without any extension if it is set to the default value. The default value of FILEEXT system variable is .sql, and it can be changed using the SET command. The tbSQL utility searches for the specified file in the path specified in FILEPATH system variable.
The following is the syntax for EDIT command.
Syntax
ED[IT] [filename]
Item | Description |
---|---|
When EDIT command is executed without specifying a file name, the contents saved in current SQL buffer will be edited. And the default file (.tbedit.sql) will be used. Default file will be deleted automatically when tbSQL utility terminates. | |
filename | Name of the file to be edited (usually, it is name of a script file). |
Example
SQL> EDIT run.sql SQL> EDIT run SQL> ED
Processes a single PSM statement. Only CALL statements and anonymous blocks are applicable. There must be a semicolon (;) at the end of the user-entered statement.
The following is the syntax for EXECUTE command.
Syntax
EXEC[UTE] {statement}
Item | Description |
---|---|
statement | Statement of a single PSM program. |
Example
SQL> EXECUTE begin dbms_output.put_line('success'); end; success PSM completed SQL> EXECUTE call proc1();
It is also useful when allocating a value to a bind variable, which the user specified.
SQL> VAR x NUMBER; SQL> EXEC :x := 5; PSM completed SQL>
Terminates tbSQL utility. Commits all transactions being processed and terminates all the accesses with database.
Syntax
EXIT
Outputs the Help of any items that include the specified word.
The following is the syntax for HELP command.
Syntax
H[ELP] [topic]
Item | Description |
---|---|
If not specified, all the commands available in tbSQL utility will be displayed. | |
topic | Specifies the word to display help. |
Example
SQL> HELP SET
Displays the history of commands that are saved in history buffer.
The following is the syntax for HISTORY command.
Syntax
HIS[TORY] [number|number number]
Item | Description |
---|---|
Outputs all the saved commands. | |
number | Displays the <number> most recent commands. |
number number | Outputs all commands from the first specified number to the second specified number. |
Example
SQL> HISTORY ..... Displays all the commands. ..... SQL> HISTORY 5 ..... Displays the 5 most recent commands. ..... SQL> HISTORY 10 20 ..... Displays all commands from the 10th to the 20th. ...
It is the same as ! command.
The following is the syntax for HOST command.
Syntax
HO[ST] [command]
Item | Description |
---|---|
When users enter only a HOST command without any OS commands, they will go out to the command prompt and be able to enter OS commands many times. To come back to the tbSQL utility, enter EXIT command. | |
command | It is an OS command. |
Adds a new line, which is entered by a user, under the last line in SQL buffer.
The following is the syntax for INPUT command.
Syntax
I[NPUT] [statement]
Item | Description |
---|---|
Statements will be added over several lines. | |
statement | SQL statement to be added. |
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 of a blank option. Unlike the example above, the SQL statement will be executed as soon as it is inputted.
SQL> select * from dual; ..... Outputs result ..... SQL> INPUT select * from dual ... Enter here. ...
Displays certain contents saved in SQL buffer onto the screen.
The following is the syntax for the LIST command.
Syntax
L[IST] [number|number number|number LAST|LAST number|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 number | Displays all lines from the last line to the second specified 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 the 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 | Name of a file without a file extension. |
Example
To save the table named EMP in the form that Oracle's SQL*Loader can recognize, enter the command as below. Then two files, emp.ctl and emp.dat, will be created.
SQL> LOADFILE emp SQL> select * from emp;
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 | FUNCTION, INDEX, PACKAGE, PROCEDURE, SEQUENCE, SYNONYM, TABLE, TABLESPACE, TRIGGER, USER, VIEW |
object_name | Name of the object to be displayed. The asterisk (*) 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> ..... Outputs all the entire objects. ..... SQL> LS TABLESPACE TABLESPACE_NAME ------------------------------ SYSTEM UNDO TEMP USR ..... Displays all the objects whose type is TABLESPACE. ..... SQL> LS USER USERNAME ------------------------------ SYS ..... Searches for the users that are accessing the current system. .....
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 | The message that will be shown on the screen when the user presses <Enter> key. |
Example
SQL> PAUSE please enter... please enter... ..... Press <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 tibero5 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 be displayed. |
Example
SQL> VARIABLE x NUMBER SQL> EXECUTE :x := 5; SQL> PRINT x x ---------- 5 SQL>
Displays a certain message or empty line on the screen.
The following is the syntax for the PROMPT command.
Syntax
PRO[MPT] [message]
Item | Description |
---|---|
Displays an empty line. | |
message | The message to be shown on the screen. |
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 example 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 / command. However, this command shows the SQL statement, currently being processed, on the screen.
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.3. Encrypting Connection String”.
The following is the syntax for the SAVE CREDENTIAL command.
Syntax
SAVE CREDENTIAL [filename]
Item | Description |
---|---|
The directory specified in the ISQL_WALLET_PATH is used to save the access information to the database. | |
filename | The directory specified in this option is used to save the access information to the database. |
Example
SQL> SAVE CREDENTIAL SQL> SAVE CREDENTIAL "./wallet.dat"
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}
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
Starts or terminates the process which saves all the contents shown in the screen in an external file. The output file will be created in the current directory.
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 | The name of the file to save the output. |
APP[END] | Specifies whether 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 | Name of the script file. |
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. This is the 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 |
---|---|
Deletes all the substitution variables. | |
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 the bind variables, on the screen. | |
variable | Name of the bind variable. |
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 {error_type} {EXIT [exit_option]|CONTINUE} [tx_option]
The following options can be entered in error_type.
Item | Description |
---|---|
Defines the type(s) of errors the actions are defined for. The default state, which does not use the WHENEVER command, is equivalent to executing OSERROR or SQLERROR with the CONTINUE NONE option. | |
OSERROR | OS error from the system on which tbSQL is running. |
SQLERROR | Error that occurs while executing a SQL statement. |
The following options can be entered in exit_option.
Item | Description |
---|---|
This option specifies the termination code value (integer) returned if the EXIT keyword is given, which terminates the program when an error occurs. | |
SUCCESS | Returns the normal termination code 0. |
FAILURE | Returns the failure termination code 1. |
WARNING | Returns the warning termination code 2. |
SQL.SQLCODE | Returns the error code when an error occurs. However, the value may change based on the termination code range. |
n | The termination code. n is an integer that can be specified directly. The range of possible values depends on the OS. |
:variable | A termination code can be specified using a bind variable defined by the VARIABLE command. However, the bind variable used must be a number type. |
The following options can be entered in tx_option.
Item | Description |
---|---|
Defines how to process a running transaction. | |
COMMIT | Performs COMMIT if an error occurs. |
ROLLBACK | Performs ROLLBACK if an error occurs. |
NONE | Does nothing if an error occurs. This option can be used only when CONTINUE is set. |
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}
Item | Description |
---|---|
col_name | Specifies the name of column. |
fmt_str | Specifies the column formats described in the table below. |
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. |
rn | rn | Displays as lowercase. |
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.