简体   繁体   中英

Composite IF statement in mysql stored procedure

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.

  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.

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 .

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

Read: IF statement in MySQL stored procedures

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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