Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 17 » SQL Anywhere Server - SQL Reference » SQL statements » Alphabetical list of SQL statements

EXIT statement [Interactive SQL]

Leaves Interactive SQL.

Syntax
{ EXIT | QUIT | BYE } [ return-code ]
return-code : number | connection-variable
Remarks

This statement closes the Interactive SQL window if you are running Interactive SQL as a windowed program, or terminates Interactive SQL altogether when running in command-prompt (batch) mode. In both cases, the database connection is also closed. Before closing the database connection, Interactive SQL automatically executes a COMMIT statement if the commit_on_exit option is set to On. If this option is set to Off, Interactive SQL performs an implicit ROLLBACK. By default, the commit_on_exit option is set to On.

The optional return code can be checked in batch files to determine the success or failure of the statements in an Interactive SQL script file. The default return code is 0.

Privileges

None.

Side effects

This statement automatically performs a commit if option commit_on_exit is set to On (the default); otherwise it performs an implicit rollback.

On Windows operating systems the optional return value is available as ERRORLEVEL.

Standards
  • ANSI/ISO SQL Standard

    Not in the standard.

Example

The following example sets the Interactive SQL return value to 1 if there are any rows in table T, or to 0 if T contains no rows.

CREATE VARIABLE rowCount INT;
CREATE VARIABLE retcode INT;
SELECT COUNT(*) INTO rowCount FROM GROUPO.Products;
IF( rowCount > 0 ) THEN
    SET retcode = 1;
ELSE
    SET retcode = 0;
END IF;
EXIT retcode;
Note

You cannot write the following statement because EXIT is an Interactive SQL statement (not a SQL statement), and you cannot include any Interactive SQL statement in other SQL block statements.

CREATE VARIABLE rowCount INT; 
SELECT COUNT(*) INTO rowCount FROM T; 
IF( rowCount > 0 ) THEN     
    EXIT 1    //  <-- not allowed 
ELSE 
    EXIT 0    //  <-- not allowed 
END IF;