Home > database >  Mysql doubts about case the when
Mysql doubts about case the when

Time:09-26

 
CREATE PROCEDURE sp_case input_number (INT)
The BEGIN
DECLARE c int;
- SELECT input_number as input_number;
- SELECT (input_number & gt; 0 AND input_number & lt; 5);
SELECT 2;
- SELECT (input_number & gt; 5 AND input_number & lt; 10);

CASE input_number
The WHEN input_number & gt; 0 AND input_number & lt; 5 THEN
The SET c=0;
The WHEN input_number & gt; 5 AND input_number & lt; 10 THEN
The SET c=1;
END CASE;
SELECT c;
END

CALL sp_case (8)

The result error: Case not found for the Case statement
Select 2 did not print it out,

CodePudding user response:

The CASE WHEN input_number & gt; 0 AND input_number & lt; 5 THEN
The SET c=0;
The CASE WHEN input_number & gt; 5 AND input_number & lt; 10 THEN
The SET c=1;

Have a try

CodePudding user response:

 mysql> Delimiter//
Mysql>
Mysql> CREATE PROCEDURE sp_case input_number (INT)
-> The BEGIN
-> DECLARE c int;
->
-> CASE
-> The WHEN input_number & gt; 0 AND input_number & lt; 5 THEN
-> The SET c=0;
-> The WHEN input_number & gt; 5 AND input_number & lt; 10 THEN
-> The SET c=1;
-> END CASE;
->
-> SELECT c;
-> END
->
->//
Query OK, 0 rows affected (0.03 SEC)

Mysql>
Mysql> Delimiter.
Mysql> CALL sp_case (8);
+ -- -- -- -- -- - +
| | c
+ -- -- -- -- -- - +
| | 1
+ -- -- -- -- -- - +
1 row in the set (0.00 SEC)

Query OK, 0 rows affected (0.00 SEC)

Mysql>

CodePudding user response:

Remove the CASE after the input_number give it a try
  • Related