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

Example Analysis of mysql seeking two or more Fields to be NULL values

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article mainly shows you the "mysql for 2 or more fields for the NULL value of the example analysis", the content is easy to understand, clear, hope to help you solve the doubt, the following let the editor lead you to study and learn "mysql for 2 or more fields for the NULL value of the example analysis" of this article.

Core code

/ *-- t1:id, id1, id2, id3, id4, id5, id6 of 2 or more records with NULL fields have a field in the T1 table, where id is the primary key. How to print a record id with one or more fields of NULL? In addition, how is it most convenient to read records sequentially in a stored procedure? Note: the primary key id is out of order or may be a string -- * / drop table if exists T1 politics create table T1 (id int,id1 int,id2 int,id3 int,id4 int,id5 int,id6 int) Insert T1 select1,1,1,1,1,null,null union all select 2 insert nullwagernullwagernullwagernullwagernullwagernullwagernullwagernullwagernullrewnwnlwnlwylwy2jy3 union all select 3jjjjjnwy3jpt3jpg 4jnullwagernullwagernullwagernullwagernullwagernullifornlwywagernullwagernullirewnlwlwlwnlwlwlwlwlwlwlwlwlwlwlwlwlwlwlwllwlwlwlwywlwlwlwlwlwlwlwlw Declare cur cursor for select id,case char_length (concat (ifnull (id1,'@'), ifnull (id2,'@'), ifnull (id3,'@'), ifnull (id4,'@'), ifnull (id5,'@'), ifnull (id6,'@')-char_length (concat (ifnull (id1,'@'), ifnull (id2,'@'), ifnull (id3,'@'), ifnull (id4,'@'), ifnull (id5,'@'), ifnull (id6) '@')),'@,') when 6 then 6 when 5 then 5 when 4 then 4 when 3 then 3 when 2 then 2 then 1 else 0 end as c from T1 Declare exit HANDLER for not found close cur; open cur;repeat fetch cur into idd,n_c;if (nexc > = 2) thenselect * from T1 where id=idd;end if; until 0 end repeat;close cur;end; $$delimiter / * +-+ | id | id1 | id2 | id3 | id4 | id5 | id6 | +-+ | 1 | 1 | 1 | | 1 | 1 | NULL | NULL | +-+ 1 row in set (0.10 sec) +-+ | id | id1 | | | id2 | id3 | id4 | id5 | id6 | +-+ | 2 | NULL | NULL | NULL | 1 | 2 | 3 | +-- | -- + 1 row in set (0.14 sec) +-+ | id | id1 | id2 | id3 | id4 | id5 | id6 | +- -+ | 5 | NULL | 3 | 4 | NULL | NULL | NULL | +-+ 1 row in set (0.17 sec) * / above is all the contents of the article "mysql asks for a sample analysis of two or more fields with NULL values" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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