DECLARE CURSOR statement [T-SQL]

Use this statement to declare a cursor in a manner compatible with Adaptive Server Enterprise.

Syntax
DECLARE cursor-name
 CURSOR FOR select-statement
 [ FOR { READ ONLY | UPDATE } ]
cursor-name : identifier
select-statement  : string
Remarks

DECLARE CURSOR statements in Transact-SQL procedures are treated as executable statements and can appear anywhere in a procedure. The cursor declaration takes effect when the statement is executed and remains in effect until a DEALLOCATE CURSOR statement is executed or until the procedure completes.

In SQL Anywhere, if a cursor is declared inside a compound statement, it exists only for the duration of that compound statement (whether it is declared in a Watcom-SQL or Transact-SQL compound statement).

In a Transact-SQL procedure, trigger, or batch, a DECLARE CURSOR statement can appear after other executable statements.

Permissions

None.

Side effects

None.

See also
Standards and compatibility
  • SQL/2003   Core feature. The FOR UPDATE and FOR READ ONLY options are Transact-SQL extensions.