sqlÖеÄ@ÊÇʲôÒâ˼
sql ÖÐ @ ·ûºÅÓÃÓÚÖ¸¶¨Ò»¸öÅÌÎÊÖпɱäµÄ²ÎÊý£¬¶ÔÌá¸ß´úÂë¿É¶ÁÐÔ¡¢±ÜÃâ sql ×¢Èë¹¥»÷¡¢Ìá¸ßÐÔÄÜÓÐ×ÊÖú¡£Óï·¨£º@parameter_name£¬ÆäÖÐ parameter_name ÊDzÎÊýµÄÃû³Æ¡£
SQL ÖÐ @ ·ûºÅµÄ¼ÄÒå
ÔÚ SQL ÖУ¬@ ·ûºÅÓÃÓÚÖ¸¶¨Ò»¸ö²ÎÊý¡£²ÎÊýÊÇÅÌÎÊÖпɱäµÄ²¿·Ö£¬¿ÉÒÔÔÚÅÌÎʱ»Ö´ÐÐʱ±»²î±ðµÄÖµÌæ»»¡£
ÓÃ;
ʹÓà @ ·ûºÅÓм¸¸öÀûÒ棺
Ìá¸ß´úÂë¿É¶ÁÐÔ£ºÊ¹ÅÌÎʸüÒ×ÓÚÔĶÁºÍÃ÷È·£¬ÓÉÓÚ²ÎÊýÓëÏÖʵֵÍÑÀë¡£
±ÜÃâ SQL ×¢Èë¹¥»÷£ºÍ¨¹ý½«Óû§ÊäÈë×÷Ϊ²ÎÊýת´ï£¬¿ÉÒÔ±ÜÃâ¶ñÒâÓû§ÐÞ¸ÄÅÌÎʲ¢Ö´ÐÐδ¾ÊÚȨµÄ²Ù×÷¡£
Ìá¸ßÐÔÄÜ£ºÍ¨¹ýʹÓòÎÊý»¯ÅÌÎÊ£¬Êý¾Ý¿â¿ÉÒÔÔ¤±àÒëÅÌÎʲ¢½«Æä´æ´¢ÔÚ»º´æÖУ¬´Ó¶øÌá¸ßÐÔÄÜ¡£
Óï·¨
ʹÓà @ ·ûºÅÖ¸¶¨²ÎÊýµÄÓï·¨ÈçÏ£º
@parameter_name
µÇ¼ºó¸´ÖÆ
ÆäÖÐ parameter_name ÊDzÎÊýµÄÃû³Æ¡£
ʾÀý
ÏÂÃæÊÇÒ»¸öʾÀýÅÌÎÊ£¬ÆäÖÐʹÓÃÁË @ ·ûºÅÖ¸¶¨Ò»¸öÃûΪ @age µÄ²ÎÊý£º
SELECT * FROM users WHERE age > @age;
µÇ¼ºó¸´ÖÆ
µ±Ö´ÐдËÅÌÎÊʱ£¬¿ÉÒÔÌṩ²î±ðµÄ @age ÖµÀ´²éÕÒ²î±ðÄêËê¶ÎµÄÓû§¡£ÀýÈ磺
-- ²éÕÒÄêËê´óÓÚ 30 ËêµÄÈË SELECT * FROM users WHERE age > 30; -- ²éÕÒÄêËê´óÓÚ 25 ËêµÄÈË SELECT * FROM users WHERE age > 25;
µÇ¼ºó¸´ÖÆ
ÒÔÉϾÍÊÇsqlÖеÄ@ÊÇʲôÒâ˼µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡