加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 数据库 > MySql > 正文

The Apache Mahout projects goal is to build a scalable machi

发布时间:2020-05-23 15:30:41 所属栏目:MySql 来源:互联网
导读:问题:使用游标遍历时,发现使用select var into tmp where var=?然后判断if tmp is null时,不能走完所有的遍历。经debug发现,当var为空时,则跳出游标的遍历。解决方式:使用if not exists(select var into tmp where var=?)时,则ok。这个可以从mysql官方

问题:

使用游标遍历时,发现使用

select var into tmp where var=?

然后判断if tmp is null时,不能走完所有的遍历。经debug发现,

当var为空时,则跳出游标的遍历。

解决方式:

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

这个可以从mysql官方文档中找到原因:

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

Problems the value a common source confusion newcomers SQL,who often think that the same thing an empty string . This the . mysql<span style="color: #808080;">> <span style="color: #0000ff;">INSERT <span style="color: #0000ff;">INTO my_table (phone) <span style="color: #0000ff;">VALUES (<span style="color: #0000ff;">NULL<span style="color: #000000;">);
mysql<span style="color: #808080;">> <span style="color: #0000ff;">INSERT <span style="color: #0000ff;">INTO my_table (phone) <span style="color: #0000ff;">VALUES (<span style="color: #ff0000;">''<span style="color: #000000;">);
Both statements <span style="color: #0000ff;">insert a value <span style="color: #0000ff;">into the phone <span style="color: #0000ff;">column,but the first inserts a <span style="color: #0000ff;">NULL value <span style="color: #808080;">and the second inserts an empty string. The meaning <span style="color: #0000ff;">of the first can be regarded <span style="color: #0000ff;">as “phone <span style="color: #0000ff;">number <span style="color: #0000ff;">is <span style="color: #808080;">not known” <span style="color: #808080;">and the meaning <span style="color: #0000ff;">of the second can be regarded <span style="color: #0000ff;">as “the person <span style="color: #0000ff;">is known <span style="color: #0000ff;">to have no phone,<span style="color: #808080;">and thus no phone <span style="color: #0000ff;">number<span style="color: #000000;">.”

<span style="color: #0000ff;">To help <span style="color: #0000ff;">with <span style="color: #0000ff;">NULL handling,you can <span style="color: #0000ff;">use the <span style="color: #0000ff;">IS <span style="color: #0000ff;">NULL <span style="color: #808080;">and <span style="color: #0000ff;">IS <span style="color: #808080;">NOT <span style="color: #0000ff;">NULL operators <span style="color: #808080;">and the IFNULL() <span style="color: #0000ff;">function<span style="color: #000000;">.

<span style="color: #808080;">In SQL,the <span style="color: #0000ff;">NULL value <span style="color: #0000ff;">is never true <span style="color: #808080;">in comparison <span style="color: #0000ff;">to <span style="color: #808080;">any other value,even <span style="color: #0000ff;">NULL. An expression that <span style="color: #0000ff;">contains <span style="color: #0000ff;">NULL always produces a <span style="color: #0000ff;">NULL value unless otherwise indicated <span style="color: #808080;">in the documentation <span style="color: #0000ff;">for the operators <span style="color: #808080;">and functions involved <span style="color: #808080;">in the expression. <span style="color: #808080;">All columns <span style="color: #808080;">in the following example <span style="color: #0000ff;">return <span style="color: #0000ff;">NULL<span style="color: #000000;">:

mysql<span style="color: #808080;">> <span style="color: #0000ff;">SELECT <span style="color: #0000ff;">NULL,<span style="color: #800000; font-weight: bold;">1<span style="color: #808080;">+<span style="color: #0000ff;">NULL,CONCAT(<span style="color: #ff0000;">'<span style="color: #ff0000;">Invisible<span style="color: #ff0000;">',<span style="color: #0000ff;">NULL<span style="color: #000000;">);
<span style="color: #ff0000;">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;
<span style="color: #0000ff;">To look <span style="color: #0000ff;">for <span style="color: #0000ff;">NULL <span style="color: #0000ff;">values,you must <span style="color: #0000ff;">use the <span style="color: #0000ff;">IS <span style="color: #0000ff;">NULL test. The following statements show how <span style="color: #0000ff;">to find the <span style="color: #0000ff;">NULL phone <span style="color: #0000ff;">number <span style="color: #808080;">and the empty phone <span style="color: #0000ff;">number<span style="color: #000000;">:

mysql<span style="color: #808080;">> <span style="color: #0000ff;">SELECT <span style="color: #808080;"> <span style="color: #0000ff;">FROM my_table <span style="color: #0000ff;">WHERE phone <span style="color: #0000ff;">IS <span style="color: #0000ff;">NULL<span style="color: #000000;">;
mysql<span style="color: #808080;">> <span style="color: #0000ff;">SELECT <span style="color: #808080;">
<span style="color: #0000ff;">FROM my_table <span style="color: #0000ff;">WHERE phone <span style="color: #808080;">= <span style="color: #ff0000;">''<span style="color: #000000;">;
See Section <span style="color: #800000; font-weight: bold;">3.3.<span style="color: #800000; font-weight: bold;">4.6,“Working <span style="color: #0000ff;">with <span style="color: #0000ff;">NULL <span style="color: #0000ff;">Values”,<span style="color: #0000ff;">for additional information <span style="color: #808080;">and<span style="color: #000000;"> examples.

You can <span style="color: #0000ff;">add an <span style="color: #0000ff;">index <span style="color: #0000ff;">on a <span style="color: #0000ff;">column that can have <span style="color: #0000ff;">NULL <span style="color: #0000ff;">values <span style="color: #0000ff;">if you are using the MyISAM,InnoDB,<span style="color: #808080;">or BDB,<span style="color: #808080;">or MEMORY storage engine. Otherwise,you must <span style="color: #0000ff;">declare an indexed <span style="color: #0000ff;">column <span style="color: #808080;">NOT <span style="color: #0000ff;">NULL,<span style="color: #808080;">and you cannot <span style="color: #0000ff;">insert <span style="color: #0000ff;">NULL <span style="color: #0000ff;">into the <span style="color: #0000ff;">column<span style="color: #000000;">.

<span style="color: #0000ff;">When reading data <span style="color: #0000ff;">with <span style="color: #0000ff;">LOAD DATA INFILE,empty <span style="color: #808080;">or missing columns are updated <span style="color: #0000ff;">with <span style="color: #ff0000;">''. <span style="color: #0000ff;">To <span style="color: #0000ff;">load a <span style="color: #0000ff;">NULL value <span style="color: #0000ff;">into a <span style="color: #0000ff;">column,<span style="color: #0000ff;">use N <span style="color: #808080;">in the data <span style="color: #0000ff;">file. The literal word “<span style="color: #0000ff;">NULL” may also be used under <span style="color: #808080;">some circumstances. See Section <span style="color: #800000; font-weight: bold;">13.2.<span style="color: #800000; font-weight: bold;">6,“<span style="color: #0000ff;">LOAD<span style="color: #000000;"> DATA INFILE Syntax”.

<span style="color: #0000ff;">When using <span style="color: #0000ff;">DISTINCT,<span style="color: #0000ff;">GROUP <span style="color: #0000ff;">BY,<span style="color: #808080;">or <span style="color: #0000ff;">ORDER <span style="color: #0000ff;">BY,<span style="color: #808080;">all <span style="color: #0000ff;">NULL <span style="color: #0000ff;">values are regarded <span style="color: #0000ff;">as<span style="color: #000000;"> equal.

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读