S
S
Sergey Korenevsky2018-04-11 04:31:48
MySQL
Sergey Korenevsky, 2018-04-11 04:31:48

How to create branches in MySQL: BEGIN, IF THEN?

MySQL gives an error in condition statements, but I do everything according to the reference book.

BEGIN;
    SET @lines := 0;
    SELECT count(*) FROM `prod_attr ` INTO @lines ;
      IF @lines > 4000        THEN       -- Тут ошибка  
            SELECT "MAX";
            TRUNCATE TABLE  `prod_attr ` ;
      END IF;
END;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lazy @BojackHorseman MySQL, 2018-04-11
@Dier_Sergio_Great

only inside the begin ... end block
BEGIN ... END syntax is used for writing compound statements, which can appear within stored programs (stored procedures and functions, triggers, and events
in this particular case, BEGIN is interpreted as an alias START TRANSACTION; , and IF - as a function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question