Get the App
SLTechnology News&Howtos  ›  Database  › 

MySQL stored procedures use if subqueries to determine what to pay attention to

Shulou Source: shulou.com Published: 2022-05-31 16:01:48 09月17日 Update

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).

Tags: Process query article storage branch result convenience value interest content number at the same time actual parenthesis method time more sometimes friend environment Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Redmi Apple MySQL Docker