MySQL stored procedures use if subqueries to determine what to pay attention to
This article mainly introduces what MySQL stored procedures need to pay attention to by using if sub-query, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let the editor take you to know it.
MySQL stored procedure
Environment 5.6.14
Drop procedure if exists p
DELIMITER $$
CREATE PROCEDURE `p` ()
BEGIN
Start transaction
If (select 10 from dual where 1: 1 < 5) then
Select 'true'
Else
Select 'false'
End if
Commit
END $$
DELIMITER
Call p
Sometimes to save trouble, a subquery is used in if to return a value and then make a comparison.
Just like the above test process.
But when it is actually executed, the procedure returns true. Basically ignored the results of select, all entered the branch of true.
I think MySQL takes the judgment behind where as the content of comparison, and the above process seems to compare if ((1) 1).