当前位置:网站首页>MySQL ifnull usage function
MySQL ifnull usage function
2022-07-05 20:51:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack , I've prepared for you today Idea Registration code .
Later MYSQL IFNULL Specific narratives that use this function , For your reference , Suppose you MYSQL IFNULL There is something wrong with the functional category of the clause . The most beautiful .
MYSQL IFNULL(expr1,expr2) hypothesis expr1 No NULL,IFNULL() return expr1. Otherwise it returns expr2.IFNULL() Returns a numeric or string value , Depending on the context in which it is used . mysql> select IFNULL(1,0); -> 1 mysql> select IFNULL(0,10); -> 0 mysql> select IFNULL(1/0,10); -> 10 mysql> select IFNULL(1/0,yes); -> yes IF(expr1,expr2,expr3) hypothesis expr1 yes TRUE(expr1<>0 And expr1<>NULL), that IF() return expr2. Otherwise it returns expr3.IF() Returns a numeric or string value , Depending on the context in which it is used .
mysql> select IF(1>2,2,3); -> 3 mysql> select IF(1<2,yes,no); -> yes mysql> select IF(strcmp(test,test1),yes,no); -> no expr1 Is calculated as an integer value . It means assuming that you are testing floating-point or string values . You should use a comparison operation to do .
mysql> select IF(0.1,1,0); -> 0 mysql> select IF(0.1<>0,1,0); -> 1 In the first case above .IF(0.1) return 0, because 0.1 Is transformed to an integer value , Cause test IF(0). This may not be what you expect . In another case , Compare and test the original floating-point value to see if it is non-zero . The result of the comparison is used as an integer .
CASE value WHEN [compare-value] THEN result [WHEN [compare-value] THEN result …] [ELSE result] END CASE WHEN [condition] THEN result [WHEN [condition] THEN result …] [ELSE result] END The first version number returns result. among value=compare-value. The second version number assumes that the first condition is true , return result. Suppose there is no match result value , So the result is ELSE After result Returned .
Suppose there is no ELSE part . that NULL Returned . mysql> SELECT CASE 1 WHEN 1 THEN “one” WHEN 2 THEN “two” ELSE “more” END; -> “one” mysql> SELECT CASE WHEN 1>0 THEN “true” ELSE “false” END; -> “true” mysql> SELECT CASE BINARY “B” when “a” then 1 when “b” then 2 END; -> NULL
The following is true of MYSQL IFNULL The use of function is described in detail , For your reference . Suppose you are in MYSQL IFNULL We have encountered similar problems in the use of functions , It's better to have a look .
MYSQL IFNULL(expr1,expr2) hypothesis expr1 No NULL,IFNULL() return expr1, Otherwise it returns expr2.
IFNULL() Returns a numeric or string value , Depending on the context in which it is used .
mysql> select IFNULL(1,0); -> 1 mysql> select IFNULL(0,10); -> 0 mysql> select IFNULL(1/0,10); -> 10 mysql> select IFNULL(1/0,yes); -> yes IF(expr1,expr2,expr3) hypothesis expr1 yes TRUE(expr1<>0 And expr1<>NULL), that IF() return expr2, Otherwise it returns expr3.IF() Returns a numeric or string value , Depending on the context in which it is used . mysql> select IF(1>2,2,3); -> 3 mysql> select IF(1<2,yes,no); -> yes mysql> select IF(strcmp(test,test1),yes,no); -> no expr1 Is calculated as an integer value , It means assuming that you are testing floating-point or string values , You should use a comparison operation to do .
mysql> select IF(0.1,1,0); -> 0 mysql> select IF(0.1<>0,1,0); -> 1 In the first case above .IF(0.1) return 0. because 0.1 Is transformed to an integer value , Cause test IF(0). This may not be what you expect . In another case , Compare and test the original floating-point value to see if it is non-zero , The result of the comparison is used as an integer .
CASE value WHEN [compare-value] THEN result [WHEN [compare-value] THEN result …] [ELSE result] END CASE WHEN [condition] THEN result [WHEN [condition] THEN result …] [ELSE result] END The first version number returns result. among value=compare-value. The second version number assumes that the first condition is true . return result. Suppose there is no match result value , So the result is ELSE After result Returned . Suppose there is no ELSE part , that NULL Returned . mysql> SELECT CASE 1 WHEN 1 THEN “one” WHEN 2 THEN “two” ELSE “more” END; -> “one” mysql> SELECT CASE WHEN 1>0 THEN “true” ELSE “false” END; -> “true” mysql> SELECT CASE BINARY “B” when “a” then 1 when “b” then 2 END; -> NULL
Copyright notice : This article is an original blog article . Blog , Without consent , Shall not be reproduced .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/117657.html Link to the original text :https://javaforall.cn
边栏推荐
- AI automatically generates annotation documents from code
- 3.3 project evaluation
- Duchefa MS medium contains vitamin instructions
- 产品好不好,谁说了算?Sonar提出分析的性能指标,帮助您轻松判断产品性能及表现
- 王老吉药业“关爱烈日下最可爱的人”公益活动在南京启动
- How to open an account online for futures? Is it safe?
- 当Steam教育进入个性化信息技术课程
- 学习机器人无从下手?带你体会当下机器人热门研究方向有哪些
- Point cloud file Dat file read save
- ViewRootImpl和WindowManagerService笔记
猜你喜欢
Prosci LAG-3 recombinant protein specification
Duchefa丨MS培养基含维生素说明书
Who the final say whether the product is good or not? Sonar puts forward performance indicators for analysis to help you easily judge product performance and performance
Kubernetes resource object introduction and common commands (V) - (configmap & Secret)
When steam education enters personalized information technology courses
最长摆动序列[贪心练习]
Which is the best online collaboration product? Microsoft loop, notion, flowus
ClickHouse 复制粘贴多行sql语句报错
Wanglaoji pharmaceutical's public welfare activity of "caring for the most lovely people under the scorching sun" was launched in Nanjing
Abnova丨DNA 标记高质量控制测试方案
随机推荐
MYSQL IFNULL使用功能
Applet global configuration
Material Design组件 - 使用BottomSheet展现扩展内容(二)
重上吹麻滩——段芝堂创始人翟立冬游记
ClickHouse 复制粘贴多行sql语句报错
当Steam教育进入个性化信息技术课程
ProSci LAG3抗体的化学性质和应用说明
Make Jar, Not War
The Chinese Academy of Management Sciences gathered industry experts, and Fu Qiang won the title of "top ten youth" of think tank experts
ts 之 泛型
Chemical properties and application instructions of prosci Lag3 antibody
Abnova丨培养细胞总 RNA 纯化试剂盒中英文说明书
PHP deserialization +md5 collision
Duchefa MS medium contains vitamin instructions
研学旅游实践教育的开展助力文旅产业发展
haas506 2.0开发教程 - 阿里云ota - pac 固件升级(仅支持2.2以上版本)
Popular science | does poor English affect the NPDP exam?
Welcome to the game and win rich bonuses: Code Golf Challenge officially launched
模式-“里氏替换原则”
线程池的使用