Contents Index EXECUTE IMMEDIATE statement [SP] EXPLAIN statement [ESQL]

ASA SQL Reference
  SQL Statements

EXIT statement [Interactive SQL]


Description 

Use this statement to leave Interactive SQL.

Syntax 

EXIT | QUIT | BYE } [ return-code ]

return-code:number
 | hostvar

Usage 

This statement closes your connection with the database, then closes the Interactive SQL environment. 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 instead performs a ROLLBACK. By default, the COMMIT_ON_EXIT option is set to ON.

The optional return code can be used in batch files to indicate success or failure of the commands in an Interactive SQL command file. The default return code is 0.

Permissions 

None.

Side effects 

This statement automatically performs a commit if option COMMIT_ON_EXIT is set to ON (the default); otherwise it performs a rollback.

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

See also 

SET OPTION statement

Standards and compatibility 
Examples 

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 T;
IF( rowCount > 0 ) THEN
    SET retcode = 1;
ELSE
    SET retcode = 0;
END IF;
EXIT retcode;

The following sample is invalid, as the EXIST statement is an Interactive SQL statement only. It cannot be included inside IF statements or any other SQL block statement.

// this example shows incorrect code
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;

The following Windows batch file prints Error = 1 on the command prompt.

dbisql -c "dsn=ASA 9.0 Sample" EXIT 1
if errorlevel 1 echo "Errorlevel is 1"

Contents Index EXECUTE IMMEDIATE statement [SP] EXPLAIN statement [ESQL]