Chapter 1. tbSQL

Table of Contents

1.1. Overview
1.2. Quick Start
1.2.1. Executing Utility
1.2.2. Accessing Database
1.2.3. Interface
1.2.4. Configuration Environment
1.2.5. Terminating Utility
1.3. System Variables
1.3.1. AUTOCOMMIT
1.3.2. AUTOTRACE
1.3.3. BLOCKTERMINATOR
1.3.4. COLSEP
1.3.5. CONCAT
1.3.6. DDLSTATS
1.3.7. DEFINE
1.3.8. ECHO
1.3.9. EDITFILE
1.3.10. ESCAPE
1.3.11. EXITCOMMIT
1.3.12. FEEDBACK
1.3.13. FILEEXT
1.3.14. FILEPATH
1.3.15. HEADING
1.3.16. HISTORY
1.3.17. LINESIZE
1.3.18. LONG
1.3.19. NUMFORMAT
1.3.20. NUMWIDTH
1.3.21. PAGESIZE
1.3.22. PAUSE
1.3.23. SERVEROUTPUT
1.3.24. SQLPROMPT
1.3.25. SQLTERMINATOR
1.3.26. TERMOUT
1.3.27. TIME
1.3.28. TIMEOUT
1.3.29. TIMING
1.3.30. TRIMOUT
1.3.31. TRIMSPOOL
1.3.32. VERIFY
1.3.33. WRAP
1.4. Basic Functions
1.4.1. Entering Commands
1.4.2. Executing Commands
1.4.3. Other Functions
1.5. Advanced Functions
1.5.1. Script Functions
1.5.2. DBA Functions
1.5.3. Encrypting Connection String
1.6. Command
1.6.1. %
1.6.2. !
1.6.3. @, @@
1.6.4. /
1.6.5. ACCEPT
1.6.6. CHANGE
1.6.7. CLEAR
1.6.8. COLUMN
1.6.9. CONNECT
1.6.10. DEFINE
1.6.11. DEL
1.6.12. DESCRIBE
1.6.13. DISCONNECT
1.6.14. EDIT
1.6.15. EXECUTE
1.6.16. EXIT
1.6.17. HELP
1.6.18. HISTORY
1.6.19. HOST
1.6.20. INPUT
1.6.21. LIST
1.6.22. LOADFILE
1.6.23. LS
1.6.24. PAUSE
1.6.25. PING
1.6.26. PRINT
1.6.27. PROMPT
1.6.28. QUIT
1.6.29. RUN
1.6.30. SAVE CREDENTIAL
1.6.31. SET
1.6.32. SHOW
1.6.33. SPOOL
1.6.34. START
1.6.35. TBDOWN
1.6.36. UNDEFINE
1.6.37. VARIABLE
1.6.38. WHENEVER
1.7. Column Format
1.7.1. Character Type
1.7.2. Numeric Type

This chapter describes the tbSQL utility and its usage.

1.1. Overview

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.

1.2. Quick Start

tbSQL utility is installed automatically when installing the Tibero. If you remove Tibero, tbSQL utility will also be removed.

1.2.1. Executing Utility

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.

OptionDescription
-h, --helpShows the Help screen.
-v, --versionShows the version.
-s, --silentDoes not show the start message and prompt on the screen.
-i, --ignoreDoes 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.

OptionDescription
usernameSpecifies a user name. It is not case-sensitive; however, when the username is inserted in double quotes(" "), it is case sensitive.
passwordSpecifies a user password. It is case-sensitive.
connect_identifierSpecifies 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.

OptionDescription
filenameName of the file.
extExtension of the file. If extension is not specified, the default value, set in FILEEXT system variable, will be used.

1.2.2. Accessing Database

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:

ItemDescription
UsernameSpecifies a user name. It is not case-sensitive; however, when the user name is inserted in double quotes (" "), it is case sensitive.
PasswordSpecifies 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'

1.2.3. Interface

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.

Note

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

1.2.4. Configuration Environment

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]

Note

For detailed information, refer to “1.3. System Variables ”.

1.2.5. Terminating Utility

To terminate the tbSQL utility, enter the EXIT or QUIT command at the SQL prompt.

SQL> EXIT

Note

For detailed information about the commands provided from tbSQL utility, refer to “1.6. Command ”.

1.3. System Variables

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 VariablesDefault ValueDescription
AUTOCOMMITOFFSpecifies the status of the AUTOCOMMIT option.
AUTOTRACEOFFSpecifies 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.
COLSEPOFFSpecifies 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.
DDLSTATSOFFSpecifies 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.
ECHOOFFSpecifies 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.
ESCAPEOFFSpecifies the escape character.
EXITCOMMITONSpecifies whether to commit when terminating a utility.
FEEDBACK0Specifies 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.
HEADINGONSpecifies whether to display column headers when displaying query execution results.
HISTORY50Specifies the size of the command history.
LINESIZE80Specifies the length of a line shown on the screen.
LONG80Specifies the length of the CLOB type data to be displayed.
NUMFORMAT""Specifies the default column format of number type data.
NUMWIDTH10Specifies the size of numeric data that is displayed from the DBMS_OUTPUT package.
PAGESIZE24Specifies the number of lines to display on each output page.
PAUSEOFFSpecifies whether to wait for user input before displaying the next page.
SERVEROUTPUTOFFSpecifies 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.
TERMOUTONSpecifies whether to display the result of executing a command, using a script, on the screen.
TIMEOFFSpecifies whether to display the current time at the prompt.
TIMEOUT3Specifies how long to wait for a server response to a PING command. (Unit: seconds)
TIMINGOFFSpecifies whether to display the processing time when the SQL and PSM statements are displayed.
TRIMOUTONSpecifies whether to truncate spaces at the end of each line, every time execution results of SQL, PSM statements are displayed.
TRIMSPOOLOFFSpecifies whether to truncate spaces at the end of each line, every time execution results of SQL, PSM statements are spooled.
VERIFYONSpecifies whether to display the details of a SQL command before and after replacing substitution variables with values.
WRAPONSpecifies 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

1.3.1. AUTOCOMMIT

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}
    ItemDescription
    ONEnables AUTOCOMMIT.
    OFF

    Disables AUTOCOMMIT. This is the default value.

    When it is set to OFF, you must commit changes manually.

1.3.2. AUTOTRACE

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]]
    ItemDescription
    OFFDoes not display the statistical or plan information. This is the default value.
    ONDisplays 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.

    OptionDescription
     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.

1.3.3. BLOCKTERMINATOR

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}
    ItemDescription
    cSpecifies a character to indicate the end of a PSM program input. The default value is ".".
    ONEnables a PSM termination character.
    OFFDisables a PSM termination character.

1.3.4. COLSEP

Specifies a column separator character to be printed between the selected columns.

The following is the syntax for COLSEP.

  • Syntax

    SET COLSEP {text}
    ItemDescription
    textSpecifies a column separator character string. The default character is " ".

1.3.5. CONCAT

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}
    ItemDescription
    cSpecifies a character that indicates that a character string is appended to a substitution variable. The default character is ".".
    ONEnables CONCAT.
    OFFDisables CONCAT.

1.3.6. DDLSTATS

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}
    ItemDescription
    OFFEnables DDLSTATS. This is the default value.
    ONDisables DDLSTATS.

1.3.7. DEFINE

Specifies the character to be used when defining a substitution variable.

The following is the syntax for DEFINE.

  • Syntax

    SET DEF[INE] {OFF|ON}
    ItemDescription
    cSpecifies a character that indicates a substitution variable. The default character is "&".
    OFFDisables DEFINE.
    ONEnables DEFINE. This is the default value.

1.3.8. ECHO

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}
    ItemDescription
    OFFDisables ECHO. This is the default value.
    ONEnables ECHO.

1.3.9. EDITFILE

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]
    ItemDescription
    filename[.ext]Filename that is to be used with the EDIT command. By default, it is set to .tbedit.sql.

1.3.10. ESCAPE

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}
    ItemDescription
    cThe escape character.
    ONEnables ESCAPE.
    OFFDisables ESCAPE. This is the default value.

1.3.11. EXITCOMMIT

Specifies whether to commit when terminating a utility.

The following is the syntax for EXITCOMMIT.

  • Syntax

    SET EXITC[OMMIT] {ON|OFF}
    ItemDescription
    ONEnables EXITCOMMIT. This is the default value.
    OFFDisables EXITCOMMIT.

1.3.12. FEEDBACK

Specifies whether to display the SQL statement result on the screen.

The following is the syntax for FEEDBACK.

  • Syntax

    SET FEED[BACK] {ON|OFF}
    ItemDescription
    ONEnables FEEDBACK. This is the default value.
    OFFDisables FEEDBACK.

1.3.13. FILEEXT

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}
    ItemDescription
    file_extensionFile extension to be used by default, initially set to .sql.

1.3.14. FILEPATH

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}
    ItemDescription
    file_pathFile path to be used by default, initially set to the current directory.

1.3.15. HEADING

Specifies whether to display column headers when displaying query execution results.

The following is the syntax for HEADING.

  • Syntax

    SET HEA[DING] {ON|OFF}
    ItemDescription
    ONEnables HEADING. This is the default value.
    OFFDisables HEADING.

1.3.16. HISTORY

Specifies the size of the command history.

The following is the syntax for HISTORY.

  • Syntax

    SET HIS[TORY] {n}
    ItemDescription
    nSize of the command history. By default, it is set to 50.
    ONEnables HISTORY. This is the default value.
    OFFDisables HISTORY.

1.3.17. LINESIZE

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}
    ItemDescription
    nLength of a line shown on the screen. By default, it is set to 80.

1.3.18. LONG

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}
    ItemDescription
    nDefault output size for large data. By default, it is set to 80.

1.3.19. NUMFORMAT

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}
    ItemDescription
    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 ”.

1.3.20. NUMWIDTH

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}
    ItemDescription
    nDefault output length of data that is generated from DBMS_OUTPUT package. By default, it is set to 10.

1.3.21. PAGESIZE

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}
    ItemDescription
    nNumber of lines per page. By default, it is set to 24.

1.3.22. PAUSE

Specifies whether to wait for user input before displaying the next page.

The following is the syntax for PAUSE.

  • Syntax

    SET PAUSE {ON|OFF}
    ItemDescription
    ONEnables PAUSE.
    OFFDisables PAUSE. This is the default value.

1.3.23. SERVEROUTPUT

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]
    ItemDescription
    ONEnables SERVEROUTPUT.
    OFFDisables SERVEROUTPUT. This is the default value.
    nSpecifies the SERVEROUTPUT buffer size. The default value is 1000000.

1.3.24. SQLPROMPT

Specifies the prompt character string on the screen.

The following is the syntax for SQLPROMPT.

  • Syntax

    SET SQLP[ROMPT] {prompt_string}
    ItemDescription
    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.

1.3.25. SQLTERMINATOR

Specifies the character for terminating a SQL statement.

The following is the syntax for SQLTERMINATOR.

  • Syntax

    SET SQLT[MINATOR} {c|ON|OFF}
    ItemDescription
    cCharacter that signifies the termination of a SQL statement. By default, it is set to ";".
    ONEnables SQLTERMINATOR.
    OFFDisables SQLTERMINATOR.

1.3.26. TERMOUT

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}
    ItemDescription
    ONEnables TERMOUT. This is the default value.
    OFFDisables TERMOUT.

1.3.27. TIME

Specifies whether to display the current time on the prompt.

The following is the syntax for TIME.

  • Syntax

    SET TI[ME] {ON|OFF}
    ItemDescription
    ONEnables TIME.
    OFFDisables TIME. This is the default value.

1.3.28. TIMEOUT

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}
    ItemDescription
    nPeriod of time to wait for a server response. The unit is second. By default, it is set to 3 seconds.

1.3.29. TIMING

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}
    ItemDescription
    ONEnables TIMING.
    OFFDisables TIMING. This is the default value.

1.3.30. TRIMOUT

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}
    ItemDescription
    ONEnables TRIMOUT. This is the default value.
    OFFDisables TRIMOUT.

1.3.31. TRIMSPOOL

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}
    ItemDescription
    ONEnables TRIMSPOOL.
    OFFDisables TRIMSPOOL. This is the default value.

1.3.32. VERIFY

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}
    ItemDescription
    ONEnables VERIFY. This is the default value.
    OFFDisables VERIFY.

1.3.33. WRAP

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}
    ItemDescription
    ONEnables WRAP. This is the default value.
    OFFDisables WRAP.

1.4. Basic Functions

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.

1.4.1. Entering Commands

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.

Entering SQL Statement

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>

Entering PSM Programs

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.

Note

For the detailed information about PSM usage, refer to "Tibero PSM Guide".

Entering tbSQL Utility Commands

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 ”.

1.4.2. Executing Commands

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>

1.4.3. Other Functions

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.

Inserting a Comment

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

Auto Commit

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.

Executing OS 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>

Saving the Output

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.

1.5. Advanced Functions

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.

1.5.1. Script Functions

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.

Creating a Script

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;

Executing a Script

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

1.5.2. DBA Functions

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.

1.5.3. Encrypting Connection String

The tbSQL utility saves database access information(connect_string) with the wallet.dat file

The information in the database, which the tbSQL

Creating an Encrypted File

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.

Using an Encrypted File

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.

Note

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.

1.6. Command

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.

ItemDescription
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 lettersContents that are written in italic letters should be replaced by another string, depending on the command.
CaseCommands 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.

CommandDescription
%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.

ACCEPTReceives the user input and specifies the attribute of a substitution variable.
CHANGESearches for a pattern character in the current line of the SQL buffer and then changes it to the given character.
CLEARInitializes or deletes the specified option.
COLUMNSpecifies the output property of the column.
CONNECTAccesses to database with a certain user's ID.
DEFINEDefines or displays substitution variables.
DELDeletes the line which is saved in a SQL buffer.
DESCRIBEDisplays the column information of specified object.
DISCONNECTCloses the connection to the current database.
EDITEdits the contents of a SQL buffer or a certain file by using an external editor.
EXECUTEProcesses a single PSM statement.
EXIT

Terminates tbSQL utility.

It is the same as QUIT command.

HELPDisplays the Help.
HISTORYDisplays the history of the executed commands.
HOST

Executes the OS commands.

It is the same as ! command.

INPUTAdds a new line under the last line in the SQL buffer.
LISTDisplays the contents saved in the SQL buffer onto the screen.
LOADFILESaves the Tibero table in the form that can be recognized by Oracle SQL*Loader.
LSOutputs the database objects created by the current user.
PAUSEHolds the execution until the user presses <Enter> key.
PINGDisplays whether a specified database allows connections.
PRINTDisplays user-defined bind variables.
PROMPTDisplays 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 CREDENTIALEncrypts tbSQL utility's database access information and saves it in a file.
SETSpecifies the system variables of tbSQL utility.
SHOWDisplays the system variables of tbSQL utility.
SPOOLStarts 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.

TBDOWNTerminates Tibero.
UNDEFINEDeletes one or more substitution variables.
VARIABLEDefines a bind variable.
WHENEVERDefines the actions to be taken when an error occurs.

1.6.1. %

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
    OptionDescription
    numberThe 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.

1.6.2. !

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]
    OptionDescription
     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.

    commandIt is an OS command.
  • Example

    SQL> ! dir *.sql
    SQL> !

1.6.3. @, @@

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}
    ItemDescription
    filenameName of the script file.
  • Example

    SQL> @ run
    SQL> @ run.sql

1.6.4. /

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 .....

1.6.5. ACCEPT

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]]
    ItemDescription
    variableName 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.

    OptionDescription
    PROMPT statementDisplays 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>

1.6.6. CHANGE

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]]]]
    ItemDescription
    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.

    OptionDescription
    delim

    Delimiter without a number.

    Character used for delimiter must not be included in either old or new pattern.

    newNew pattern.
    option
    • g: Converts the entire pattern from the current line.

    • c: Converts any pattern user wants from the current line.

    • a: Converts the entire pattern from the whole statement.

  • 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>

1.6.7. CLEAR

Initializes or deletes the specified option.

The following is the syntax for CLEAR command.

  • Syntax

    CL[EAR] [option]
    OptionDescription
    option
    • BUFF[ER]: Deletes all the contents in the SQL buffer.

    • SCR[EEN]: Deletes all the contents on the screen.

    • COL[UMNS]: Initializes the output property of all registered columns.

  • Example

    SQL> CLEAR BUFFER
    SQL buffer is cleared
    SQL> CLEAR SCREEN
    SQL> CLEAR COLUMNS

1.6.8. COLUMN

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]]
    ItemDescription
    nameName of the column to specify.
    option
    • CLE[AR]: Initializes the output property of a column.

    • FOR[MAT] text: Specifies the format of a column. For more detail information, refer to “1.7. Column Format ”.

    • HEA[DING] text: Specifies the heading of a column.

    • NEW_V[ALUE] variable: Specifies the variable that saves the column value.

    • WRA[PPED]: If the column data is too long, the text will go to the next line.

    • TRU[NCATED]: If the column data is too long, the data will be truncated to fit.

    • ON: Turns on the output property of a column.

    • OFF: Turns off the output property of a column.

  • 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

1.6.9. CONNECT

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]]}
    ItemDescription
    usernameName of the user.

    Following table shows the syntax for the CONNECT command options.

    OptionDescription
    passwordPassword 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

1.6.10. DEFINE

Defines or displays bind variables.

The following is the syntax for the DEFINE command.

  • Syntax

    DEF[INE] [variable]|[variable = value]
    ItemDescription
     When no substitution variable name is specified, all the substitution variables are displayed.
    variableThe name of the substitution variable to specify.
    variable = valueThe 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. .....

1.6.11. DEL

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]
    ItemDescription
    numberDeletes the line that corresponds to the specified number.
    number numberDeletes all lines from the first specified line to the second specified line.
    number LASTDeletes all lines from the first specified line to the last line.
    LAST numberDeletes all lines from the last line to the specified line.
    LASTDeletes 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. .....

1.6.12. DESCRIBE

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}
    ItemDescription
    schemaSchema (or owner) that contains the target object.

    The following table describes the items that can be entered in the DESCRIBE command.

    ItemDescription
    objectObject that will display the column information.
  • Example

    SQL> DESCRIBE emp
    SQL> DESC scott.emp

1.6.13. DISCONNECT

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]

1.6.14. EDIT

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]
    ItemDescription
     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.
    filenameName of the file to be edited (usually, it is name of a script file).
  • Example

    SQL> EDIT run.sql
    SQL> EDIT run
    SQL> ED

1.6.15. EXECUTE

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}
    ItemDescription
    statementStatement 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> 

1.6.16. EXIT

Terminates tbSQL utility. Commits all transactions being processed and terminates all the accesses with database.

  • Syntax

    EXIT

1.6.17. HELP

Outputs the Help of any items that include the specified word.

The following is the syntax for HELP command.

  • Syntax

    H[ELP] [topic]
    ItemDescription
     If not specified, all the commands available in tbSQL utility will be displayed.
    topicSpecifies the word to display help.
  • Example

    SQL> HELP SET

1.6.18. HISTORY

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]
    ItemDescription
     Outputs all the saved commands.
    numberDisplays the <number> most recent commands.
    number numberOutputs 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. ...

1.6.19. HOST

It is the same as ! command.

The following is the syntax for HOST command.

  • Syntax

    HO[ST] [command]
    ItemDescription
     

    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.

    commandIt is an OS command.

1.6.20. INPUT

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]
    ItemDescription
     Statements will be added over several lines.
    statementSQL 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. ... 

1.6.21. LIST

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]
    ItemDescription
     Displays all the lines.
    numberDisplays the line that corresponds to the specified number.
    number numberDisplays all lines from the first specified line to the second specified line.
    number LASTDisplays all lines from the first specified line to the last line.
    LAST numberDisplays all lines from the last line to the second specified line.
    LASTDisplays 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. .....

1.6.22. LOADFILE

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}
    ItemDescription
    filenameName 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;

1.6.23. LS

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]
    ItemDescription
     Outputs all the objects owned by the user.
    object_typeFUNCTION, 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. .....

1.6.24. PAUSE

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]
    ItemDescription
    messageThe 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>

1.6.25. PING

Displays whether a specified database allows connections.

The following is the syntax for PING command.

  • Syntax

    PING connect_identifier
    ItemDescription
    connect_identifierName of the database to connect to.
  • Example

    SQL> PING tibero5
    Server is alive.
    
    SQL>

1.6.26. PRINT

Displays the value and name of user-defined bind variables.

The following is the syntax for the PRINT command.

  • Syntax

    PRI[NT] [variable...]
    ItemDescription
     Displays all the bind variables.
    variableList of the names of bind variables to be displayed.
  • Example

    SQL> VARIABLE x NUMBER
    SQL> EXECUTE :x := 5;
    SQL> PRINT x
    
             x
    ----------
             5
    
    SQL>

1.6.27. PROMPT

Displays a certain message or empty line on the screen.

The following is the syntax for the PROMPT command.

  • Syntax

    PRO[MPT] [message]
    ItemDescription
     Displays an empty line.
    messageThe 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>

1.6.28. QUIT

It is the same as the EXIT command.

The following is the syntax for the QUIT command.

  • Syntax

    Q[UIT]

1.6.29. RUN

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.

1.6.30. SAVE CREDENTIAL

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]
    ItemDescription
     The directory specified in the ISQL_WALLET_PATH is used to save the access information to the database.
    filenameThe directory specified in this option is used to save the access information to the database.
  • Example

    SQL> SAVE CREDENTIAL
    SQL> SAVE CREDENTIAL "./wallet.dat"

1.6.31. SET

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}
    ItemDescription
    parameterName of tbSQL utility system variable.
    valueValue of tbSQL utility system variable.
  • Example

    SQL> SET AUTOCOMMIT ON

1.6.32. SHOW

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.

    ItemDescription
    system_parameterDisplays the tbSQL utility system variable which corresponds to the specified name.
    ALLOutputs all the system variables of the tbSQL utility.
    ERRORDisplays 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.

    RELEASEDisplays 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

1.6.33. SPOOL

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]
    ItemDescription
     When the SPOOL command is entered, the current process state of the SPOOL command will be displayed.
    filenameThe name of the file to save the output.
    APP[END]Specifies whether to attach to the end of the output file.
    OFFStops saving output files.
  • Example

    SQL> SPOOL report.txt
    SQL> SPOOL OFF

1.6.34. START

It is the same as the @ command.

The following is the syntax for the START command.

  • Syntax

    STA[RT] {filename}
    ItemDescription
    filenameName of the script file.

1.6.35. TBDOWN

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]
    ItemDescription
    NORMALWaits until all the users terminate their access. This is the default value.
    POST_TXWaits until the transactions currently being processed are terminated.
    IMMEDIATERolls back the transactions currently being processed, and then executes forced termination.
    ABORTTerminates immediately without rolling back the transactions currently being processed.
  • Example

    SQL> TBDOWN
    SQL> TBDOWN ABORT

1.6.36. UNDEFINE

Deletes a substitution variable specified by the ACCEPT command.

The following is the syntax for UNDEFINE command.

  • Syntax

    UNDEF[INE] [variable...]
    ItemDescription
     Deletes all the substitution variables.
    variable...List of the substitution variable names.
  • Example

    SQL> UNDEFINE x
    SQL> UNDEFINE x y z

1.6.37. VARIABLE

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]]
    ItemDescription
     Displays all the bind variables, on the screen.
    variableName of the bind variable.
    datatype

    Options are:

    • NUMBER, CHAR(n), VARCHAR(n), VARCHAR2(n), NCHAR(n), NVARCHAR2(n), RAW(n), BLOB, CLOB, NCLOB, DATE, TIMESTAMP, REFCURSOR

  • Example

    SQL> VARIABLE x NUMBER
    SQL> EXEC :x := 1;
    
    PSM completed.
    
    SQL> SELECT :x FROM DUAL;
            :x
    ----------
             1
    1 row selected.
    SQL>

1.6.38. WHENEVER

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.

    ItemDescription
     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.
    OSERROROS error from the system on which tbSQL is running.
    SQLERRORError that occurs while executing a SQL statement.

    The following options can be entered in exit_option.

    ItemDescription
     This option specifies the termination code value (integer) returned if the EXIT keyword is given, which terminates the program when an error occurs.
    SUCCESSReturns the normal termination code 0.
    FAILUREReturns the failure termination code 1.
    WARNINGReturns the warning termination code 2.
    SQL.SQLCODEReturns the error code when an error occurs. However, the value may change based on the termination code range.
    nThe termination code. n is an integer that can be specified directly. The range of possible values depends on the OS.
    :variableA 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.

    ItemDescription
     Defines how to process a running transaction.
    COMMITPerforms COMMIT if an error occurs.
    ROLLBACKPerforms ROLLBACK if an error occurs.
    NONEDoes 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
    $
    

1.7. Column Format

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.

1.7.1. Character Type

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>

1.7.2. Numeric Type

The following is the syntax for specifying a numeric-type column format.

  • Syntax

    COL[UMN] {col_name} FOR[MAT] {fmt_str}
    ItemDescription
    col_nameSpecifies the name of column.
    fmt_strSpecifies the column formats described in the table below.

    The following table shows the formats that can be specified to the fmt_str.

    FormatExampleDescription
    Comma (,)9,999Displays a comma (,) at the specified location.
    Period (.)9.999Displays a period (.) at the location to distinguish integer and decimal parts.
    $$9999Displays $ in the first place.
    00999, 9990Displays 0 in the last place.
    99999Displays the number according to the specified cipher (digit).
    BB9999If the integer part is 0, it is replaced with a blank space.
    CC9999Displays ISO currency symbol at the specified location.
    D9D999Displays a decimal character to separate the integer and decimal parts of a real number.
    EEEE9.99EEEEDisplays scientific notation.
    G9G999Displays a group separator at the specified location of the integer part.
    LL9999Displays the local currency symbol at the specified location.
    MI9999MIDisplays a minus sign at the end of a negative number. Displays a blank space at the end of a positive number.
    PR9999PRDisplays a negative number surrounded by '<' and '>' (angle brackets), and positive number surrounded by blank spaces.
    RNRNDisplays as uppercase.
    rnrnDisplays as lowercase.
    SS9999, 9999SDisplays the positive/negative sign at the first or last place.
    TMTMDisplays the smallest number.
    UU9999Displays dual currency symbol at the specified location.
    V99V999

    Displays the value multiplied by 10n.

    n is the number of 9 that comes after V.

    XXXXX, xxxxDisplays in hexadecimal format.
  • Example

    SQL> COLUMN x FORMAT 999,999
    SQL> SELECT 123456 x FROM DUAL;
    
               X
     --------
       123,456
    
    1 row selected.