NEXT_CONNECTION Function [System]

Returns the next connection number, or the first connection if the parameter is NULL.

Syntax

NEXT_CONNECTION ( {connection-id }, {database-id } )
Note: CIS functional compensation performance considerations apply.

Returns

INT

Parameters

Parameter

Description

connection-id

An integer, usually returned from a previous call to NEXT_CONNECTION. If connection-id is NULL, NEXT_CONNECTION returns the most recent connection ID.

database-id

An integer representing one of the databases on the current server. If you supply no database-id, the current database is used. If you supply NULL, then NEXT_CONNECTION returns the next connection regardless of database.

Usage

You can use NEXT_CONNECTION to enumerate the connections to a database. To get the first connection, pass NULL; to get each subsequent connection, pass the previous return value. The function returns NULL when there are no more connections.

NEXT_CONNECTION can be used to enumerate the connections to a database. Connection IDs are generally created in monotonically increasing order. This function returns the next connection ID in reverse order.

To get the connection ID value for the most recent connection, enter NULL as the connection-id. To get the subsequent connection, enter the previous return value. The function returns NULL when there are no more connections in the order.

NEXT_CONNECTION is useful if you want to disconnect all the connections created before a specific time. However, because NEXT_CONNECTION returns the connection IDS in reverse order, connections made after the function is started are not returned. If you want to ensure that all connections are disconnected, prevent new connections from being created before you run NEXT_CONNECTION.

Standards and Compatibility

  • SQL—Vendor extension to ISO/ANSI SQL grammar.

Examples

The following statement returns an identifier for the first connection on the current database. The identifier is an integer value like 10.

SELECT NEXT_CONNECTION( NULL );

The following statement returns a value like 5.

SELECT NEXT_CONNECTION( 10 );

The following call returns the next connection ID in reverse order from the specified connection-id on the current database.

SELECT NEXT_CONNECTION( connection-id );

The following call returns the next connection ID in reverse order from the specified connection-id (regardless of database).

SELECT NEXT_CONNECTION( connection-id, NULL );

The following call returns the next connection ID in reverse order from the specified connection-id on the specified database.

SELECT NEXT_CONNECTION( connection-id, database-id );

The following call returns the first (earliest) connection (regardless of database).

SELECT NEXT_CONNECTION( NULL, NULL );

The following call returns the first (earliest) connection on the specified database.

SELECT NEXT_CONNECTION( NULL, database-id );