Skip to main content

cancel_session

1. CANCEL_SESSION Function

The CANCEL_SESSION function in H2 database is used to cancel a running session or statement in the database.

2. Syntax

The syntax for the CANCEL_SESSION function in H2 database is as follows:

CANCEL_SESSION(sessionId)

Arguments

  • sessionId: The ID of the session or statement that needs to be canceled. It should be an integer value representing the session ID.

Return

  • The CANCEL_SESSION function does not return any value.

3. Notes

  • The CANCEL_SESSION function in H2 database can be used to terminate a long-running or blocking query to free up resources.
  • Only the sessions or statements that are initiated by the current user can be canceled.
  • The sessionId argument should be a valid session ID. You can obtain the session ID by querying the INFORMATION_SCHEMA.SESSIONS system table.
  • Canceling a session or statement may lead to rollback of any uncommitted changes made by that session.

4. Examples

Here are a few examples demonstrating the usage of the CANCEL_SESSION function in H2 database:

Example 1 - Canceling a specific session:

CANCEL_SESSION(123);

This will cancel the session with ID 123.

Example 2 - Canceling a specific statement:

CANCEL_SESSION(0);

This will cancel the currently running statement in the current session.

There are no related functions for the CANCEL_SESSION function in H2 database.