日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql 变量is null 和 not exists区别

發(fā)布時間:2025/4/5 数据库 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql 变量is null 和 not exists区别 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

問題:

使用游標遍歷時,發(fā)現(xiàn)使用

select var into tmp where var=?

然后判斷if tmp is null時,不能走完所有的遍歷。經(jīng)debug發(fā)現(xiàn),

當var為空時,則跳出游標的遍歷。

?

解決方式:

使用if not exists(select var into tmp where var=?)時,則ok。

?

這個可以從mysql官方文檔中找到原因:

1. ?select var into tmp where var=? 中where 條件不支持為空,如下面紅色部分所示。

Problems with NULL Values The concept of the NULL value is a common source of confusion for newcomers to SQL, who often think that NULL is the same thing as an empty string ''. This is not the case. For example, the following statements are completely different:mysql> INSERT INTO my_table (phone) VALUES (NULL); mysql> INSERT INTO my_table (phone) VALUES (''); Both statements insert a value into the phone column, but the first inserts a NULL value and the second inserts an empty string. The meaning of the first can be regarded as “phone number is not known” and the meaning of the second can be regarded as “the person is known to have no phone, and thus no phone number.”To help with NULL handling, you can use the IS NULL and IS NOT NULL operators and the IFNULL() function.In SQL, the NULL value is never true in comparison to any other value, even NULL. An expression that contains NULL always produces a NULL value unless otherwise indicated in the documentation for the operators and functions involved in the expression. All columns in the following example return NULL:mysql> SELECT NULL, 1+NULL, CONCAT('Invisible',NULL); To search for column values that are NULL, you cannot use an expr = NULL test. The following statement returns no rows, because expr = NULL is never true for any expression:mysql> SELECT * FROM my_table WHERE phone = NULL; To look for NULL values, you must use the IS NULL test. The following statements show how to find the NULL phone number and the empty phone number:mysql> SELECT * FROM my_table WHERE phone IS NULL; mysql> SELECT * FROM my_table WHERE phone = ''; See Section 3.3.4.6, “Working with NULL Values”, for additional information and examples.You can add an index on a column that can have NULL values if you are using the MyISAM, InnoDB, or BDB, or MEMORY storage engine. Otherwise, you must declare an indexed column NOT NULL, and you cannot insert NULL into the column.When reading data with LOAD DATA INFILE, empty or missing columns are updated with ''. To load a NULL value into a column, use \N in the data file. The literal word “NULL” may also be used under some circumstances. See Section 13.2.6, “LOAD DATA INFILE Syntax”.When using DISTINCT, GROUP BY, or ORDER BY, all NULL values are regarded as equal.When using ORDER BY, NULL values are presented first, or last if you specify DESC to sort in descending order.Aggregate (summary) functions such as COUNT(), MIN(), and SUM() ignore NULL values. The exception to this is COUNT(*), which counts rows and not individual column values. For example, the following statement produces two counts. The first is a count of the number of rows in the table, and the second is a count of the number of non-NULL values in the age column:mysql> SELECT COUNT(*), COUNT(age) FROM person; For some data types, MySQL handles NULL values specially. If you insert NULL into a TIMESTAMP column, the current date and time is inserted. If you insert NULL into an integer or floating-point column that has the AUTO_INCREMENT attribute, the next number in the sequence is inserted.

?

2. 從下面紅色部分可以得到 exisit 判斷記錄是否存在,不管select colum等同于select * ,mysql會忽略select colum的列而且允許有null 行。

Subqueries with EXISTS or NOT EXISTS If a subquery returns any rows at all, EXISTS subquery is TRUE, and NOT EXISTS subquery is FALSE. For example:SELECT column1 FROM t1 WHERE EXISTS (SELECT * FROM t2); Traditionally, an EXISTS subquery starts with SELECT *, but it could begin with SELECT 5 or SELECT column1 or anything at all. MySQL ignores the SELECT list in such a subquery, so it makes no difference.For the preceding example, if t2 contains any rows, even rows with nothing but NULL values, the EXISTS condition is TRUE. This is actually an unlikely example because a [NOT] EXISTS subquery almost always contains correlations. Here are some more realistic examples:What kind of store is present in one or more cities?SELECT DISTINCT store_type FROM storesWHERE EXISTS (SELECT * FROM cities_storesWHERE cities_stores.store_type = stores.store_type); What kind of store is present in no cities?SELECT DISTINCT store_type FROM storesWHERE NOT EXISTS (SELECT * FROM cities_storesWHERE cities_stores.store_type = stores.store_type); What kind of store is present in all cities?SELECT DISTINCT store_type FROM stores s1WHERE NOT EXISTS (SELECT * FROM cities WHERE NOT EXISTS (SELECT * FROM cities_storesWHERE cities_stores.city = cities.cityAND cities_stores.store_type = stores.store_type)); The last example is a double-nested NOT EXISTS query. That is, it has a NOT EXISTS clause within a NOT EXISTS clause. Formally, it answers the question “does a city exist with a store that is not in Stores”? But it is easier to say that a nested NOT EXISTS answers the question “is x TRUE for all y?”

?

The Apache Mahout? project's goal is to build a scalable machine learning library.

https://mahout.apache.org/

轉(zhuǎn)載于:https://www.cnblogs.com/davidwang456/p/3968026.html

總結(jié)

以上是生活随笔為你收集整理的mysql 变量is null 和 not exists区别的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 久久精品片 | 国产美女精品一区二区三区 | 色人阁五月| 先锋影音av资源在线观看 | 海角国产乱辈乱精品视频 | 玉丸(双性调教) | 国产精品99久久久久久大便 | 琪琪色18 | 在线观看日韩一区二区 | 亚洲AV永久无码国产精品国产 | 国产精品视频大全 | 成人1区 | 久久b| 人妻巨大乳hd免费看 | 一区二区三区精彩视频 | 中文字幕第六页 | 日本精品99 | 欧美少妇视频 | 亚洲 欧美 国产 另类 | 一区二区三区四区五区六区 | 久久夜夜操 | 日韩欧美少妇 | 欧美精品在欧美一区二区少妇 | 亚洲第6页 | 九热在线| 欧美激情国产日韩精品一区18 | 91偷拍精品一区二区三区 | 中国一区二区三区 | 97色在线观看 | 激情爱爱网 | 免费h片网站 | 亚洲精品乱码久久久久久久久久久久 | 成人久久久久 | 欧美乱论视频 | 一区二区中文字幕 | 中文字幕十一区 | 亚洲精品在线视频 | 中文字幕在线观看网站 | 久久久激情 | av网站大全在线观看 | 成人av高清在线观看 | 日韩色吧| 午夜精品久久久久久久久久蜜桃 | 精品国产一区二区三区四区阿崩 | 欧美成人片在线 | 伦伦影院午夜理论片 | 午夜寂寞福利 | 免费av网址在线观看 | 人人干人人搞 | av中文字幕一区二区三区 | 最新天堂在线视频 | 手机av在线网 | 在线中文天堂 | 欧美 日韩 国产一区 | 成人午夜视频在线 | 91蝌蚪视频在线观看 | 天堂网在线看 | 一级黄色免费毛片 | 日韩精品视频三区 | 国产麻豆影视 | 亚洲成人精品一区二区 | 亚洲第一在线视频 | 国产精品专区在线观看 | 伊人热久久 | 精品99在线观看 | 小h片在线观看 | 国产高清一区二区三区 | 丰满少妇麻豆av苏语棠 | 未满十八岁勿进 | 天狂传说之巴啦啦小魔仙 | 亚洲av永久无码精品一区二区国产 | 狠狠躁18三区二区一区视频 | 一本—道久久a久久精品蜜桃 | 在线观看亚洲免费视频 | 特黄三级又爽又粗又大 | 九草av | 中文字幕一区二区三区又粗 | 国产福利片在线观看 | 亚洲 欧美 视频 | 好男人天堂网 | 亚洲熟妇无码一区二区三区 | 熟女俱乐部一区二区视频在线 | 福利视频二区 | 一区二区三区www污污污网站 | 欧美成人免费在线观看视频 | 国产精品91视频 | 中文字幕高清av | 精品处破女学生 | 中国大陆一级片 | 成年人免费视频播放 | 欧美一区自拍 | va视频在线观看 | 亚洲成av人片在线观看无 | 久久爱综合网 | 亚洲码国产精品高潮在线 | 成人av图片 | 99精品欧美 | 成人精品三级av在线看 | 日韩一区二区免费视频 |