Home > database >  mysql noop or null statement equivalent
mysql noop or null statement equivalent

Time:06-30

When coding I personally like to complete my flow control/structure before filling it in. To allow it to work in oracle I could just put a null; command oracle null command in the empty block to satisfy the parser. In mysql i'm getting an error for an empty codeblock and using null; doesn't work.

e.g.

if( _orgId IS NULL ) then
   select _orgId;

else
   null; -- this throws an error.
   -- TODO: Write complex statement.
end if;

Does Mysql have a null command equivalent and if so what is it?

CodePudding user response:

MySQL supports a statement DO <expression>;

See https://dev.mysql.com/doc/refman/8.0/en/do.html

It doesn't matter what the expression is, the statement does not return any results. The common use of this statement is for calling functions such as RELEASE_LOCK() or any other function that has a side-effect.

So you can use it as a no-op by writing any expression that has no side-effect:

DO NULL;
  • Related