Geen cache-versie.


Caching uitgeschakeld. Standaardinstelling voor deze pagina:ingeschakeld (code DEF204)
Als het scherm te langzaam is, kunt u de gebruikersmodus uitschakelen om de cacheversie te bekijken.

Rechercher dans le manuel MySQL

12.3.3 Logical Operators

Table 12.4 Logical Operators

Name Description
AND, && Logical AND
NOT, ! Negates value
OR, || Logical OR
XOR Logical XOR

In SQL, all logical operators evaluate to TRUE, FALSE, or NULL (UNKNOWN). In MySQL, these are implemented as 1 (TRUE), 0 (FALSE), and NULL. Most of this is common to different SQL database servers, although some servers may return any nonzero value for TRUE.

MySQL evaluates any nonzero, non-NULL value to TRUE. For example, the following statements all assess to TRUE:

  1. mysql> SELECT 10 IS TRUE;
  2. -> 1
  3. mysql> SELECT -10 IS TRUE;
  4. -> 1
  5. mysql> SELECT 'string' IS NOT NULL;
  6. -> 1
  • NOT, !

    Logical NOT. Evaluates to 1 if the operand is 0, to 0 if the operand is nonzero, and NOT NULL returns NULL.

    1. mysql> SELECT NOT 10;
    2.         -> 0
    3. mysql> SELECT NOT 0;
    4.         -> 1
    5. mysql> SELECT NOT NULL;
    6.         -> NULL
    7. mysql> SELECT ! (1+1);
    8.         -> 0
    9. mysql> SELECT ! 1+1;
    10.         -> 1

    The last example produces 1 because the expression evaluates the same way as (!1)+1.

    The !, operator is a nonstandard MySQL extension. As of MySQL 8.0.17, this operator is deprecated and support for it will be removed in a future MySQL version. Applications should be adjusted to use the standard SQL NOT operator.

  • AND, &&

    Logical AND. Evaluates to 1 if all operands are nonzero and not NULL, to 0 if one or more operands are 0, otherwise NULL is returned.

    1. mysql> SELECT 1 AND 1;
    2.         -> 1
    3. mysql> SELECT 1 AND 0;
    4.         -> 0
    5. mysql> SELECT 1 AND NULL;
    6.         -> NULL
    7. mysql> SELECT 0 AND NULL;
    8.         -> 0
    9. mysql> SELECT NULL AND 0;
    10.         -> 0

    The &&, operator is a nonstandard MySQL extension. As of MySQL 8.0.17, this operator is deprecated and support for it will be removed in a future MySQL version. Applications should be adjusted to use the standard SQL AND operator.

  • OR, ||

    Logical OR. When both operands are non-NULL, the result is 1 if any operand is nonzero, and 0 otherwise. With a NULL operand, the result is 1 if the other operand is nonzero, and NULL otherwise. If both operands are NULL, the result is NULL.

    1. mysql> SELECT 1 OR 1;
    2.         -> 1
    3. mysql> SELECT 1 OR 0;
    4.         -> 1
    5. mysql> SELECT 0 OR 0;
    6.         -> 0
    7. mysql> SELECT 0 OR NULL;
    8.         -> NULL
    9. mysql> SELECT 1 OR NULL;
    10.         -> 1
    Note

    If the PIPES_AS_CONCAT SQL mode is enabled, || signifies the SQL-standard string concatenation operator (like CONCAT()).

    The ||, operator is a nonstandard MySQL extension. As of MySQL 8.0.17, this operator is deprecated and support for it will be removed in a future MySQL version. Applications should be adjusted to use the standard SQL OR operator. Exception: Deprecation does not apply if PIPES_AS_CONCAT is enabled because, in that case, || signifies string concatentation.

  • XOR

    Logical XOR. Returns NULL if either operand is NULL. For non-NULL operands, evaluates to 1 if an odd number of operands is nonzero, otherwise 0 is returned.

    1. mysql> SELECT 1 XOR 1;
    2.         -> 0
    3. mysql> SELECT 1 XOR 0;
    4.         -> 1
    5. mysql> SELECT 1 XOR NULL;
    6.         -> NULL
    7. mysql> SELECT 1 XOR 1 XOR 1;
    8.         -> 1

    a XOR b is mathematically equal to (a AND (NOT b)) OR ((NOT a) and b).


Zoek in de MySQL-handleiding

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 26/06/2006 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/mysql-rf-logical-operators.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.

Referenties

  1. Bekijk - html-document Taal van het document:en Manuel MySQL : https://dev.mysql.com/

Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.

Inhoudsopgave Haut