类似语法问题,但其实请参考手册的说明和例子。
MySQL 5.4 reference manual 12.8.6.1.if statement
if search _ conditionthenstatement _ list
END IF
ifimplementsabasicconditionalconstruct.ifthe search _ conditionevaluatestotrue,thecorrespondingsqlstatementlistisexecuted
笔记本
thereisalsoanif(function,whichdiffersfromtheifstatementdescribedhere.see section 11.3,“控制流功能”)。
An IF . END IF block,likeallotherflow-controlblocksusedwithinstoredprograms,must be terminated with a semicolon,asshowninthinthion
DELIMITER //。
createfunctionsimplecompare (nint,m INT )。
返回变量(20 )。
比根
戴尔varchar (20 );
IF n m THEN SET s=' ';
ELSEIF n=m THEN SET s='=';
ELSE SET s='
END IF;
sets=concat(n,',s,',m );
返回s;
结束//
删除器
aswithotherflow-control constructs,if . endifblocksmaybenestedwithinotherflow-control constructs, includingotherifstatements.eachifmustbeterminatedbyitsownendiffollowedbyasemicolon.youcanuseindentationtomakenestedflow-ow ed flow-olblocksmoreeasilyreadablebyhumans (althoughthisisnotrequiredbymysql ),as shown here:
DELIMITER //。
createfunctionverbosecompare (nint,m INT ) )。
返回变量(50 )。
比根
declareSvarchar(50;
IF n=m THEN SET s='equals ';
ELSE
IF n m THEN SET s='greater ';
ELSE SET s='less ';
END IF;
sets=concat('is ',s,' than ' );
END IF;
sets=concat(n,',s,',m,'.');
返回s;
结束//
删除器