sqlÖÐnvlÊÇʲôÒâ˼
sql ÖÐ nvl º¯ÊýÓÃÓÚÌæ»» null ֵΪָ¶¨µÄĬÈÏÖµ£¬Ó﷨Ϊ nvl(expression, default_value)¡£ËüÓÃÓÚ×èÖ¹Òò null Öµµ¼Ö¹ýʧ»òÒì³££¬ÌṩÓÐÒâÒåµÄĬÈÏÖµ£¬È·±£ÅÌÎÊ·µ»Ø·Ç null Öµ¡£ÐèҪעÖصÄÊÇ£¬default_value ±ØÐèÓë expression ÏàͬÊý¾ÝÀàÐÍ£¬ÇÒ nvl ²»»áÐÞ¸ÄÔʼֵ¡£¹ØÓÚÖØ´ó±í´ïʽ£¬¿ÉÒÔʹÓÃǶÌ× nvl º¯Êý´¦Öóͷ£¶à¸ö null Öµ£¬µ«¹ØÓÚ´óÐÍÊý¾Ý¼¯£¬½¨ÒéÔÚÐèҪʱ²ÅʹÓà nvl ÒÔ×èÖ¹ÐÔÄÜϽµ¡£
SQL ÖÐ NVL µÄ¼ÄÒå
NVL ÊÇ SQL ÖеÄÒ»¸öº¯Êý£¬ËüÓÃÓÚÌæ»» NULL ֵΪָ¶¨µÄĬÈÏÖµ¡£
Óï·¨
NVL(expression, default_value)
ÆäÖУº
expression£ºÒª¼ì²éµÄ±í´ïʽ¡£
default_value£ºÈôÊÇ expression Ϊ NULL£¬Ôò·µ»ØµÄÖµ¡£
ʾÀý
ÒÔÏÂʾÀý½« NULL ÖµÌ滻Ϊ “Unknown”:
SELECT NVL(name, 'Unknown') FROM customers;
µÇ¼ºó¸´ÖÆ
ÊÂÇéÔÀí
NVL º¯ÊýÊ×Ïȼì²é expression ÊÇ·ñΪ NULL¡£ÈôÊÇΪ NULL£¬Ôò·µ»Ø default_value¡£ÈôÊÇ expression ²»Îª NULL£¬Ôò·µ»Ø expression µÄÖµ¡£
ÓÃ;
NVL º¯ÊýÔÚÒÔÏÂÇéÐÎϺÜÓÐÓãº
×èÖ¹Òò NULL Öµµ¼ÖµĹýʧ»òÒì³£¡£
Ϊ±¨±í»òÏÔʾÌṩÓÐÒâÒåµÄĬÈÏÖµ¡£
È·±£ÅÌÎÊʼÖÕ·µ»Ø·Ç NULL Öµ¡£
ÐèҪעÖصÄÊÂÏî
default_value ±ØÐèÊÇÓë expression ÏàͬµÄÊý¾ÝÀàÐÍ¡£
NVL ²»»áÐÞ¸ÄÔʼֵ£¬ËüÖ»·µ»ØÒ»¸öÌæ»»ºóµÄÖµ¡£
¹ØÓÚÖØ´óµÄ±í´ïʽ£¬¿ÉÒÔʹÓÃǶÌ× NVL º¯ÊýÀ´´¦Öóͷ£¶à¸ö NULL Öµ¡£
¹ØÓÚ´óÐÍÊý¾Ý¼¯£¬Ê¹Óà NVL ¿ÉÄܵ¼ÖÂÐÔÄÜϽµ£¬Òò´Ë½¨ÒéÔÚÐèҪʱ²ÅʹÓá£
ÒÔÉϾÍÊÇsqlÖÐnvlÊÇʲôÒâ˼µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡