Version sans cache


Mise en cache désactivé. Réglage défaut pour cette page : actif (code DEF204)
Si l'affichage est trop lent, vous pouvez désactiver le mode utilisateur pour visualiser la version en cache.

Rechercher dans le manuel MySQL

13.6.7.1 DECLARE ... CONDITION Syntax

  1. DECLARE condition_name CONDITION FOR condition_value
  2.  
  3. condition_value: {
  4.     mysql_error_code
  5.   | SQLSTATE [VALUE] sqlstate_value
  6. }

The DECLARE ... CONDITION statement declares a named error condition, associating a name with a condition that needs specific handling. The name can be referred to in a subsequent DECLARE ... HANDLER statement (see Section 13.6.7.2, “DECLARE ... HANDLER Syntax”).

Condition declarations must appear before cursor or handler declarations.

The condition_value for DECLARE ... CONDITION indicates the specific condition or class of conditions to associate with the condition name. It can take the following forms:

  • mysql_error_code: An integer literal indicating a MySQL error code.

    Do not use MySQL error code 0 because that indicates success rather than an error condition. For a list of MySQL error codes, see Section B.3.1, “Server Error Message Reference”.

  • SQLSTATE [VALUE] sqlstate_value: A 5-character string literal indicating an SQLSTATE value.

    Do not use SQLSTATE values that begin with '00' because those indicate success rather than an error condition. For a list of SQLSTATE values, see Section B.3.1, “Server Error Message Reference”.

Condition names referred to in SIGNAL or use RESIGNAL statements must be associated with SQLSTATE values, not MySQL error codes.

Using names for conditions can help make stored program code clearer. For example, this handler applies to attempts to drop a nonexistent table, but that is apparent only if you know that 1051 is the MySQL error code for unknown table:

  1. DECLARE CONTINUE HANDLER FOR 1051
  2.     -- body of handler
  3.   END;

By declaring a name for the condition, the purpose of the handler is more readily seen:

  1. DECLARE no_such_table CONDITION FOR 1051;
  2. DECLARE CONTINUE HANDLER FOR no_such_table
  3.     -- body of handler
  4.   END;

Here is a named condition for the same condition, but based on the corresponding SQLSTATE value rather than the MySQL error code:

  1. DECLARE no_such_table CONDITION FOR SQLSTATE '42S02';
  2. DECLARE CONTINUE HANDLER FOR no_such_table
  3.     -- body of handler
  4.   END;

Rechercher dans le manuel MySQL

Traduction non disponible

Le manuel MySQL n'est pas encore traduit en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.

Document créé le 26/06/2006, dernière modification le 26/10/2018
Source du document imprimé : https://www.gaudry.be/mysql-rf-declare-condition.html

L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.

Références

  1. Consulter le document html Langue du document :en Manuel MySQL : https://dev.mysql.com/

Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.

Table des matières Haut