Flow control (MySQL)
Het goede nieuws: MySQL kent flow control. Het slechte nieuws: Het meeste hiervan is alleen bruikbaar in sprocs, en niet in recht-toe-recht-aan SQL-scripts.
- Beschikbaar in stored procedures: if, case, iterative, leave, loop, while & repeat
- Beschikbaar in stored functions: return
- Beschikbaar in SQL: case, if(), ifnull(), nullif().
If-functie
Een directe IF-functie kan in SQL-scripts worden toegepast:
SELECT IF(expressie, if_true, if_false)
Bv.:
select if ((select count(*) from information_schema.tables where table_schema='koolborstels' and table_name='term_data_bk01'),1,0);
IF-statement
Het IF-statement, dat echte conditional branching kent, kan alleen binnen stored procedures worden toegepast.
Zie ook
Bronnen
- https://dev.mysql.com/doc/refman/5.1/en/control-flow-functions.html - Flow control in scripts
- https://dev.mysql.com/doc/refman/5.7/en/flow-control-statements.html - Flow control in sprocs
- https://dev.mysql.com/doc/refman/5.1/en/if.html - if-Statement
- https://dev.mysql.com/doc/refman/5.0/en/user-variables.html