Global variables are system-supplied variables that provide system-supplied values.
Sybase IQ sets the values of global variables. For example, the global variable @@version has a value that is the current version number of the database server.
Global variables are distinguished from local and connection-level variables by two @ signs preceding their names. For example, @@error is a global variable. Users cannot create global variables, and cannot update the value of global variables directly.
Some global variables, such as @@spid, hold connection-specific information and therefore have connection-specific values. Other variables, such as @@connections, have values that are common to all connections.
The special constants such as CURRENT DATE, CURRENT TIME, USER, SQLSTATE, and so on are similar to global variables.
The following statement retrieves the value of the version global variable:
SELECT @@version
In procedures, global variables can be selected into a variable list. The following procedure returns the server version number in the ver parameter.
CREATE PROCEDURE VersionProc ( OUT ver VARCHAR ( 100) ) BEGIN SELECT @@version INTO ver; END
In Embedded SQL, global variables can be selected into a host variable list.
This table lists the global variables available in Sybase IQ.
Variable name |
Meaning |
---|---|
@@error |
Commonly used to check the error status (succeeded or failed) of the most recently executed statement. Contains 0 if the previous transaction succeeded; otherwise, contains the last error number generated by the system. A statement such as if @@error != 0 return causes an exit if an error occurs. Every SQL statement resets @@error, so the status check must immediately follow the statement whose success is in question. |
@@fetch_status |
Contains status information resulting from the last fetch statement. @@fetch_status may contain the following values
This feature is the same as @@sqlstatus, except that it returns different values. It is for Microsoft SQL Server compatibility. |
@@identity |
The last value inserted into an Identity/Autoincrement column by an insert, load or update statement. @@identity is reset each time a row is inserted into a table. If a statement inserts multiple rows, @@identity reflects the Identity/Autoincrement value for the last row inserted. If the affected table does not contain an Identity/Autoincrement column, @@identity is set to 0. The value of @@identity is not affected by the failure of an insert, load, or update statement, or the rollback of the transaction that contained the failed statement. @@identity retains the last value inserted into an Identity/Autoincrement column, even if the statement that inserted that value fails to commit. |
@@isolation |
Current isolation level. @@isolation takes the value of the active level. |
@@procid |
Stored procedure ID of the currently executing procedure. |
@@rowcount |
Number of rows affected by the last statement. The value of @@rowcount should be checked immediately after the statement. Inserts, updates, and deletes set @@rowcount to the number of rows affected. With cursors, @@rowcount represents the cumulative number of rows returned from the cursor result set to the client, up to the last fetch request. The @@rowcount is not reset to zero by any statement which does not affect rows, such as an IF statement. |
@@servername |
Name of the current database server. |
@@sqlstatus |
Contains status information resulting from the last FETCH statement. |
@@version |
Version number of the current version of Sybase IQ. |