Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » ElevateDB Technical Support » Product Manuals » ElevateDB Version 2 SQL Manual » SQL/PSM Statements » DECLARE |
DECLARE <VariableDefinition>|<CursorDefinition>| <StatementDefinition> <VariableDefinition> = <VariableName> [,<VariableName>] <DataType> [ARRAY [<MaximumCardinality>]] [DEFAULT <DefaultExpression>] <DataType> = CHARACTER|CHAR [(<Length>]) [<CollationName>] CHARACTER VARYING|VARCHAR [(<Length>]) [<CollationName>] GUID BYTE [(<LengthInBytes>]) BYTE VARYING|VARBYTE [(<LengthInBytes>]) BINARY LARGE OBJECT|BLOB CHARACTER LARGE OBJECT|CLOB [<CollationName>] BOOLEAN|BOOL SMALLINT INTEGER|INT BIGINT FLOAT [(<Precision>,<Scale>)] DECIMAL|NUMERIC [(<Precision>,<Scale>)] DATE TIME TIMESTAMP INTERVAL YEAR [TO MONTH] INTERVAL MONTH INTERVAL DAY [TO HOUR|MINUTE|SECOND|MSECOND] INTERVAL HOUR [TO MINUTE|SECOND|MSECOND] INTERVAL MINUTE [TO SECOND|MSECOND] INTERVAL SECOND [TO MSECOND] INTERVAL MSECOND <CursorDefinition> = <CursorName> [SENSITIVE|INSENSITIVE|ASENSITIVE] CURSOR [WITH RETURN|WITHOUT RETURN] FOR <StatementName> <StatementDefinition> = <StatementName> STATEMENT
Type | Description |
SENSITIVE | Sensitive cursors are dynamic and change along with the table used to output the rows in the result set on which the cursor is operating. |
INSENSITIVE | Insensitive cursors are static and do not change even if the tables used to output the rows in the result set on which the cursor is operating change. |
ASENSITIVE | Asensitive cursors, the default, are esentially the same as a sensitive cursor because ElevateDB will always attempt to open a sensitive cursor if the cursor is declared as asensitive. |
Type | Description |
WITH RETURN | Specifies that the cursor should be returned to the calling program if it is left open in the procedure. |
WITHOUT RETURN | Specifies that the cursor should be automatically closed if it is left open when the function or procedure exits. This is the default. |
-- This procedure changes all -- rows with a State column value of 'FL' -- to 'NY'and returns a sensitive cursor -- on the Customers table CREATE PROCEDURE UpdateState() BEGIN DECLARE CustCursor CURSOR WITH RETURN FOR Stmt; DECLARE State CHAR(2) DEFAULT ''; PREPARE Stmt FROM 'SELECT * FROM Customer'; OPEN CustCursor; FETCH FIRST FROM CustCursor ('State') INTO State; WHILE NOT EOF(CustCursor) DO IF (State='FL') THEN UPDATE CustCursor SET 'State'='NY'; END IF; FETCH NEXT FROM CustCursor ('State') INTO State; END WHILE; END -- This procedure simply returns an insensitive -- cursor on the States table CREATE PROCEDURE States() BEGIN DECLARE Test INSENSITIVE CURSOR WITH RETURN FOR stmt; PREPARE stmt FROM 'SELECT * FROM States'; OPEN Test; END -- This procedure uses a statement to -- execute a CREATE TABLE statement CREATE PROCEDURE CreateTestTable() BEGIN DECLARE stmt STATEMENT; PREPARE stmt FROM 'CREATE TEMPORARY TABLE "TestTable" ( "FirstColumn" INTEGER, "SecondColumn" VARCHAR(30), "ThirdColumn" CLOB, PRIMARY KEY ("FirstColumn") ) DESCRIPTION ''Test Table'''; EXECUTE stmt; END -- This script loops through the Customer table and -- populates an array with the CustNo column value -- for each row SCRIPT BEGIN DECLARE Done BOOLEAN DEFAULT False; DECLARE TotalRows INTEGER DEFAULT 0; DECLARE CustCursor CURSOR FOR CustStmt; DECLARE CustArray INTEGER ARRAY [56]; PREPARE CustStmt FROM 'SELECT CustNo, Company FROM Customer'; OPEN CustCursor; WHILE (NOT EOF(CustCursor)) DO SET TotalRows=TotalRows+1; FETCH NEXT FROM CustCursor INTO CustArray[TotalRows]; SET PROGRESS TO TRUNC((TotalRows/ROWCOUNT(CustCursor))*100); END WHILE; CLOSE CustCursor; END
Deviation | Details |
Dynamic SQL | The use of dynamic SQL for cursor declarations and statement declarations instead of static SQL in procedures and functions is an ElevateDB extension. |
BEGIN..END | Declarations can only be made at the beginning of the outermost BEGIN..END block in an ElevateDB procedure or function. The standard dictates that declarations can be made anywhere inside of any BEGIN..END block. |
This web page was last updated on Thursday, November 16, 2023 at 10:39 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |