Switch to: V14V13V12V11V10V9V8V7V6V5

DECLARE Statement Syntax

The DECLARE statement is used to define various items local to a routine:

Syntax

variable_declaration
    :    DECLARE variable_name_list data_type [default_clause]

cursor_def
    :    DECLARE cursor_name CURSOR FOR direct_select_multiple_rows_stmt
default_clause
    :    DEFAULT default_option

default_option
    :	USER
    |	CURRENT_USER
    |	SESSION_USER
    |	SYSTEM_USER
    |   FALSE
    |   TRUE
    |   UNKNOWN
    |	NULL
    |	ARRAY '[' ']'		
    |	array_value_constructor_by_enumeration	
    |   valentina_method
    |	literal

Description

DECLARE is allowed only inside a BEGIN … END compound statement.

Notice that in ValentinaSQL you are allowed to DECLARE variables at any point of routine body (as in C++), but not only at the beginning (as in C).

Examples

CREATE PROCEDURE sp1( x VARCHAR(500) )
BEGIN
    -- declare cursor:
    DECLARE curs1 CURSOR FOR SELECT f1, f2, f5 FROM T1 join T2 WHERE f3 > 10;

    -- Declare local variables of procedure:
    DECLARE xname VARCHAR(5) DEFAULT 'bob';
    DECLARE newname VARCHAR(5);
    DECLARE xid INT;

    ...
END;