公告
财富商城
积分规则
提问
发文
2019-06-20 04:09发布
混吃等死
Is there any difference between MySQL
IF (myText IS NOT NULL) THEN
and
IF (myText != '') THEN
Yes there is a difference.
In simple words, myText IS NOT NULL specifies that myText is having some value which could be '' too.
Where as myText != '' specifies that it returns TRUE, if myText does NOT contain an empty string.
There is a difference. If the default value of a column is "NULL", then if no data has been set for a field, it is truly null. However, if the value of a field has been updated as '', it is not NULL, rather it is empty.
See here for more information Link
Yes there is a big difference between a NULL value and a blank/empty value.
NULL
Here's one resource that describes the differences.
When myText IS NULL:
myText IS NULL
myText IS NOT NULL
FALSE
myText != ''
However, you should not get into the habit of treating them the same, since most of the time they will behave differently: For example:
Assume you have a table tbl:
tbl
id text 1 NULL 2 3 abc
Note: 1 contains a NULL value, and 2 contains an empty string ('').
''
If you run the following query:
SELECT * FROM tbl WHERE text != ''
... it will return record 3.
SELECT * FROM tbl WHERE text IS NOT NULL
... it will return records 2 and 3.
最多设置5个标签!
Yes there is a difference.
In simple words, myText IS NOT NULL specifies that myText is having some value which could be '' too.
Where as myText != '' specifies that it returns TRUE, if myText does NOT contain an empty string.
There is a difference. If the default value of a column is "NULL", then if no data has been set for a field, it is truly null. However, if the value of a field has been updated as '', it is not NULL, rather it is empty.
See here for more information Link
Yes there is a big difference between a
NULL
value and a blank/empty value.Here's one resource that describes the differences.
When
myText IS NULL
:myText IS NOT NULL
evaluates toFALSE
myText != ''
evaluates toNULL
(which essentially behaves the same asFALSE
would in this specific case you wrote)However, you should not get into the habit of treating them the same, since most of the time they will behave differently: For example:
Assume you have a table
tbl
:Note: 1 contains a
NULL
value, and 2 contains an empty string (''
).If you run the following query:
... it will return record 3.
If you run the following query:
... it will return records 2 and 3.