plsqlÖÐcase whenÓ÷¨
pl/sql ÖÐµÄ case when ÊÇÒ»ÖÖƾ֤Ìõ¼þÖ´Ðвî±ðÐж¯µÄÌõ¼þÓï¾ä¡£Óï·¨£ºcase when Ìõ¼þ then Ч¹û else ĬÈÏЧ¹û end;Óŵ㣺¸ü¾«Á·¡¢Ò׶Á£¬¿ÉÓÃǶÌס£ÏÞÖÆ£ºÖ»ÄÜ´¦Öóͷ£¼òµ¥ÖµÌõ¼þ£¬Ð§¹û±ØÐèÊǵ¥¸öÖµ¡£
PL/SQL ÖÐ CASE WHEN Ó÷¨
ʲôÊÇ CASE WHEN£¿
CASE WHEN ÊÇ PL/SQL ÖÐÒ»ÖÖÌõ¼þÓï¾ä£¬ÓÃÓÚƾָ֤¶¨µÄÌõ¼þÖ´Ðвî±ðµÄÐж¯¡£
Óï·¨
CASE WHEN Ìõ¼þ1 THEN Ч¹û1 WHEN Ìõ¼þ2 THEN Ч¹û2 ... ELSE ĬÈÏЧ¹û END;
µÇ¼ºó¸´ÖÆ
Ó÷¨
½ç˵Ìõ¼þ£ºWHEN ×Ó¾äÖ¸¶¨Òª¼ì²éµÄÌõ¼þ¡£
Ö¸¶¨Ð§¹û£ºTHEN ×Ó¾äÖ¸¶¨ÈôÊÇÌõ¼þΪÕæʱҪ·µ»ØµÄЧ¹û¡£
ÉèÖÃĬÈÏÖµ£ºELSE ×Ó¾äÖ¸¶¨ÈôÊÇËùÓÐÌõ¼þ¶¼²»Öª×ãʱҪ·µ»ØµÄЧ¹û¡£
ʾÀý
-- ½«Êý×Öת»»ÎªÔ·ÝÃû³Æ CASE score WHEN 1 THEN 'January' WHEN 2 THEN 'February' WHEN 3 THEN 'March' ELSE 'Unknown' END;
µÇ¼ºó¸´ÖÆ
Óŵã
¿ÉÓÃ×÷Ìæ»» IF-ELSEIF-ELSE Óï¾äµÄ¸ü¾«Á·¡¢Ò׶ÁµÄÒªÁì¡£
¿ÉÒÔǶÌ׶à¸ö CASE WHEN Óï¾ä£¬ÒÔ´¦Öóͷ£¸üÖØ´óµÄÌõ¼þ¡£
ÏÞÖÆ
Ö»ÄÜ´¦Öóͷ£¼òµ¥ÖµÌõ¼þ£¬²»¿ÉÓÃÓÚ´¦Öóͷ£¹æÄ£»òÁÐ±í¡£
CASE WHEN Óï¾äµÄЧ¹û±ØÐèÊǵ¥¸öÖµ£¬²»¿ÉÊDZí»òÓαꡣ
ÒÔÉϾÍÊÇplsqlÖÐcase whenÓ÷¨µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡