sqlÖÐdeclareÊÇʲôÒâ˼
declare Óï¾äÓÃÓÚÔÚ sql ÖÐÉùÃ÷±äÁ¿£¬¼´´æ´¢ÖµµÄÊý¾ÝÈÝÆ÷¡£±äÁ¿ÀàÐÍ°üÀ¨ÕûÊý¡¢Ð¡Êý¡¢×Ö·û´®¡¢ÈÕÆÚ¡¢²¼¶ûÖµµÈ¡£±äÁ¿ÃüÃûÒÔ @·ûºÅ¿ªÍ·£¬²¢×ñÕÕÌض¨ÃüÃû¹æÔò¡£ÉùÃ÷±äÁ¿ÓÐÖúÓÚ´úÂë¿É¶ÁÐÔ¡¢´úÂëÖØÓúÍÐÔÄÜÓÅ»¯¡£
SQL ÖÐµÄ DECLARE
DECLARED µÄ¼ÄÒå
DECLARE Óï¾äÓÃÓÚÔÚ SQL ÖÐÉùÃ÷±äÁ¿¡£±äÁ¿ÊÇ´æ´¢ÖµµÄÊý¾ÝÈÝÆ÷£¬¿ÉÒÔÔÚÕû¸ö SQL Óï¾äÖÐʹÓá£
Óï·¨
DECLARE ;
µÇ¼ºó¸´ÖÆ
Ó÷¨
DECLARE @age INT; SET @age = 25; SELECT @age;
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃÇÉùÃ÷ÎúÒ»¸öÃûΪ @age µÄÕûÊý±äÁ¿£¬²¢½«Öµ 25 ¸¶ÓëËü¡£È»ºó£¬ÎÒÃÇ¿ÉÒÔʹÓà @age ±äÁ¿À´¼ìË÷´æ´¢µÄÖµ¡£
±äÁ¿µÄÀàÐÍ
SQL ÖеıäÁ¿¿ÉÒÔ¾ßÓвî±ðµÄÊý¾ÝÀàÐÍ£¬°üÀ¨£º
ÕûÊý (INT)
СÊý (NUMERIC)
×Ö·û´® (CHAR/VARCHAR)
ÈÕÆÚ (DATE/TIME)
²¼¶ûÖµ (BIT)
±äÁ¿µÄÃüÃû¹æÔò
SQL ±äÁ¿Ãû³Æ±ØÐèÒÔ @·ûºÅ¿ªÍ·£¬²¢ÇÒÖ»ÄÜ°üÀ¨×Öĸ¡¢Êý×ÖºÍÏ»®Ïß¡£±äÁ¿Ãû³Æ²»¿ÉÓë SQL ±£´æ×Ö³åÍ»¡£
Óŵã
ʹÓà DECLARE Óï¾äÉùÃ÷±äÁ¿ÌṩÁËÒÔÏÂÓŵ㣺
´úÂë¿É¶ÁÐÔ£ºËüʹ´úÂë¸ü¾ß¿É¶ÁÐÔ£¬ÓÉÓÚ±äÁ¿Ãû³Æ¸ü¾ßÐÎòÐÔÇÒÒ×ÓÚÃ÷È·¡£
´úÂëÖØÓ㺱äÁ¿¿ÉÒÔ´æ´¢¾³£Ê¹ÓõÄÖµ£¬Õâ¿ÉÒÔïÔÌ´úÂëÖظ´¡£
ÐÔÄÜÓÅ»¯£ºÍ¨¹ý½«Öµ´æ´¢ÔÚ±äÁ¿ÖУ¬¿ÉÒÔ×èÖ¹¶à´ÎÔÚÊý¾Ý¿âÖмìË÷ËüÃÇ£¬´Ó¶øÌá¸ßÐÔÄÜ¡£
ÒÔÉϾÍÊÇsqlÖÐdeclareÊÇʲôÒâ˼µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡