docs.intersystems.com
Home / InterSystems SQL Reference / SQL Commands / OPEN

InterSystems SQL Reference
OPEN
Previous section           Next section
InterSystems: The power behind what matters   
Search:  


Opens a cursor.
Synopsis
OPEN cursor-name
Arguments
cursor-name The name of the cursor, which has already been declared. The cursor name was specified in the DECLARE statement. Cursor names are case-sensitive.
Description
An OPEN statement opens a cursor according to the parameters specified in the cursor’s DECLARE statement. Once opened, a cursor can be fetched. An open cursor must be closed.
A successful OPEN sets SQLCODE = 0, even if the result set is empty.
OPEN does not support the #SQLCompile Mode=Deferred preprocessor directive. Attempting to use Deferred mode with a DECLARE, OPEN, FETCH, or CLOSE cursor statement generates a #5663 compilation error.
As an SQL statement, this is only supported from embedded SQL. Equivalent operations are supported through ODBC using the ODBC API.
Example
The following embedded SQL example shows a cursor (named EmpCursor) being opened and closed:
   SET name="LastName,FirstName",state="##"
   &sql(DECLARE EmpCursor CURSOR FOR 
        SELECT Name, Home_State
        INTO :name,:state FROM Sample.Person
        WHERE Home_State %STARTSWITH 'A')
   WRITE !,"BEFORE: Name=",name," State=",state 
   &sql(OPEN EmpCursor)
   IF SQLCODE '= 0 { WRITE "Open error: ",SQLCODE
                     QUIT }
   NEW %ROWCOUNT,%ROWID
   FOR { &sql(FETCH EmpCursor)
        QUIT:SQLCODE  
        WRITE !,"DURING: Name=",name," State=",state }
   WRITE !,"FETCH status SQLCODE=",SQLCODE
   WRITE !,"Number of rows fetched=",%ROWCOUNT
   &sql(CLOSE EmpCursor)
   WRITE !,"AFTER: Name=",name," State=",state
See Also


Previous section           Next section
View this book as PDF   |  Download all PDFs
Copyright © 1997-2019 InterSystems Corporation, Cambridge, MA
Content Date/Time: 2019-04-10 14:45:57