sql - How can I test an IF statement in MySQL? -
how can test if statement in mysql ?
i need know, happens when query if
statement , returns nothing (0 row selected) ?
in other word, select
query returns when no row selected? return null
? if yes, throw error? if ( null ) ...
? or in case statement of if
won't execute?
in reality, have code this:
if ( select banned users id=new.user_id ) // stuff
note: banned
column contains either 0
or 1
.
all want know, code safe when query doesn't return row? mean throw error or nothing happens (just if
statement doesn't execute) ?
noted wanted test myselft, don't know how can test if
statement in mysql. example, wanted test code:
begin if ( select banned users id=new.user_id ) select 'test'; endif; end
but code above doesn't run. that's why i've asked question.
an if
statement can tested in context of mysql stored program (a procedure, function or trigger.) mysql doesn't support anonymous blocks.
to test if
statement, can create procedure
delimiter $$ create procedure foo begin if ( some_condition ) select 'evaluation of some_condition returned true' msg; else select 'evaluation of some_condition did not return true' msg; end if; end$$ delimiter ; call foo;
Comments
Post a Comment