User's Guide
Part VI. SQL Anywhere Reference
Chapter 43. Watcom-SQL StatementsTo close a cursor.
CLOSE cursor-name
cursor-name: identifier, or host-variable
Embedded SQL, procedures, triggers, and batches.
The host-variable format is for Embedded SQL only.
The cursor must have been previously opened.
None.
This statement closes the named cursor.
The following examples close cursors in Embedded SQL.
EXEC SQL CLOSE employee_cursor;
EXEC SQL CLOSE :cursor_var;
The following procedure uses a cursor.
CREATE PROCEDURE TopCustomer (OUT TopCompany CHAR(35), OUT TopValue INT)BEGINDECLARE err_notfound EXCEPTIONFOR SQLSTATE '02000' ;DECLARE curThisCust CURSOR FORSELECT company_name, CAST( sum(sales_order_items.quantity *product.unit_price) AS INTEGER) VALUEFROM customerLEFT OUTER JOIN sales_orderLEFT OUTER JOIN sales_order_itemsLEFT OUTER JOIN productGROUP BY company_name ;DECLARE ThisValue INT ;DECLARE ThisCompany CHAR(35) ;SET TopValue = 0 ;OPEN curThisCust ;CustomerLoop:LOOPFETCH NEXT curThisCustINTO ThisCompany, ThisValue ;IF SQLSTATE = err_notfound THENLEAVE CustomerLoop ;END IF ;IF ThisValue > TopValue THENSET TopValue = ThisValue ;SET TopCompany = ThisCompany ;END IF ;END LOOP CustomerLoop ;CLOSE curThisCust ;END