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

时间:2022-03-25 10:57:23

I have a mysql stored procedure in which I want to write a composite If statement. Let a, b,c be the variables then In what order the following if will execute.

我有一个mysql存储过程,我想在其中编写一个复合的If语句。设a,b,c为变量,然后按以下顺序执行以下if。

  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. Is there any problem in the statement? I actually want to know the precedence of AND, OR operators.

以上If语句不能正常工作。声明中有什么问题吗?我实际上想知道AND,OR运算符的优先级。

2 个解决方案

#1


0  

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 uses 3-state logic where an expression can be TRUE, FALSE, or NULL, and all comparisons with NULL are FALSE. See the documentation Working with NULL Values.

在SQL中,NULL不像FALSE; SQL使用3状态逻辑,其中表达式可以是TRUE,FALSE或NULL,并且所有与NULL的比较都是FALSE。请参阅文档使用NULL值。

#2


0  

If statement allows you to execute a set of SQL statements based on condition. If certain condition returns true then statement executes, otherwise not.

If语句允许您根据条件执行一组SQL语句。如果某些条件返回true则执行语句,否则不执行。

Read: IF statement in MySQL stored procedures

阅读:MySQL存储过程中的IF语句

#1


0  

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 uses 3-state logic where an expression can be TRUE, FALSE, or NULL, and all comparisons with NULL are FALSE. See the documentation Working with NULL Values.

在SQL中,NULL不像FALSE; SQL使用3状态逻辑,其中表达式可以是TRUE,FALSE或NULL,并且所有与NULL的比较都是FALSE。请参阅文档使用NULL值。

#2


0  

If statement allows you to execute a set of SQL statements based on condition. If certain condition returns true then statement executes, otherwise not.

If语句允许您根据条件执行一组SQL语句。如果某些条件返回true则执行语句,否则不执行。

Read: IF statement in MySQL stored procedures

阅读:MySQL存储过程中的IF语句