sqlÖÐ@µÄÒâ˼
sql ÖÐµÄ @ ·ûºÅÌåÏÖÒ»¸ö²ÎÊýµÄռλ·û£¬ÓÃÓÚ´æ´¢¶¯Ì¬»òδָ¶¨µÄÖµ£¬ÏêϸʹÓó¡¾°°üÀ¨´æ´¢Àú³Ì/º¯Êý¡¢¶¯Ì¬ sql ºÍÅÌÎʲÎÊý»¯¡£
SQL ÖÐ @ µÄ¼ÄÒå
SQL ÖÐµÄ @ ·ûºÅͨ³£ÌåÏÖÒ»¸ö²ÎÊýµÄռλ·û£¬ÓÃÓÚ´æ´¢¶¯Ì¬»òδָ¶¨µÄÖµ¡£
ʹÓó¡¾°
@ ·ûºÅÆÕ±éÓÃÓÚÖÖÖÖ SQL Óï¾äÖУ¬°üÀ¨£º
´æ´¢Àú³ÌºÍº¯Êý£º½«ÊäÈë»òÊä³ö²ÎÊýת´ï¸ø´æ´¢Àú³Ì»òº¯Êý¡£
¶¯Ì¬ SQL£º½¨É趯̬ SQL Óï¾ä£¬ÆäÖвÎÊýµÄÖµÔÚÔËÐÐʱȷ¶¨¡£
ÅÌÎʲÎÊý»¯£º×ª´ïÖµÀ´¹ýÂË»òÏÞÖÆÅÌÎÊЧ¹û£¬×èÖ¹ SQL ×¢Èë¹¥»÷¡£
Óï·¨
ÔÚ SQL ÖÐʹÓà @ ·ûºÅʱ£¬Í¨³£×ñÕÕÒÔÏÂÓï·¨£º
@parameter_name
µÇ¼ºó¸´ÖÆ
ÀýÈ磺
SELECT * FROM table_name WHERE id = @id
µÇ¼ºó¸´ÖÆ
ÏêϸʹÓÃ
´æ´¢Àú³ÌºÍº¯Êý£ºÔÚ½¨Éè´æ´¢Àú³Ì»òº¯Êýʱ£¬¿ÉÒÔÔÚ²ÎÊýÁбíÖÐÖ¸¶¨´øÓÐ @ ·ûºÅµÄ²ÎÊý¡£ÀýÈ磺
CREATE PROCEDURE my_proc (@param1 int, @param2 varchar(50))
µÇ¼ºó¸´ÖÆ
¶¯Ì¬ SQL£ºÊ¹Óà EXEC Óï¾äÖ´Ðж¯Ì¬ SQL ʱ£¬¿ÉÒÔʹÓà @ ·ûºÅת´ï²ÎÊý¡£ÀýÈ磺
EXEC (@sql_statement)
µÇ¼ºó¸´ÖÆ
ÅÌÎʲÎÊý»¯£ºÔÚÅÌÎÊÖÐʹÓà @ ·ûºÅÌæ»»Ìض¨Öµ£¬¿ÉÒÔÌá¸ßÐÔÄܺÍÇå¾²ÐÔ¡£ÀýÈ磺
SELECT * FROM table_name WHERE id = ?
µÇ¼ºó¸´ÖÆ
×¢ÖØ£º²î±ðÊý¾Ý¿âÖÎÀíϵͳ (DBMS) ¿ÉÄÜ¶Ô @ ·ûºÅµÄ´¦Àí·½·¨ÓÐËù²î±ð£¬Òò´ËÇë²ÎÔÄÌض¨ DBMS µÄÎĵµÒÔÏàʶÏêϸÓ÷¨¡£
ÒÔÉϾÍÊÇsqlÖÐ@µÄÒâ˼µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡