简体   繁体   English

mysql存储过程中的复合IF语句

[英]Composite IF statement in mysql stored procedure

I have a mysql stored procedure in which I want to write a composite If statement. 我有一个mysql存储过程,我想在其中编写一个复合If语句。 Let a, b,c be the variables then In what order the following if will execute. 令a,b,c为变量,然后将按以下顺序执行。

  IF (a AND c=0) OR (b AND c=0) OR (!a AND !b) THEN
    execute the code....

The above If statement not working properly. 上面的If语句无法正常工作。 Is there any problem in the statement? 声明中有任何问题吗? I actually want to know the precedence of AND, OR operators. 我实际上想知道AND,OR运算符的优先级。

I think you want: 我想你要:

IF (a IS NOT NULL AND c=0) OR (b IS NOT NULL AND c=0) OR (a IS NOT NULL AND b IS NOT NULL) THEN
execute the code....

In SQL, NULL does not act like FALSE ; 在SQL中, NULL行为不像FALSE SQL uses 3-state logic where an expression can be TRUE , FALSE , or NULL , and all comparisons with NULL are FALSE . SQL使用三态逻辑,其中表达式可以为TRUEFALSENULL ,并且所有与NULL比较均为FALSE See the documentation Working with NULL Values . 请参阅文档使用NULL值

If statement allows you to execute a set of SQL statements based on condition. 如果语句允许您根据条件执行一组SQL语句。 If certain condition returns true then statement executes, otherwise not. 如果某些条件返回true,则执行语句,否则不执行。

Read: IF statement in MySQL stored procedures 阅读: MySQL存储过程中的IF语句

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM