Updated on 2023-10-31 GMT+08:00

DBMS_SQL

Related Interfaces

Table 1 lists interfaces supported by the DBMS_SQL package.

Table 1 DBMS_SQL

API

Description

DBMS_SQL.OPEN_CURSOR

Opens a cursor.

DBMS_SQL.CLOSE_CURSOR

Closes an open cursor.

DBMS_SQL.PARSE

Transmits a group of SQL statements to a cursor. Currently, only the SELECT statement is supported.

DBMS_SQL.EXECUTE

Performs a set of dynamically defined operations on the cursor.

DBMS_SQL.FETCHE_ROWS

Reads a row of cursor data.

DBMS_SQL.DEFINE_COLUMN

Dynamically defines a column.

DBMS_SQL.DEFINE_COLUMN_CHAR

Dynamically defines a column of the CHAR type.

DBMS_SQL.DEFINE_COLUMN_INT

Dynamically defines a column of the INT type.

DBMS_SQL.DEFINE_COLUMN_LONG

Dynamically defines a column of the LONG type.

DBMS_SQL.DEFINE_COLUMN_RAW

Dynamically defines a column of the RAW type.

DBMS_SQL.DEFINE_COLUMN_TEXT

Dynamically defines a column of the TEXT type.

DBMS_SQL.DEFINE_COLUMN_UNKNOWN

Dynamically defines a column of an unknown type.

DBMS_SQL.COLUMN_VALUE

Reads a dynamically defined column value.

DBMS_SQL.COLUMN_VALUE_CHAR

Reads a dynamically defined column value of the CHAR type.

DBMS_SQL.COLUMN_VALUE_INT

Reads a dynamically defined column value of the INT type.

DBMS_SQL.COLUMN_VALUE_LONG

Reads a dynamically defined column value of the LONG type.

DBMS_SQL.COLUMN_VALUE_RAW

Reads a dynamically defined column value of the RAW type.

DBMS_SQL.COLUMN_VALUE_TEXT

Reads a dynamically defined column value of the TEXT type.

DBMS_SQL.COLUMN_VALUE_UNKNOWN

Reads a dynamically defined column value of an unknown type.

DBMS_SQL.IS_OPEN

Checks whether a cursor is opened.

  • You are advised to use dbms_sql.define_column and dbms_sql.column_value to define columns.
  • If the size of the result set is greater than the value of work_mem, the result set will be flushed to disk. The value of work_mem must be no greater than 512 MB.
  • DBMS_SQL.OPEN_CURSOR

    This function opens a cursor and is the prerequisite for the subsequent dbms_sql operations. This function does not transfer any parameter. It automatically generates cursor IDs in an ascending order and returns values to integer variables.

    The function prototype of DBMS_SQL.OPEN_CURSOR is:

  • DBMS_SQL.CLOSE_CURSOR

    This function closes a cursor. It is the end of each dbms_sql operation. If this function is not invoked when the stored procedure ends, the memory is still occupied by the cursor. Therefore, remember to close a cursor when you do not need to use it. If an exception occurs, the stored procedure exits but the cursor is not closed. Therefore, you are advised to include this interface in the exception handling of the stored procedure.

    The function prototype of DBMS_SQL.CLOSE_CURSOR is:

    Table 2 DBMS_SQL.CLOSE_CURSOR interface parameters

    Parameter Name

    Description

    cursorid

    ID of the cursor to be closed

  • DBMS_SQL.PARSE

    This function parses the query statement of a given cursor. The input query statement is executed immediately. Currently, only the SELECT query statement can be parsed. The statement parameters can be transferred only through the TEXT type. The length cannot exceed 1 GB.

    The function prototype of DBMS_SQL.PARSE is:
    Table 3 DBMS_SQL.PARSE interface parameters

    Parameter Name

    Description

    cursorid

    ID of the cursor whose query statement is parsed

    query_string

    Query statements to be parsed

    language_flag

    Version language number. Currently, only 1 is supported.

  • DBMS_SQL.EXECUTE

    This function executes a given cursor. This function receives a cursor ID. The obtained data after is used for subsequent operations. Currently, only the SELECT query statement can be executed.

    The function prototype of DBMS_SQL.EXECUTE is:
    Table 4 DBMS_SQL.EXECUTE interface parameters

    Parameter Name

    Description

    cursorid

    ID of the cursor whose query statement is parsed

  • DBMS_SQL.FETCHE_ROWS

    This function returns the number of data rows that meet query conditions. Each time the interface is executed, the system obtains a set of new rows until all data is read.

    The function prototype of DBMS_SQL.FETCHE_ROWS is:
    Table 5 DBMS_SQL.FETCH_ROWS interface parameters

    Parameter Name

    Description

    curosorid

    ID of the cursor to be executed

  • DBMS_SQL.DEFINE_COLUMN

    This function defines columns returned from a given cursor and can be used only for the cursors defined by SELECT. The defined columns are identified by the relative positions in the query list. The data type of the input variable determines the column type.

    The function prototype of DBMS_SQL.DEFINE_COLUMN is:
    Table 6 DBMS_SQL.DEFINE_COLUMN interface parameters

    Parameter Name

    Description

    cursorid

    ID of the cursor to be executed

    position

    Position of a dynamically defined column in the query

    column_ref

    Variable of any type. You can select an appropriate interface to dynamically define columns based on variable types.

    column_size

    Length of a defined column

  • DBMS_SQL.DEFINE_COLUMN_CHAR

    This function defines columns of the CHAR type returned from a given cursor and can be used only for the cursors defined by SELECT. The defined columns are identified by the relative positions in the query list. The data type of the input variable determines the column type.

    The function prototype of DBMS_SQL.DEFINE_COLUMN_CHAR is:
    Table 7 DBMS_SQL.DEFINE_COLUMN_CHAR interface parameters

    Parameter Name

    Description

    cursorid

    ID of the cursor to be executed

    position

    Position of a dynamically defined column in the query

    column

    Parameter to be defined

    column_size

    Length of a dynamically defined column

  • DBMS_SQL.DEFINE_COLUMN_INT

    This function defines columns of the INT type returned from a given cursor and can be used only for the cursors defined by SELECT. The defined columns are identified by the relative positions in the query list. The data type of the input variable determines the column type.

    The function prototype of DBMS_SQL.DEFINE_COLUMN_INT is:
    Table 8 DBMS_SQL.DEFINE_COLUMN_INT interface parameters

    Parameter Name

    Description

    cursorid

    ID of the cursor to be executed

    position

    Position of a dynamically defined column in the query

  • DBMS_SQL.DEFINE_COLUMN_LONG

    This function defines columns of a long type (not LONG) returned from a given cursor and can be used only for the cursors defined by SELECT. The defined columns are identified by the relative positions in the query list. The data type of the input variable determines the column type. The maximum size of a long column is 1 GB.

    The function prototype of DBMS_SQL.DEFINE_COLUMN_LONG is:
    Table 9 DBMS_SQL.DEFINE_COLUMN_LONG interface parameters

    Parameter Name

    Description

    cursorid

    ID of the cursor to be executed

    position

    Position of a dynamically defined column in the query

  • DBMS_SQL.DEFINE_COLUMN_RAW

    This function defines columns of the RAW type returned from a given cursor and can be used only for the cursors defined by SELECT. The defined columns are identified by the relative positions in the query list. The data type of the input variable determines the column type.

    The function prototype of DBMS_SQL.DEFINE_COLUMN_RAW is:
    Table 10 DBMS_SQL.DEFINE_COLUMN_RAW interface parameters

    Parameter Name

    Description

    cursorid

    ID of the cursor to be executed

    position

    Position of a dynamically defined column in the query

    column

    Parameter of the RAW type

    column_size

    Column length

  • DBMS_SQL.DEFINE_COLUMN_TEXT

    This function defines columns of the TEXT type returned from a given cursor and can be used only for the cursors defined by SELECT. The defined columns are identified by the relative positions in the query list. The data type of the input variable determines the column type.

    The function prototype of DBMS_SQL.DEFINE_COLUMN_TEXT is:
    Table 11 DBMS_SQL.DEFINE_COLUMN_TEXT interface parameters

    Parameter Name

    Description

    cursorid

    ID of the cursor to be executed

    position

    Position of a dynamically defined column in the query

    max_size

    Maximum length of the defined TEXT type

  • DBMS_SQL.DEFINE_COLUMN_UNKNOWN

    This function processes columns of unknown data types returned from a given cursor and is used only for the system to report an error and exist when the type cannot be identified.

    The function prototype of DBMS_SQL.DEFINE_COLUMN_UNKNOWN is:
    Table 12 DBMS_SQL.DEFINE_COLUMN_UNKNOWN interface parameters

    Parameter Name

    Description

    cursorid

    ID of the cursor to be executed

    position

    Position of a dynamically defined column in the query

    column

    Dynamically defined parameter

  • DBMS_SQL.COLUMN_VALUE

    This function returns the cursor element value specified by a cursor and accesses the data obtained by DBMS_SQL.FETCH_ROWS.

    The function prototype of DBMS_SQL.COLUMN_VALUE is:
    Table 13 DBMS_SQL.COLUMN_VALUE interface parameters

    Parameter Name

    Description

    cursorid

    ID of the cursor to be executed

    position

    Position of a dynamically defined column in the query

    column_value

    Return value of a defined column

  • DBMS_SQL.COLUMN_VALUE_CHAR

    This function returns the value of the CHAR type in a specified position of a cursor and accesses the data obtained by DBMS_SQL.FETCH_ROWS.

    The function prototype of DBMS_SQL.COLUMN_VALUE_CHAR is:
    Table 14 DBMS_SQL.COLUMN_VALUE_CHAR interface parameters

    Parameter Name

    Description

    cursorid

    ID of the cursor to be executed

    position

    Position of a dynamically defined column in the query

    column_value

    Return value

    err_num

    Error No. It is an output parameter and the argument must be a variable. Currently, the output value is –1 regardless of the argument.

    actual_length

    Length of a return value

  • DBMS_SQL.COLUMN_VALUE_INT
    This function returns the value of the INT type in a specified position of a cursor and accesses the data obtained by DBMS_SQL.FETCH_ROWS. The function prototype of DBMS_SQL.COLUMN_VALUE_INT is:
    Table 15 DBMS_SQL.COLUMN_VALUE_INT interface parameters

    Parameter Name

    Description

    cursorid

    ID of the cursor to be executed

    position

    Position of a dynamically defined column in the query

  • DBMS_SQL.COLUMN_VALUE_LONG

    This function returns the value of a long type (not LONG or BIGINT) in a specified position of a cursor and accesses the data obtained by DBMS_SQL.FETCH_ROWS.

    The function prototype of DBMS_SQL.COLUMN_VALUE_LONG is:
    Table 16 DBMS_SQL.COLUMN_VALUE_LONG interface parameters

    Parameter Name

    Description

    cursorid

    ID of the cursor to be executed

    position

    Position of a dynamically defined column in the query

    length

    Length of a return value

    off_set

    Start position of a return value

    column_value

    Return value

    actual_length

    Length of a return value

  • DBMS_SQL.COLUMN_VALUE_RAW

    This function returns the value of the RAW type in a specified position of a cursor and accesses the data obtained by DBMS_SQL.FETCH_ROWS.

    The function prototype of DBMS_SQL.COLUMN_VALUE_RAW is:
    Table 17 DBMS_SQL.COLUMN_VALUE_RAW interface parameters

    Parameter Name

    Description

    cursorid

    ID of the cursor to be executed

    position

    Position of a dynamically defined column in the query

    column_value

    Returned column value

    err_num

    Error No. It is an output parameter and the argument must be a variable. Currently, the output value is –1 regardless of the argument.

    actual_length

    Length of a return value. The value longer than this length will be truncated.

  • DBMS_SQL.COLUMN_VALUE_TEXT

    This function returns the value of the TEXT type in a specified position of a cursor and accesses the data obtained by DBMS_SQL.FETCH_ROWS.

    The function prototype of DBMS_SQL.COLUMN_VALUE_TEXT is:
    Table 18 DBMS_SQL.COLUMN_VALUE_TEXT interface parameters

    Parameter Name

    Description

    cursorid

    ID of the cursor to be executed

    position

    Position of a dynamically defined column in the query

  • DBMS_SQL.COLUMN_VALUE_UNKNOWN

    This function returns the value of an unknown type in a specified position of a cursor. This is an error handling interface when the type is not unknown.

    The function prototype of DBMS_SQL.COLUMN_VALUE_UNKNOWN is:
    Table 19 DBMS_SQL.COLUMN_VALUE_UNKNOWN interface parameters

    Parameter Name

    Description

    cursorid

    ID of the cursor to be executed

    position

    Position of a dynamically defined column in the query

    column_type

    Returned parameter type

  • DBMS_SQL.IS_OPEN

This function returns the status of a cursor: open, parse, execute, or define. The value is TRUE. If the status is unknown, an error is reported. In other cases, the value is FALSE.

The function prototype of DBMS_SQL.IS_OPEN is:
Table 20 DBMS_SQL.IS_OPEN interface parameters

Parameter Name

Description

cursorid

ID of the cursor to be queried

Examples