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. DESCRIBE
1.3.9. ECHO
1.3.10. EDITFILE
1.3.11. ESCAPE
1.3.12. EXITCOMMIT
1.3.13. FEEDBACK
1.3.14. HEADING
1.3.15. HEADSEP
1.3.16. HISTORY
1.3.17. INTERVAL
1.3.18. LINESIZE
1.3.19. LONG
1.3.20. NEWPAGE
1.3.21. NUMFORMAT
1.3.22. NUMWIDTH
1.3.23. PAGESIZE
1.3.24. PAUSE
1.3.25. RECSEP
1.3.26. RECSEPCHAR
1.3.27. ROWS
1.3.28. SERVEROUTPUT
1.3.29. SQLPROMPT
1.3.30. SQLTERMINATOR
1.3.31. SUFFIX
1.3.32. TERMOUT
1.3.33. TIME
1.3.34. TIMEOUT
1.3.35. TIMING
1.3.36. TRIMOUT
1.3.37. TRIMSPOOL
1.3.38. UNDERLINE
1.3.39. VERIFY
1.3.40. WRAP
1.4. Basic Functions
1.4.1. Entering Commands
1.4.2. Executing Commands
1.4.3. Additional Functions
1.5. Advanced Functions
1.5.1. Script Function
1.5.2. DBA Functions
1.5.3. User Access Control
1.5.4. Encrypting Connection String
1.6. Commands
1.6.1. !
1.6.2. %
1.6.3. @, @@
1.6.4. /
1.6.5. ACCEPT
1.6.6. ARCHIVE LOG
1.6.7. CHANGE
1.6.8. CLEAR
1.6.9. COLUMN
1.6.10. CONNECT
1.6.11. DEFINE
1.6.12. DEL
1.6.13. DESCRIBE
1.6.14. DISCONNECT
1.6.15. EDIT
1.6.16. EXECUTE
1.6.17. EXIT
1.6.18. EXPORT
1.6.19. HELP
1.6.20. HISTORY
1.6.21. HOST
1.6.22. INPUT
1.6.23. LIST
1.6.24. LOADFILE
1.6.25. LOOP
1.6.26. LS
1.6.27. PASSWORD
1.6.28. PAUSE
1.6.29. PING
1.6.30. PRINT
1.6.31. PROMPT
1.6.32. QUIT
1.6.33. RESTORE
1.6.34. RUN
1.6.35. SAVE
1.6.36. SET
1.6.37. SHOW
1.6.38. SPOOL
1.6.39. START
1.6.40. TBDOWN
1.6.41. UNDEFINE
1.6.42. VARIABLE
1.6.43. WHENEVER
1.7. Column Formats
1.7.1. Character Type
1.7.2. Numeric Type

This chapter describes the tbSQL utility and its usage.

1.1. Overview

tbSQL is an interactive utility provided by Tibero to process SQL statements. tbSQL utility can process SQL queries, Data Definition Language (hereafter DDL), and transactional SQL statements. It can also be used to create and execute PSM programs, and DBAs can execute commands to manage Tibero systems.

In addition, tbSQL provides many other functions, such as auto commit setting, OS command execution, output save, and script creation. The script function allows the user to conveniently create SQL statements, PSM programs, and tbSQL utility commands into a single script file.

tbSQL is one of the most frequently used utility in Tibero. It provides the following functions in addition to executing SQL statements.

  • Input, edit, save, and execute general SQL statements and tbSQL programs.

  • Configure and terminate a transaction.

  • Batch processing using a script.

  • Management of databases by a DBA.

  • Start and terminate a database.

  • Execute external utilities and programs.

  • Configure the tbSQL utility.

1.2. Quick Start

tbSQL is automatically installed and uninstalled with Tibero.

1.2.1. Executing Utility

The following example illustrates how to execute tbSQL.

[Example 1.1] Executing tbSQL

$ tbsql

tbSQL 6

TmaxData Corporation Copyright (c) 2008-. All rights reserved.

When tbSQL is successfully executed, the previous SQL prompt is displayed. Database users can enter and execute SQL statements at the prompt.

The following is the command syntax for executing tbSQL.

  • Usage

    tbsql [[options]|[connect_string]|[start_script]]
    • options

      OptionDescription
      -h, --helpDisplay the Help screen.
      -v, --versionDisplay the version information.
      -s, --silentDo not output the start message and prompt.
      -i, --ignoreDo not execute the login script (tbsql.login).
    • connect_string

      connect_string contains the user account information for Tibero. It is specified as follows:

      username[/password[@connect_identifier]]

      The following are the connect_string options.

      OptionDescription
      usernameUser name. It is not case-sensitive except when it is enclosed in double quotes (" ").
      passwordUser password. It is not case-sensitive except when it is enclosed in single quotes (' ').
      connect_identifierDSN (Data Source Name) that contains database access information or the connection information of the set connection policy.
    • start_script

      start_script sets the script files to execute during tbSQL startup. It is specified as follows:

      @filename[.ext] [parameter ...]

      The following are the start_script options.

      OptionDescription
      filenameFile name.
      extFile extension. If not set, the default value (SUFFIX system variable value) will be used.
      parameterSubstitution variable used in the file.

1.2.2. Accessing Database

When the SQL prompt appears after executing tbSQL, it is ready to connect to the database.

If there are any tasks that need to be processed before starting the database session, create the tbsql.login file. If this file can't be found in the current directory, it can be found in the directory specified in the environment variable, TB_SQLPATH.

The following shows how to connect to the database in tbSQL.

[Example 1.2] Connecting to Database

$ tbsql SYS/syspassword

tbSQL 6

TmaxData Corporation Copyright (c) 2008-. All rights reserved.

Connected.

SQL>

In the previous example, username and password are entered at the UNIX shell prompt that is displayed after starting tbSQL.

Rules for entering the username and password are as follows:

ItemDescription
UsernameUser name. It is not case-sensitive except when it is enclosed in double quotes (" ").
PasswordPassword. It is not case-sensitive except when it is enclosed in single quotes (' ').

If connect_identifier is omitted, as in the previous example, connection is made to the default database. To access a specific database, specify connect_identifier in one of the following ways.

  • DSN (Data Source Name)

    Specify the name that is defined in tbdsn.tbr or Data Source (ODBC) in Windows.

    The following is an example of a tbdsn.tbr file.

    tibero6=(
        (INSTANCE=(HOST=192.168.36.42)
                  (PORT=8629)
                  (DB_NAME=tibero6)
        )
    ) 

    Connect to the database using the previous setting as follows:

    $ tbsql tibero/tmax@tibero6
  • Connection information

    Connection information can be manually specified using one of the following two methods (without using a tbdsn.tbr file).

    • Method 1

      (INSTANCE=(HOST=host)(PORT=port)(DB_NAME=dbname))

      Example:

      $ tbsql 'tibero/tmax@(INSTANCE=(HOST=192.168.36.42)(PORT=8629)(DB_NAME=tibero6))'
      
    • Method 2

      host:port/dbname

      Example:

      $ tbsql 'tibero/tmax@192.168.36.42:8629/tibero6'
      

1.2.3. Interface

The following example shows tbSQL utility execution.

$ tbsql

tbSQL 6

TmaxData Corporation Copyright (c) 2008-. All rights reserved.

SQL> CONNECT dbuser
Enter password : dbuserpassword
Connected to Tibero.

In the previous example, after starting tbSQL a connection is made to the database using the CONNECT command with the username 'dbuser'. tbSQL is a text-based user interface.

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.

The tbSQL interface that supports the following features:

  • When tbSQL SQL prompt is displayed.

    At the SQL prompt, it is possible to enter SQL statements, PSM programs, and tbSQL utility commands.

  • Input can span over multiple lines.

    SQL statements and PSM programs are not automatically executed at input, but tbSQL utility commands are executed immediately.

  • Case insensitive.

    Input text is case insensitive, with some exceptions such as a string value in a SQL statement.

    For example, the following two statements will produce the same results.

    SQL> SET AUTOCOMMIT ON 
    SQL> set autocommit on

1.2.4. Configuration Environment

Use the SET command to configure tbSQL. It can be used to configure various settings including SQL query result output format and transaction commit option.

The following is the syntax of the SET command.

SET [system_variable] [system_variable_value]

Note

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

1.2.5. Terminating Utility

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

SQL> EXIT

Note

For detailed information about the commands provided in tbSQL, refer to “1.6. Commands”.

1.3. System Variables

This section describes the system variables in tbSQL. Use the SET command to configure the system variables, and the SHOW command to display the results.

Following are the system variables that can be configured with the SET command.

System VariablesDefault ValueDescription
AUTOCOMMITOFFOption to enable the AUTOCOMMIT option.
AUTOTRACEOFFOption to display the statistical or plan information for the current query.
BLOCKTERMINATOR"." (0x2E)Character to indicate the end of a PSM statement input.
COLSEP" " (0x20)Column separator character used in the query result.
CONCAT"." (0x2E)Character that indicates the end of the substitution variable name.
DDLSTATSOFFOption to show the statistical or plan information for the running DDL statement.
DEFINE"&" (0x26)Character used to define a substitution variable.
DESCRIBEDEPTH 10Depth of the object specification shown by the DESCRIBE command.
ECHOOFFOption to display queries as they are being executed when a script is executed by using @ or START command.
EDITFILE".tbedit.sql"Default value of a filename used with the EDIT command.
ESCAPEOFFEscape character.
EXITCOMMITONOption to commit when terminating the utility.
FEEDBACK0Option to display the SQL statement result.
HEADINGONFile extension used when the extension is omitted.
HEADSEP"|" (0x7C)Line-break character used in column headings.
HISTORY50Size of the command history.
INTERVAL1Interval at which each statement in the LOOP command is executed.
LINESIZE80Length of a line on the screen.
LONG80Number of the characters that can represent data that is longer than VARCHAR type.
NEWPAGE1Number of empty lines added to the beginning of each page.
NUMFORMAT""Default column format for numeric data.
NUMWIDTH10Default width for outputting numeric data.
PAGESIZE24Number of lines to output on each page.
PAUSEOFFOption to wait for user input before displaying the next page.
RECSEPWRAPPEDWhere to display a row separator.
RECSEPCHAR" " (0x20)Row separator character.
ROWSONOption to display query statement result.
SERVEROUTPUTOFFOption to display the result of the DBMS_OUTPUT package.
SQLPROMPT"SQL> "Prompt string (same as PROMPT).
SQLTERMINATOR";" (0x3B)Character for terminating a SQL statement.
SUFFIX"sql"Default file extension.
TERMOUTONOption to display the result of executing commands in a script.
TIMEOFFOption to display the current time in the prompt.
TIMEOUT3Timeout for a server response to a PING command.
TIMINGOFFOption to display the processing time with the SQL and PSM results.
TRIMOUTONOption to truncate whitespaces at the end of each line, every time SQL or PSM results are displayed.
TRIMSPOOLOFFOption to truncate whitespaces at the end of each line while spooling.
UNDERLINE"-" (0x2D)Character used to underline headers.
VERIFYONOption to display the command after replacing substitution variables with values.
WRAPONOption to wrap the output to the next line when it is too long.

The following is an example of configuring system variables.

SET AUTOCOMMIT ON
SET PAGESIZE 32
SET TRIMSPOOL ON

1.3.1. AUTOCOMMIT

Executes commit after an INSERT, UPDATE, DELETE, MERGE, or PSM block is successfully executed.

The following is the syntax of AUTOCOMMIT.

  • Syntax

    SET AUTO[COMMIT] {ON|OFF|n}
    ItemDescription
    ONEnable AUTOCOMMIT.
    OFF

    Disable AUTOCOMMIT. (Default value)

    If set to OFF, the changes must be committed manually.

    n

    Execute commit when n number of INSERTs, UPDATEs, DELETEs, MERGEs, or PSM blocks were successfully executed.

    If set to 0, AUTOCOMMIT is disabled (OFF). If set to 1, AUTOCOMMIT is enabled (ON).

1.3.2. AUTOTRACE

Shows the statistical or plan information for the current query. DBA or PLUSTRACE privileges are required to use AUTOTRACE. PLUSTRACE role includes the permissions required to use AUTOTRACE. A user with the DBA privileges can create the PLUSTRACE role and grant it to other users. The creation script is $TB_HOME/scripts/plustrace.sql.

The following is the syntax for AUTOTRACE.

  • Syntax

    SET AUTOT[RACE] {ON|OFF|TRACE[ONLY]} [EXP[LAIN]] [STAT[ISTICS]] [PLANS[TAT]]
    • Input

      ItemDescription
      ONDisplay the statistical or plan information based on the query result and additional options.
      OFFDo not display the statistical or plan information. (Default value)
      TRACE[ONLY]Only display the statistical or plan information, without the query results, based on additional options.
    • Options

      The following options specify whether to show the statistical or plan information.

      OptionDescription
       If unspecified, display both plan and statistical information.
      EXP[LAIN]Display the plan information.
      STAT[ISTICS]Display the statistical information.
      PLANS[TAT]Display query execution information (processing time, number of processed rows, execution count, etc.) by node.

1.3.3. BLOCKTERMINATOR

Specifies a character to indicate the end of a tbPSM statement input.

The following is the syntax for BLOCKTERMINATOR.

  • Syntax

    SET BLO[CKTERMINATOR] {c|ON|OFF}
    ItemDescription
    cCharacter to indicate the end of a PSM program input. (Default value: period (.))
    ONEnable the PSM termination character. (Default value)
    OFFDisable the PSM termination character.

1.3.4. COLSEP

Specifies a column separator character to print between columns of the results.

The following is the syntax for COLSEP.

  • Syntax

    SET COLSEP {text}
    ItemDescription
    textColumn separator character string. (Default character: " ")

1.3.5. CONCAT

Specifies a character that indicates the end of the name of a substitution variable.

The following is the syntax for COLSEP.

  • Syntax

    SET CON[CAT] {c|ON|OFF}
    ItemDescription
    cCharacter that indicates the end of the substitution variable name. (Default character: ".")
    ONEnable CONCAT. (Default value)
    OFFDisable CONCAT.

1.3.6. DDLSTATS

Specifies whether to show the statistical or plan information for the running DDL statement. To use this system variable, AUTOTRACE must also be enabled.

The following is the syntax for DDLSTATS.

  • Syntax

    SET DDLSTAT[S] {ON|OFF}
    ItemDescription
    ONEnable DDLSTATS.
    OFFDisable DDLSTATS. (Default value)

1.3.7. DEFINE

Specifies the character used to define a substitution variable.

The following is the syntax for DEFINE.

  • Syntax

    SET DEF[INE] {c|ON|OFF}
    ItemDescription
    cCharacter that indicates a substitution variable. (Default character: "&")
    ONEnable DEFINE. (Default value)
    OFFDisable DEFINE.

1.3.8. DESCRIBE

Specifies the depth of the object specification shown by the DESCRIBE command.

The following is the syntax for DESCRIBE.

  • Syntax

    SET DESCRIBE DEPTH {n}
    ItemDescription
    nDepth of object specification to ouput recursively. (Default value: 10)

1.3.9. ECHO

Specifies whether to display queries as they are being executed when a script is executed by using @ or START command

The following is the syntax for ECHO.

  • Syntax

    SET ECHO {ON|OFF}
    ItemDescription
    ONEnable ECHO.
    OFFDisable ECHO. (Default value)

1.3.10. EDITFILE

Specifies the default value of a filename used with the EDIT command. When the extension is omitted, the value set in SUFFIX is used.

The following is the syntax for EDITFILE.

  • Syntax

    SET EDITF[ILE] filename[.ext]
    ItemDescription
    filename[.ext]Filename to use with the EDIT command. (Default value: .tbedit.sql)

1.3.11. ESCAPE

Specifies the escape character. If ESCAPE is enabled and the escape character is appended at the front of '&<character string>', it is not recognized as a substitution variable.

The following is the syntax for ESCAPE.

  • Syntax

    SET ESC[APE] {c|ON|OFF}
    ItemDescription
    cEscape character. (Default value: "\")
    ONEnable ESCAPE.
    OFFDisable ESCAPE. (Default value)

1.3.12. EXITCOMMIT

Specifies whether to commit when terminating the utility.

The following is the syntax for EXITCOMMIT.

  • Syntax

  • SET EXITC[OMMIT] {ON|OFF}
    ItemDescription
    ONEnable EXITCOMMIT. (Default value)
    OFFDisable EXITCOMMIT.

1.3.13. FEEDBACK

Specifies whether to display the SQL statement result.

The following is the syntax for FEEDBACK.

  • Syntax

    SET FEED[BACK] {n|ON|OFF}
    ItemDescription
    nMinimum number of rows required to output the results. (Default value: 0)
    ONEnable FEEDBACK. (Default value)
    OFFDisable FEEDBACK.

1.3.14. HEADING

Specifies whether to display column headers for query results.

The following is the syntax for HEADING.

  • Syntax

    SET HEA[DING] {ON|OFF}
    ItemDescription
    ONEnable HEADING. (Default value)
    OFFDisable HEADING.

1.3.15. HEADSEP

Specifies the line-break character used in column headings.

The following is the syntax for HEADSEP.

  • Syntax

    SET HEADS[EP] {c|ON|OFF}
    ItemDescription
    cLine-break character. (Default value: "|")
    ONEnable HEADSEP. (Default value)
    OFFDisable HEADSEP.

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. (Default value: 50)

1.3.17. INTERVAL

Specifies the interval for executing each statement in the LOOP command.

The following is the syntax for INTERVAL.

  • Syntax

    SET INTER[VAL] {n}
    ItemDescription
    nInterval time in seconds. (Default value: 1)

1.3.18. LINESIZE

Specifies the length of a line on the screen. Minimum value is 1 and the maximum value depends on the OS.

The following is the syntax for LINESIZE.

  • Syntax

    SET LIN[ESIZE] {n}
    ItemDescription
    nLength of a line on the screen. (Default value: 80)

1.3.19. LONG

Specifies the output size of the CLOB, BLOB, NCLOB, LONG, or XML data type. Maximum length is 2 billion.

The following is the syntax for LONG.

  • Syntax

    SET LONG {n}
    ItemDescription
    nDefault output size for large object data types. (Default value: 80)

1.3.20. NEWPAGE

Specifies the number of empty lines added to the beginning of each page.

The following is the syntax for NEWPAGE.

  • Syntax

    SET NEWP[AGE] {1|n|NONE}
    ItemDescription
    nNumber of empty lines. (Default value: 1)

1.3.21. NUMFORMAT

Specifies the default column format of numeric data. This applies numeric columns except those with FORMAT defined through the COLUMN command.

The following is the syntax for NUMFORMAT.

  • Syntax

    SET NUMF[ORMAT] {fmt_str}
    ItemDescription
    fmt_str

    Default column format of numeric data. (Default value: "")

    For more information about the number type, refer to “1.7. Column Formats”.

1.3.22. NUMWIDTH

Specifies the default width for outputting numeric data. This value cannot exceed the size set in LINESIZE.

The following is the syntax for NUMWIDTH.

  • Syntax

    SET NUM[WIDTH] {n}
    ItemDescription
    nDefault width for outputting numeric data. (Default value: 10)

1.3.23. PAGESIZE

Specifies the number of lines to output on each page.

The following is the syntax for PAGESIZE.

  • Syntax

    SET PAGES[IZE] {n}
    ItemDescription
    nNumber of lines per page. (Default value: 24)

1.3.24. PAUSE

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

The following is the syntax for PAUSE.

  • Syntax

    SET PAU[SE] {ON|OFF}
    ItemDescription
    ONEnable PAUSE.
    OFFDisable PAUSE. (Default value)

1.3.25. RECSEP

Specifies where to print the row separator.

The following is the syntax for RECSEP.

  • Syntax

    SET RECSEP {WR[APPED]|EA[CH]|OFF}
    ItemDescription
    WRAPPEDDisplay a separator when a row is wrapped. (Default value)
    EACHDisplay a separator following each row.
    OFFDisable RECSEP.

1.3.26. RECSEPCHAR

Specifies the row separator character to print after each line of the size, LINESIZE.

The following is the syntax for RECSEPCHAR.

  • Syntax

    SET RECSEPCHAR {c}
    ItemDescription
    cRow separator. (Default value: " ")

1.3.27. ROWS

Specifies whether to display query statement result.

The following is the syntax for ROWS.

  • Syntax

    SET ROWS {ON|OFF}
    ItemDescription
    ONEnable ROWS. (Default value)
    OFFDisable ROWS.

1.3.28. 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
    ONEnable SERVEROUTPUT.
    OFFDisable SERVEROUTPUT. (Default value)
    nSERVEROUTPUT buffer size. (Default value: 1000000)

1.3.29. SQLPROMPT

Specifies the prompt string.

The following is the syntax for SQLPROMPT.

  • Syntax

    SET SQLP[ROMPT] {prompt_string}
    ItemDescription
    prompt_string

    Prompt string. (Default value: "SQL>").

    If the string is enclosed in braces ({ }), it is recognized as an environment variable. For example, if '{ISQL_PROMPT}' is specified, the value of $ISQL_PROMPT is used as the prompt. The environment variable name is case sensitive.

1.3.30. 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. (Default value: ";")
    ONEnable SQLTERMINATOR.
    OFFDisable SQLTERMINATOR.

1.3.31. SUFFIX

Specifies the default file extension.

The following is the syntax for SUFFIX.

  • Syntax

    SET SUF[FIX] {extension}
    ItemDescription
    extensionDefault file extension. (Default value: sql)

1.3.32. TERMOUT

Specifies whether to display the result of executing commands in a script.

The following is the syntax for TERMOUT.

  • Syntax

    SET TERM[OUT] {ON|OFF}
    ItemDescription
    ONEnable TERMOUT. (Default value)
    OFFDisable TERMOUT.

1.3.33. TIME

Specifies whether to display the current time in the prompt.

The following is the syntax for TIME.

  • Syntax

    SET TI[ME] {ON|OFF}
    ItemDescription
    ONEnable TIME.
    OFFDisable TIME. (Default value)

1.3.34. TIMEOUT

Specifies the timeout for a server response to a PING command.

The following is the syntax for TIMEOUT.

  • Syntax

    SET TIMEOUT {n}
    ItemDescription
    nTimeout for a server response. The unit is second. (Default value: 3 seconds)

1.3.35. TIMING

Specifies whether to display the processing time with the SQL and PSM statement results.

The following is the syntax for TIMING.

  • Syntax

    SET TIMI[NG] {ON|OFF}
    ItemDescription
    ONEnable TIMING.
    OFFDisable TIMING. (Default value)

1.3.36. TRIMOUT

Specifies whether to truncate whitespaces at the end of each line, every time SQL or PSM results are displayed.

The following is the syntax for TRIMOUT.

  • Syntax

    SET TRIM[OUT] {ON|OFF}
    ItemDescription
    ONEnable TRIMOUT. (Default value)
    OFFDisable TRIMOUT.

1.3.37. TRIMSPOOL

Specifies whether to truncate to truncate whitespaces at the end of each line while spooling.

The following is the syntax for TRIMSPOOL.

  • Syntax

    SET TRIMS[POOL] {ON|OFF}
    ItemDescription
    ONEnable TRIMSPOOL.
    OFFDisable TRIMSPOOL. (Default value)

1.3.38. UNDERLINE

Specifies the character used to underline headers.

The following is the syntax for UNDERLINE.

  • Syntax

    SET UND[ERLINE] {c|ON|OFF}
    ItemDescription
    cUnderline character. (Default value: "-")
    ONEnable UNDERLINE. (Default value)
    OFFDisable UNDERLINE.

1.3.39. VERIFY

Specifies whether to display the command after replacing substitution variables with values.

The following is the syntax for VERIFY.

  • Syntax

    SET VER[IFY] {ON|OFF}
    ItemDescription
    ONEnable VERIFY. (Default value)
    OFFDisable VERIFY.

1.3.40. WRAP

Specifies whether to wrap the output to the next line when it exceeds the line size.

The following is the syntax for WRAP.

  • Syntax

    SET WRA[P] {ON|OFF}
    ItemDescription
    ONEnable WRAP. (Default value)
    OFFDisable WRAP.

1.4. Basic Functions

tbSQL is mainly used for executing user entered SQL statements or PSM programs. This section describes the basic and additional functions of tbSQL.

1.4.1. Entering Commands

A SQL statement, PSM program, or tbSQL command can be entered at the tbSQL command prompt. Each command can be entered in the same way.

The following describes how to enter each command.

SQL Statement

How to enter a SQL statement:

  • SQL Statement

    In general, a SQL statement is entered at the command prompt. One SQL statement can span over multiple lines. To cancel an entry, enter a blank line.

  • Line Feed

    When entering a SQL statement over several lines, a line feed can be entered anywhere except within a string. For readability, it is recommended to change lines at the end of each clause.

  • Inserting Comments

    Comments can be inserted in the middle of a SQL statement by using two dashes (--) and continues to the end of the line. An entire line can be a comment, or a comment can be placed in the middle of a line after a string.

  • Using Pre-saved Statements

    Once a SQL statement is entered, it is saved in the SQL buffer of tbSQL. The saved SQL can be modified or used as is. If modified, it will be saved as a new SQL in the SQL buffer.

    SQL statements and PSM programs are saved in the SQL buffer. Depending on the OS, the UP (↑) arrow or DOWN (↓) arrow key can be used to select the saved statement. One line of a saved SQL is displayed with each key press. This allows the user to retrieve all or part of the saved SQL statement from the buffer.

The following example illustrates how to enter a SQL statement in tbSQL.

SQL> SELECT ENAME, SALARY, ADDR
    FROM EMP
    -- this is a comment.
    WHERE DEPTNO = 5;
SQL>

PSM Programs

PSM program consists of multiple SQL or PSM statements. Each SQL statement is terminated with a semicolon (;). When the user starts to enter PSM program, tbSQL will be automatically switched to PSM program input mode. In the PSM program input mode, SQL statements are not executed until the entire program is entered.

The statements that trigger tbSQL to switch to PSM program input mode are anonymous blocks such as DECLARE and BEGIN, and those that create a procedure, function, and trigger (CREATE (OR REPLACE) PROCEDURE, FUNCTION, and TRIGGER).

PSM programs can be entered like SQL statements.

How to enter a PSM program:

  • PSM Program

    A PSM program can span over multiple lines. To cancel a SQL statement entry, enter a blank line. To cancel a PSM program entry, enter the block terminator character (BLOCKTERMINATOR). By default, the character is set to a PERIOD (.). The block terminator character must be entered on a separate line by itself without any other strings.

  • Using Pre-saved Statements

    Once a program is entered, it is saved in the SQL buffer for reuse.

  • Inserting Comments

    Comments are entered in the same way as in SQL statements.

The following example illustrates how to enter an anonymous block in tbSQL.

SQL> DECLARE
    deptno NUMBER(2);
    BEGIN
        deptno := 5;
        UPDATE EMP SET SALARY = SALARY * 1.05
        WHERE DEPTNO = deptno;
        -- this is a comment.
    END;
    .
SQL>

In the previous example, there is a comment line and a period (.), which terminates the PSM program, below the END statement. The last line contains only the block terminator character (a period) without any other characters or strings.

Note

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

tbSQL Utility Commands

tbSQL utility commands are used to execute SQL or manage Tibero database. For more detailed information about tbSQL utility commands, refer to “1.6. Commands”.

1.4.2. Executing Commands

There are 3 ways to execute a command from the command prompt in tbSQL.

  • Executing a PSM program or SQL statement saved in SQL buffer

    SQL buffer saves only the last executed SQL statement or PSM program. To execute the SQL statement or tbPSM program, enter 'RUN' or '/' command.

  • Executing a SQL statement

    Enter the statement and a semicolon (;) at the end to execute SQL statement.

  • Executing SQL statement and saving it in SQL buffer

    To execute the SQL statement or PSM program and save it in the butter, enter the '/' command. The command must be on a separate line by itself like the aforementioned terminator character (.).

There is no separate tbSQL utility command for executing commands unlike SQL statement or PSM program. The commands are not saved in the SQL buffer, and each command is automatically executed as it is entered.

The following example illustrates how to execute a SQL statement that is saved in the SQL buffer.

SQL> SELECT ENAME, SALARY, ADDR
    FROM EMP
    -- this is a comment.
    WHERE DEPTNO = 5;
......Execution result (1)......
SQL> /
......Execution result (2)......
SQL>

At the first SQL prompt, a SQL statement is immediately executed when it is terminated with a semicolon (;). At the second SQL prompt, the '/' command executes the last SQL statement saved in the SQL buffer, which is the SQL entered at the first prompt. Hence, the execution result (1) and (2) will be the same.

The following example illustrates how to execute the previous SQL statement using the slash (/) command. In this case, a semicolon (;) is not entered at the end of the SQL statement.

SQL> SELECT ENAME, SALARY, ADDR
    FROM EMP
    -- this is a comment.
    WHERE DEPTNO = 5
    /
......Execution result......
SQL>

1.4.3. Additional Functions

This section describes the functions for inserting a comment, auto commit, executing OS command, and saving output, which are the most commonly used functions in tbSQL.

Inserting Comments

Comments can be inserted in the following two ways.

  • Using /* … */

    As in C or C++ programing language, the parts enclosed between /* and */ are treated as a comment in tbSql.

    A comment cannot be nested in another comment.

  • Using Double Dashes (--)

    When double dashes (--) are encountered, they mark the beginning of a comment until the end of the line.

    This comment can be placed anywhere as with /* … */, except on a line with a period that indicates the end of a PSM program.

    Hence, the following script file will cause an error.

    (PSM Program)
    .-- wrong comment 
    RUN

Auto Commit

A SQL execution does not update the database until the transaction is committed. A transaction usually consists of multiple SQL statements.

In tbSQL, the AUTOCOMMIT parameter can be set to ON or OFF. By default, it is set to OFF.

Use the SET AUTOCOMMIT command to set auto commit on or off. To check the current setting, use the SHOW AUTOCOMMIT command.

Executing OS Commands

To execute an OS command in tbSQL, use the HOST command.

The following example illustrates how to list all script files with .sql extension. The '!' command can be used in place of the HOST command.

SQL> HOST dir *.sql
..... OS command execution result .....
SQL>

After executing an OS command, the tbSQL prompt is displayed again to accept other tbSQL commands.

If the HOST or '!' command is entered without additional commands, the tbSql interface switches to the OS command line interface. To return to tbSQL, enter EXIT.

SQL> !
$ dir *.sql
..... OS command execution result .....
$ EXIT
SQL>

Saving the Output

To save all inputs and outputs of tbSQL as a text file, use the SPOOL command. The SPOOL command saves all user-entered SQL statements or PSM programs, tbSQL utility commands, query results, program execution results, and tbSQL command prompts.

If you execute the SPOOL command, it will start saving from the next line. To stop the command, enter SPOOL OFF and any following lines are not saved.

The following example illustrates how to use the SPOOL command. If the specified file, save.txt, already exists, the existing file will be overwritten by the new file.

SQL> SPOOL save.txt
Spooling is started.
SQL> SELECT
    *
    FROM DUAL;

DUMMY
-----
X

1 row selected.

SQL> SPOOL OFF
Spooling is stopped: save.txt

The following is an example of the save.txt file from the previous example.

SQL> SELECT
    *
    FROM DUAL;

DUMMY
-----
X

1 row selected.

SQL> SPOOL OFF

Any user-entered SQL statements, query results, and commands are saved in th file until SPOOL OFF command is executed.

1.5. Advanced Functions

This section describes the advanced functions of tbSQL including batch processing using a script and DBA functions for managing Tibero.

1.5.1. Script Function

A script consists of SQL statements, PSM programs, and tbSQL utility commands used to perform batch processing. When the script is executed in tbSQL, the commands in the script are executed sequentially.

Creating a Script

A script file can be created and edited externally and executed in tbSQL, or an external editor can be executed from tbSQL by specifying the editor to use.

The following example illustrates how to execute vi, an external editor, in tbSQL.

$ export TB_EDITOR=vi

To edit a script file using an external editor, use the EDIT command with the file name. The file extension can be omitted if the extension is same as the value set in the SUFFIX system variable.

The following example illustrates how to call an external editor to edit the script file, run.sql.

SQL> EDIT run

A SQL statement, PSM program, or tbSQL command can be added to a script file as follows:

  • Command Entry

    A command can be entered similar to a command line entry, and can span over multiple lines.

  • Terminating a SQL Statement and PSM Program

    A SQL statement must be terminated with a semicolon (;), and a PSM program must be terminated with a (.) on the last line.

  • Inserting a Comment

    Comments can be added to a script file.

When a script is executed, the SQL statements in the script are executed immediately. A PSM program is executed with the RUN or '/' command.

The following example shows a script file that performs multiple operations on the table EMP. Blank lines are allowed between lines.

-- SQL statement 
SELECT ENAME, SALARY, ADDR FROM EMP
    WHERE DEPTNO = 5;
UPDATE EMP SET SALARY = SALARY * 1.05
    WHERE DEPTNO = 5;

-- PSM program
DECLARE
    deptno NUMBER(2);
BEGIN
    deptno := 20;
    UPDATE EMP SET SALARY = SALARY * 1.05
    WHERE DEPTNO = deptno;
END;

RUN -- Execute PSM program
/* Reflect the final updates. */
COMMIT;

Executing a Script

To execute a script file, use the START or @ command with the file name. The file extension can be omitted if the extension is the same as the SUFFIX system variable (sql).

The following example illustrates how to execute a script file, run.sql, using the two commands that produce the same results.

SQL> START run
SQL> @run

One or more script files can be executed from within a script file by calling the START or @ command. Make sure not to create an infinite loop when executing a script file recursively.

The @ command can be executed when starting tbSQL to execute a script at startup. This is useful when executing a batch program from the OS.

The following example illustrates how to run a script file, run.sql, at tbSql startup.

$ tbsql dbuser/dbuserpassword @run

Or the redirect shell command can be used to execute the script as follows:

$ tbsql dbuser/dbuserpassword < run.sql

1.5.2. DBA Functions

DBA functions can be executed in tbSQL by loggin into Tibero as a user with DBA privileges.

The following illustrates how to log in as a SYS user with DBA privileges.

$ tbsql sys/syspassword

The user can also connect to the database as a DBA after starting tbSQL by using the CONNECT command.

The following illustrates how to connect to the database as a DBA using the CONNECT command.

SQL> CONNECT sys/syspassword

A DBA can perform the following task in tbSQL:

  • TerminateTibero

    Terminate Tibero using the TBDOWN tbSQL command.

1.5.3. User Access Control

tbSQL can restrict users from executing certain commands.

For this, tbSQL references the CLIENT_ACCESS_POLICY table created by the SYS user. DBA can define the access policy to grant privileges to execute commands to specific users.

tbSQL loads user information when the user connects to the database, and checks the privileges each time the user executes a command to allow/prohit its execution. The user information is released when the user disconnects from the database.

Note

User privilege is not checked for SYS users.

Creating Access Control Table

The access control table can only be created by a SYS user by executing the $TB_HOME/scripts/client_policy.sql file.

Note

User privileges will not be checked if the table does not exist or could not be created.

A detailed description of the CLIENT_ACCESS_POLICY is as follows:

CLIENT  VARCHAR2(32)   NOT NULL
USERID  VARCHAR2(128)
ACTION  VARCHAR2(256)
POLICY  VARCHAR2(64)
ItemDescription
CLIENT

Client program name.

This is case-sensitive and uses tbSQL

USERID

USERID(s).

Specify as follows and wilcard (%) is allowed.

  • TIBERO
  • T% (All users that start with T)
  • % (All users)
ACTIONCommand.
POLICY

Access policy.

Set to DISABLED.

Configuring Command Access Control

A record must be added to the CLIENT_ACCESS_POLICY to restrict access to tbSQL, SQL, or PSM commands. To allow access to these commands again, the record must be deleted.

CLIENT   USERID       ACTION            POLICY
-------- ------------ ----------------  ----------
tbSQL    TIBERO       HOST              DISABLED
tbSQL    %            INSERT            DISABLED 
tbSQL    PUBLIC       UPDATE            DISABLED

The following are the command lists:

  • tbSQL Commands

    ACCEPT           APPEND           ARCHIVE           CHANGE
    CLEAR            COLUMN           CONNECT           DEFINE
    DEL              DESCRIBE         DISCONNECT        EDIT
    EXECUTE          EXIT             EXPORT            HELP (?)
    HISTORY          HOST (!)         INPUT             LIST
    LOADFILE         LOOP             LS                PASSWORD
    PAUSE            PING             PRINT             PROMPT
    QUIT             REMARK           RESTORE           RUN
    SAVE             SET              SHOW              SPOOL
    START (@, @@)    TBDOWN           UNDEFINE          VARIABLE
    WHENEVER 
  • SQL Commands

    ALTER             ANALYZE          AUDIT             CALL
    COMMENT           COMMIT           CREATE            DELETE
    DROP              EXPLAIN          FLASHBACK         GRANT
    INSERT            LOCK             MERGE             NOAUDIT
    PURGE             RENAME           REVOKE            ROLLBACK
    SAVEPOINT         SELECT           SET CONSTRAINTS   SET ROLE
    SET TRANSACTION   TRUNCATE         UPDATE 
  • PSM Commands

    BEGIN              DECLARE 

The following is an example of using the user access control function.

..... Connect as SYS user .....
SQL> CONNECT SYS
..... Configure Access Control .....
SQL> INSERT INTO CLIENT_ACCESS_POLICY VALUES ('tbSQL', 'TIBERO', 'SELECT', 'DISABLED'); 
..... Connect as TIBERO user .....
SQL> CONNECT TIBERO
SQL> SELECT * FROM DUAL;
TBS-70082: The 'SELECT' command has been disabled.

1.5.4. Encrypting Connection String

tbSQL saves database access information (connect_string) in an encrypted file (wallet).

The database connection information used in tbSQL

Creating an Encrypted File

After accessing a database in tbSQL, the user can create an encrypted file using the SAVE CREDENTIAL command.

The following illustrates how to encrypt the database connection information by setting ISQL_WALLET_PATH to the wallet.dat file in the current directory.

$ export ISQL_WALLET_PATH=./wallet.dat
$ tbsql

tbSQL 6

TmaxData Corporation Copyright (c) 2008-. All rights reserved.

Can't login with the wallet file.
Login the database and SAVE CREDENTIAL again.

Enter Username: dbuser
Enter Password: dbuserpassword
Connected to Tibero.

SQL> SAVE CREDENTIAL
Complete to generate the wallet file.

In this example,

To resolve the error, reconnect to the database and create the './wallet.dat' file using the SAVE CREDENTIAL command.

The following illustrates how to encrypt the database connection information in the wallet.dat file of the current directory, without setting the environment variable of ISQL_WALLET_PATH.

$ tbsql

tbSQL 6

TmaxData Corporation Copyright (c) 2008-. All rights reserved.

SQL> CONN dbuser/dbuserpassword
Connected to Tibero.

SQL> SAVE CREDENTIAL "./wallet.dat"
Complete to generate the wallet file.

Execute SAVE CREDENTIAL with the './wallet.dat' file to create the wallet by encrypting the database connection information.

Using an Encrypted File

Set the ./wallet.dat file created in the previous example to the ISQL_WALLET_PATH before starting tbSQL to be able to reuse the database connection information that was used before configuring the encrypted file.

The following illustrates how to access the database by using the file specified in ISQL_WALLET_PATH:

$ tbsql

tbSQL 6

TmaxData Corporation Copyright (c) 2008-. All rights reserved.

Connected to Tibero.

Note

To use the encrypted file, it must be set in ISQL_WALLET_PATH. The encrypted file is only available in tbSQL.

To use the same file in another tbSQL instance, the encrypted file must be reconfigured using the aforementioned steps.

This function is not available in the Windows environment.

1.6. Commands

This section describes, in detail, the commands provided in tbSQL.

Following is the syntax for the tbSQL utility commands.

COM[MAND] param {choice1|choice2} [option] [arg]*

The following describes the special characters that define the command syntax:

ItemDescription
Brackets ([ ])Optional argument.

In the syntax, the [MAND], [option], and [arg] can be omitted.

Curly braces ({ })

Mutually exclusive argument where one is required.

In the syntax, choice1 and choice2 are separated by (|) inside curly braces ({ }). One of the choices must be entered.
Vertical bar (|)OR operator. A separator for mutually exclusive arguments.
Asterisk (*)None or multiple argument values can be entered.

In the syntax, [arg] with an asterisk (*) indicates that it can be excluded or entered multiple times.

Italic lettersMust be replaced by another string depending on the command type.
CaseCommands are not case-sensitive.

The following are examples of valid commands.

COMMAND param choice1
COM param choice1 option
COM param choice2 arg1 arg2 arg3

tbSQL includes commands for managing databases or processing SQL statements. The following describes the syntax, parameters, and example of each commands, in alphabetical order.

The following are the tbSQL commands.

CommandDescription
!

Executes an OS command.

Same as the HOST command.

%Re-executes the command saved in the history buffer.
@, @@

Executes a script file.

Same as the START command.

/

Executes PSM programs or SQL statements that are saved in the SQL buffer.

Same as the RUN command.

ACCEPTReceives user input and saves it in a specified substitution variable.
ARCHIVE LOGDisplays redo log file information.
CHANGEFinds and replaces a specified pattern with a new pattern in the current line of the SQL buffer.
CLEARInitializes or deletes the specified option.
COLUMNSpecifies the display properties of a specified column.
CONNECTConnects to the database with a specified user ID.
DEFINEDefines or displays substitution variables.
DELDeletes the line that is saved in the SQL buffer.
DESCRIBEDisplays the column information of a 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.
EXECUTEExecutes a PSM statement.
EXIT

Terminates tbSQL.

Same as the QUIT command.

EXPORTOutputs SELECT statement results or table data to a file.
HELPDisplays help.
HISTORYDisplays command execution history.
HOST

Executes an OS command.

Same as the '!' command.

INPUTAdds a new line after the last line in the SQL buffer.
LISTDisplays specified lines from the SQL buffer.
LOADFILESaves a Tibero table in a format that can be recognized by Oracle SQL*Loader.
LOOPInfinitely repeats a statement.
LSDisplays the database objects created by the current user.
PASSWORDChanges the user password.
PAUSEPauses the execution until the user presses the <Enter> key.
PINGDisplays whether a specified database allows connections.
PRINTDisplays user-defined bind variables.
PROMPTDisplays a user-defined SQL or an empty line.
QUIT

Terminates tbSQL utility.

Same as the EXIT command.

RESTORERestores the selected data from a file.
RUN

Executes a PSM program or SQL statements that are saved in the SQL buffer.

Same as the '/' command.

SAVESaves the selected data to a file.
SETSets the system variables of tbSQL.
SHOWDisplays the system variables of tbSQL.
SPOOLStarts or terminates the process that saves all screen output to an external file.
START

Executes a script file.

Same as the @ command.

TBDOWNTerminates Tibero.
UNDEFINEDeletes one or more substitution variables.
VARIABLEDefines a user-defined bind variable.
WHENEVERDefines the actions to take when an error occurs.

1.6.1. !

Executes an OS command in tbSQL. The HOST command can be used instead of this command.

The following is the syntax for the '!' command.

  • Syntax

    ! [command]
    OptionDescription
     If only the '!' command is entered without an OS command, the window will change to the OS command prompt where multiple OS commands can be entered.

    To return to the tbSQL command prompt, enter the EXIT command.

    commandOS command.
  • Example

    SQL> ! dir *.sql
    SQL> !

1.6.2. %

Re-executes the command stored in the tbSQL history buffer without re-entering it.

The following is the syntax for the '%' command.

  • Syntax

    % number
    OptionDescription
    numberCommand number in the history buffer.
  • Example

    SQL> history
      1: set serveroutput on
      2: set pagesize 40
      3: select 1 from dual;
    SQL> %3
    
              1
    -----------
              1
    
    1 row selected.
    

1.6.3. @, @@

Executes the script file. If the script file has the same file extension as the SUFFIX system variable, the extension can be omitted. tbSQL finds the specified script file in the current directory.

The system variable set using the SET command before executing the script remains in effect while executing the script. Use the EXIT or QUIT command in a script file to terminate tbSQL.

The START command can be used instead of the '@' command.

The following is the syntax for the '@' command.

  • Syntax

    @ {filename}
    ItemDescription
    filenameScript file name.
  • 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 user input and saves it in a specified substitution variable. The specified value will automatically replace any string in a SQL statement or PSM program specified as &variable.

The following is the syntax for the ACCEPT command.

  • Syntax

    ACC[EPT] variable [FOR[MAT] format] [DEF[AULT] default]
    [PROMPT statement|NOPR[OMPT]]
    • Input

      ItemDescription
      variableSubstitution variable name. One will be created if it does not exist.
    • Options

      OptionDescription
      FOR[MAT] formatFormat of the substitution variable. If the value does not match the format, an error occurs.
      DEF[AULT] defaultDefault value of the substitution variable.
      PROMPT statementDisplay a prompt before receiving the value of a substitution variable from the user.
      NOPR[OMPT]Wait for an input without displaying a prompt.
  • Example

    SQL> ACCEPT name PROMPT 'Enter name : '
    Enter name : 'John'
    SQL> SELECT &name FROM DUAL;
    At line 1, column 8
    old value : SELECT &name FROM DUAL
    new value : SELECT 'John' FROM DUAL
    
    'JOHN'
    ------
    John
    
    1 row selected.
    
    SQL>

1.6.6. ARCHIVE LOG

Displays redo log file information.

The following is the syntax for the ARCHIVE LOG command.

  • Syntax

    ARCHIVE LOG LIST
  • Example

    SQL> ARCHIVE LOG LIST
    
    NAME                            VALUE
    ------------------------------- ------------------------------------------------
    Database log mode               Archive Mode
    Archive destination             /home/tibero/database/tibero/archive
    Oldest online log sequence      300
    Next log sequence to archive    302
    Current log sequence            302
    
    SQL>

1.6.7. CHANGE

Finds and replaces a specified pattern with a new pattern in the current line of the SQL buffer. Generally, the current line of the last executed SQL statement is the last line. Refer to the example below to change the current line.

The following is the syntax for the CHANGE command.

  • Syntax

    C[HANGE] delim old [delim [new [delim [option]]]]
    • Input

      ItemDescription
      delim

      Delimiter excluding numbers.

      Characters used for a delimiter must not be included in either the old or new pattern.

      old

      New pattern. This is not case-sensitive.

      Words, such as duala and ksc911, as well as ..., which indicates a random pattern, can be used. Refer to the following example.

    • Options

      OptionDescription
      delim

      Delimiter excluding numbers.

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

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

      • c: replace user-selected pattern from the current line.

      • a: replace all patterns from the entire statement.

  • Example

    Since the current line is always the last line by default, the DUAL on the second line is replaced with T.

    SQL> SELECT *
        FROM DUAL;
    ..... SQL execution results .....
    SQL> C/DUAL/T
        FROM T
    SQL>

    To change the current line, enter a line number.

    SQL> 5
        5 WHERE ROWNUM < 5 AND

    A random pattern can be specified by using ..., which can be placed in the front, back, or middle of a word.

    SQL> CHANGE /RE...AND/RE ROWNUM >= 5 AND/
        5 WHERE ROWNUM >= 5 AND
    SQL> CHANGE /...AND/WHERE ROWNUM < 3/
        5 WEHRE ROWNUM < 3
    SQL> CHANGE /WHE.../WHERE ROWNUM < 5 AND/
        5 WHERE ROWNUM < 5 AND

    Use the 'a' option to replace any occurrences of the old pattern from the entire statement. The '*' character in the fist line is changed to the new pattern.

    SQL> SELECT *
        FROM DUAL;
    ..... SQL execution results .....
    SQL> C/*/'replaced'/a
        SELECT 'replaced'
        FROM DUAL;
    SQL>

1.6.8. CLEAR

Initializes or deletes the specified option.

The following is the syntax for the CLEAR command.

  • Syntax

    CL[EAR] [option]
    • options

      OptionDescription
      BUFF[ER]Clear the SQL buffer.
      SCR[EEN]Clear the screen.
      COL[UMNS]Initialize the display properties of all columns.
  • Example

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

1.6.9. COLUMN

Specifies the display properties of a specified column. When the column name is specified, only the display properties of the column is displayed. Otherwise, those of all columns are displayed.

The following is the syntax for the COLUMN command:

  • Syntax

    COL[UMN] [name [option]]
    • Input

      ItemDescription
      nameColumn name.
    • Options

      OptionDescription
      CLE[AR]Initialize the column's display properties.
      FOR[MAT] textSet the column format. For more detailed information, refer to “1.7. Column Formats”.
      HEA[DING] textSet the column heading.
      NEW_V[ALUE] variableSet the variable to save the column value.
      WRA[PPED]Wrap the text to the next line if the column data is too long.
      TRU[NCATED]Truncate the data if the column data exceeds the limit.
      ONTurn on the output property of the column.
      OFFTurn off the output property of the column.
  • Example

    SQL> COLUMN
    SQL> COLUMN empno
    SQL> COLUMN empno CLEAR
    SQL> COLUMN empno FORMAT 999,999
    SQL> COLUMN ename FORMAT A10
    SQL> COLUMN sal HEADING the salary of this month
    SQL> COLUMN sal OFF
    SQL> COLUMN job WRAPPED
    SQL> COLUMN job TRUNCATED

1.6.10. CONNECT

Connects to the database with a specified user ID. If the user name or password is not specified, tbSQL prompts for the name or password.

The CONNECT command commits the last transaction, disconnects from the database, and then tries to reconnect. If the new connection attempt fails, the previous connection cannot be recovered.

The following is the syntax for the CONNECT command.

  • Syntax

    CONN[ECT] {username[/password[@connect_identifier]]}
    • Input

      ItemDescription
      usernameUser name.
    • Options

      OptionDescription
      passwordPassword of the user.
      connect_identifier

      Database connection string.

      This option includes the IP, PORT, and DB_NAME information. It can be set in tbdsn.tbr of $TB_HOME/client/config directory, or Data Source (ODBC) in Windows. The latter is searched first.

  • Example

    SQL> CONNECT dbuser/dbuserpassword@db_id

1.6.11. DEFINE

Defines or displays substitution 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 substitution variables are displayed.
    variableSubstitution variable name.
    variable = valueName and default value of the substitution variable.
  • Example

    SQL> DEFINE NAME
    ..... Outputs a substitution variable 'NAME'. .....
    SQL> DEFINE NAME = 'SMITH'
    ..... Defines SMITH as a default value of the substitution variable.....
    SQL> DEFINE
    ..... Outputs all the substitution variables. .....

1.6.12. 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]
    ItemDescription
    numberDelete the line with the specified number.
    number numberDelete all lines in the specified range.
    number LASTDelete all lines starting from the specified number to the last line.
    LASTDelete the last line.
  • Example

    SQL> DEL 1
    ..... Deletes the first line. .....
    SQL> DEL 1 3
    ..... Deletes all lines starting from the first line to the third line. .....
    SQL> DEL 1 LAST
    ..... Deletes all lines starting from the first line to the last line. .....
    SQL> DEL LAST
    ..... Deletes the last line. .....

1.6.13. DESCRIBE

Displays the column information of the specified object. An object can be a table, view, synonym, function, procedure, or package.

  • For tables and views, the column name, data type, constraint, index information, maximum length, precision, scale, etc. will be displayed.

  • For functions and procedures, parameter information (name, data type, IN/OUT) will be displayed. For packages, all details of the functions and procedures of the package will be displayed.

  • The column information about an object owned by a specified user can also be displayed. The name of the owner must be specified. Otherwise, the the current username will be used by default.

The following is the syntax for the DESCRIBE command.

  • Syntax

    DESC[RIBE] [schema.]{object}
    ItemDescription
    schemaSchema (or owner) that contains the target object.
    objectObject to display column information for.
  • Example

    SQL> DESCRIBE emp
    SQL> DESC scott.emp

1.6.14. DISCONNECT

Closes the connection to the current database. This command terminates the currently running transaction but does not terminate tbSQL.

When a transaction is terminated without being disconnected from the database, the transaction will continue to access to the database. For security, if a CONNECT command is included in a script file, it is recommended to execute the DISCONNECT command to terminate a transaction.

The following is the syntax for the DISCONNECT command.

  • Syntax

    DISC[ONNECT]

1.6.15. EDIT

Edits the contents of a SQL buffer or a certain file by using an external editor. An external editor can be specfied in the environment variable $TB_EDITOR.

If $TB_EDITOR is not set, this command references $EDITOR. If neither variables are set, vi editor is used. If the SQL buffer is empty, an error will be returned.

A file name can be specified without an extension if its extension is the default value. The default value of the SUFFIX system variable is .sql, and it can be changed using the SET command. tbSQL searches for the specified file in the current directory.

The following is the syntax for the EDIT command.

  • Syntax

    ED[IT] [filename]
    ItemDescription
     When EDIT command is executed without a file name, the contents saved in current SQL buffer will be opened for editing using the default file (.tbedit.sql). The default file will be deleted automatically when tbSQL terminates.
    filenameName of the file to edit (this is usually a script file name).
  • Example

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

1.6.16. EXECUTE

Processes a PSM statement, which includes only CALL statements and anonymous blocks. There must be a semicolon (;) at the end of the statement.

The following is the syntax for the EXECUTE command.

  • Syntax

    EXEC[UTE] {statement}
    ItemDescription
    statementPSM statement.
  • Example

    SQL> EXECUTE begin dbms_output.put_line('success'); end;
    success
    
    PSM completed
    
    SQL> EXECUTE call proc1();

    This command is also useful when allocating a value to a user-defined bind variable.

    SQL> VAR x NUMBER;
    SQL> EXEC :x := 5;
    
    PSM completed
    
    SQL> 

1.6.17. EXIT

Terminates tbSQL. Commits all transactions being processed and terminates all connections to the database.

The following is the syntax for the EXIT command.

  • Syntax

    EXIT [SUCCESS|FAILURE|WARNING|n|variable|:variable]
    ItemDescription
    SUCCESSReturns 0 to indicate a successful termination.
    FAILUREReturns 1 to indicate a termination failure.
    WARNINGReturns 2 to indicate termination with warnings.
    nTermination code of an integer value. Value range varies per OS.
    variableReturns a user variable specified with the DEFINE command or a system variable like SQL.SQLCODE. The user variable must be set to a number.
    :variableSets the termination code using a bind variable specified with the VARIABLE command. The bind variable must be set to a number.
    COMMITExecutes COMMIT before termination.
    ROLLBACKExecutes ROLLBACK before termination.

1.6.18. EXPORT

Exports SELECT statement results or table data to a file with a format that tbLoader can recognize. Must use either a fixed or variable format that uses column and row separators.

The following is the syntax for the EXPORT command.

  • Syntax

    EXP[ORT] {QUERY filename|TABLE [schema.]table} [variable_fmt|FIXED]
    
    variable_fmt:
      [FIELDS {TERM[INATED] BY {,|text}|ENCL[OSED] BY {"|text}}]
      [LINES TERM[INATED] BY {\n|text}]
    ItemDescription
    filenameName of the file to export. This name is used as the table name in the control file.
    [schema.]tableName of the table to export.
    FIELDS ...Column separator for variable format.
    LINES ...Row separator for variable format.
    FIXEDFixed format indicator.
  • Example

    The following example creates t.csv (data file) and t.ctl (control file).

    SQL> EXPORT QUERY 't.csv'
    Ready to export to 't.csv'
    
    SQL> SELECT * FROM t;
    
    10 rows exported.
    

    Specify variable format as follows:

    SQL> EXPORT QUERY 't.csv' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'
    SQL> EXPORT QUERY 't.csv' FIELDS ENCLOSED BY '*'
    

1.6.19. HELP

Outputs help for items that include a specified word.

The following is the syntax for the HELP command.

  • Syntax

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

    SQL> HELP SET

1.6.20. HISTORY

Displays command execution history that is saved in the history buffer.

The following is the syntax for HISTORY command.

  • Syntax

    HIS[TORY]
  • Example

    SQL> HISTORY
    ..... Displays all commands. .....

1.6.21. HOST

This is same as the '!' command.

The following is the syntax for the HOST command.

  • Syntax

    HO[ST] [command]
    ItemDescription
     If only the HOST command is entered without an OS command, the window will change to the OS command prompt where multiple OS commands can be entered.

    To return to the tbSQL command prompt, enter the EXIT command.

    commandOS command.

1.6.22. INPUT

Adds a new line after the last line in the SQL buffer.

The following is the syntax for INPUT command.

  • Syntax

    I[NPUT] [statement]
    ItemDescription
     If the statement option is omitted, multiple lines can be added to the last line in the buffer.
    statementSQL statement to add.
  • Example

    SQL> select * from dual;
    ..... Outputs result  .....
    SQL> LIST
         select * from dual
    SQL> INPUT where rownum < 2
         select * from dual
         where rownum < 2
    SQL>

    The following is an example omitting the statement option. Unlike the previous example, the SQL statement will be executed as soon as it is entered.

    SQL> select * from dual;
    ..... Outputs result  .....
    SQL> INPUT
         select * from dual
         ... Enter here. ... 

1.6.23. LIST

Displays specified lines from the SQL buffer.

The following is the syntax for the LIST command.

  • Syntax

    L[IST] [number|number number|number LAST|LAST]
    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.
    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.24. LOADFILE

Saves a Tibero table in a form that can be recognized by Oracle SQL*Loader.

The following is the syntax for LOADFILE command.

  • Syntax

    LOAD[FILE] {filename}
    ItemDescription
    filenameFile name without a file extension.
  • Example

    Enter the following command to save the EMP table in the form that Oracle's SQL*Loader can recognize. This creates two files, emp.ctl and emp.dat.

    SQL> LOADFILE emp
    SQL> select * from emp;

1.6.25. LOOP

Infinitely repeats a statement. Enter <Ctrl>+C to terminate the loop.

The following is the syntax for the LOOP command.

  • Syntax

    LOOP stmt
    ItemDescription
    stmtStatement to repeat.
  • Example

    SQL> LOOP select count(*) from v$session
    ..... SQL is executed every 1 second. .....
    SQL> SET INTERVAL 10
    SQL> LOOP ls
    ..... LS is executed every 10 seconds. .....
    

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

    One of:

    • FUNCTION, INDEX, PACKAGE, PROCEDURE, SEQUENCE, SYNONYM, TABLE, TABLESPACE, TRIGGER, USER, VIEW

    object_name

    Name of the object to display.

    The percent (%) sign can be used to indicate a temporary pattern.

  • Example

    SQL> LS
    NAME                           SUBNAME       OBJECT_TYPE
    ------------------------------ ------------- --------------------
    SYS_CON100                                   INDEX
    SYS_CON400                                   INDEX
    SYS_CON700                                   INDEX
    _DD_CCOL_IDX1                                INDEX
    ......Omitted......
    UTL_RAW                                      PACKAGE
    DBMS_STATS                                   PACKGE BODY
    TB_HIDDEN2                                   PACKGE BODY
    
    SQL>
    ..... Displays all objects. .....
    
    SQL> LS TABLESPACE
    TABLESPACE_NAME
    ------------------------------
    SYSTEM
    UNDO
    TEMP
    USR
    ..... Displays all objects of TABLESPACE type. .....
    
    SQL> LS USER
    USERNAME
    ------------------------------
    SYS
    ..... Inquires the users that are connecting to the system. .....

1.6.27. PASSWORD

Changes the user password.

The following is the syntax for the PASSWORD command.

  • Syntax

    PASSW[ORD] [username]
    ItemDescription
    usernameUsername to change the password for. If not specified, the currently connected user is specified.
  • Example

    SQL> PASSWORD
    Changing password for 'TIBERO'
    
    Enter old password: ...Enter the current password...
    Enter new password: ...Enter a new password...
    Confirm new password: ...Re-enter the new password...
    
    Password changed successfully.
    SQL>

1.6.28. 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
    messageMessage to display when the user presses the <Enter> key.
  • Example

    SQL> PAUSE please enter...
    please enter...
    ..... Press the <Enter> key. .....
    SQL>

1.6.29. 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 tibero6
    Server is alive.
    
    SQL>

1.6.30. 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 display.
  • Example

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

1.6.31. PROMPT

Displays a certain message or empty line.

The following is the syntax for the PROMPT command.

  • Syntax

    PRO[MPT] [message]
    ItemDescription
     Displays an empty line.
    messageMessage to show.
  • Example

    The following is an example of the externally written SQL file. The file name is PromptUsage.sql.

    PROMPT >>> Test is started.
    CREATE TABLE T (c1 NUMBER);
    INSERT INTO T VALUES (1);
    PROMPT Value 1 is inserted.
    COMMIT;
    PROMPT <<< Test is ended.

    The following illustrates the execution result of PromptUsage.sql.

    SQL> @PromptUsage
    >>> Test is started.
    Table 'T' created.
    1 row inserted.
    Value 1 is inserted.
    Commit succeeded.
    <<< Test is ended.
    File finished.
    
    SQL>

1.6.32. QUIT

It is the same as the EXIT command.

The following is the syntax for the QUIT command.

  • Syntax

    Q[UIT] [SUCCESS|FAILURE|WARNING|n]

1.6.33. RESTORE

Restores user selected data from a file.

The following is the syntax for the RESTORE command.

  • Syntax

    REST[ORE] HIST[ORY] filename[.ext]
    ItemDescription
    filename[.ext]Name of the file to read from. If the file extension is omitted, the SUFFIX value is used.
  • Example

    SQL> RESTORE HISTORY history.sql
    

1.6.34. RUN

It is the same as the / command. However, this command displays the SQL statement saved in the SQL buffer.

The following is the syntax for the RUN command.

  • Syntax

    R[UN]
  • Example

    SQL> select 1 from dual;
    
             1
    ----------
             1
    
    1 row selected.
    
    SQL> RUN
       1 select 1 from dual
    
             1
    ----------
             1
    
    1 row selected.

1.6.35. SAVE

Encrypts the tbSQL utility's database access information and saves it in a file. For detailed information on this command, refer to “1.5.4. Encrypting Connection String”.

The following is the syntax for the SAVE CREDENTIAL command.

  • Syntax

    SAVE CRED[ENTIAL] [filename]
    SAVE HIST[ORY] filename[.ext] [CRE[ATE]|REP[LACE]|APP[END]]
    ItemDescription
    CREDENTIAL

    Encrypts the database connection string.

    It the filename is omitted, it is saved in the file specified by ISQL_WALLET_PATH.

    HISTORY

    Saves command history in the specified file. If the file extension is omitted, the SUFFIX value is used.

    • CREATE: Creates the file. An error occurs if the file already exists. (Default value)

    • REPLACE: Creates the file. Overwrites the file if it already exists.

    • APPEND: Creates the file. Appends new data to the file if it already exists.

    filenameFile to save to.
  • Example

    SQL> SAVE CREDENTIAL
    SQL> SAVE CREDENTIAL "./wallet.dat"
    SQL> SAVE HISTORY history.sql
    SQL> SAVE HISTORY history.sql APPEND
    

1.6.36. 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.37. 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}

    • 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.38. SPOOL

Saves all screen outputs to a file in the current directory. The HOST and ! commands are excluded.

The following is the syntax for the SPOOL command

  • Syntax

    SPO[OL] [filename [APP[END]]|OFF]
    ItemDescription
     When the SPOOL command is entered, the current process state of the SPOOL command will be displayed.
    filenameName of the file to save the output.
    APP[END]Option to attach to the end of the output file.
    OFFStops saving output files.
  • Example

    SQL> SPOOL report.txt
    SQL> SPOOL OFF

1.6.39. START

It is the same as the @ command.

The following is the syntax for the START command.

  • Syntax

    STA[RT] {filename}
    ItemDescription
    filenameScript file name.

1.6.40. 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. (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.41. UNDEFINE

Deletes a substitution variable specified by the ACCEPT command.

The following is the syntax for UNDEFINE command.

  • Syntax

    UNDEF[INE] [variable...]
    ItemDescription
     If [variable...] is omitted, all substitution variables are deleted.
    variable...List of the substitution variable names.
  • Example

    SQL> UNDEFINE x
    SQL> UNDEFINE x y z

1.6.42. 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 bind variables.
    variableBind variable name.
    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.43. WHENEVER

Defines the actions to be taken by tbSQL when an error occurs.

The following is the syntax for the WHENEVER command.

  • Syntax

    WHENEVER {OSERROR|SQLERROR} 
      {EXIT [SUCCESS|FAILURE|WARNING|n|variable|:variable] |
       CONTINUE [NONE|COMMIT|ROLLBACK]}
    • clause1

      ItemDescription
      OSERRORPerforms the specified action for OS errors from the system on which tbSQL is running.
      SQLERRORPerforms the specified action for errors that occurs while executing SQL statements. This excludes tbSQL errors.
    • clause2 (Default value: CONTINUE)

      ItemDescription
      EXITTerminates the program when an error occurs. For return code, refer to the EXIT command.
      CONTINUE

      Continue on to the next command even if an error occurs.

      • NONE: Transaction is not processed. (Default value)

      • COMMIT: Commits the transaction.

      • ROLLBACK: Rolls back the transaction.

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

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

      ItemDescription
      col_nameColumn name.
      fmt_strColumn formats described in the table below.
    • fmt_str Format

      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 roman numeral.
      rnrnDisplays as lowercase roman numeral.
      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.