Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-03-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report