²ÎÊý»¯SQLÓï¾äSqlParameter
±ÜÃâSQL×¢ÈëµÄ·½·¨ÓÐÁ½ÖÖ£ºÒ»ÊÇËùÓеÄSQLÓï¾ä¶¼´æ·ÅÔÚ´æ´¢¹ý³ÌÖУ¬ÕâÑù²»µ«¿ÉÒÔ±ÜÃâSQL×¢È룬»¹ÄÜÌá¸ßһЩÐÔÄÜ£¬²¢ÇÒ´æ´¢¹ý³Ì¿ÉÒÔÓÉרÃŵÄÊý¾Ý¿â¹ÜÀíÔ±(DBA)±àдºÍ¼¯ÖйÜÀí£¨ÕâÖÖ×ö·¨ÎÒÔÚһЩ¹«Ë¾¼û¹ý£©£¬²»¹ýÕâÖÖ×ö·¨ÓÐʱºòÕë¶ÔÏàͬµÄ¼¸¸ö±íÓв»Í¬Ìõ¼þµÄ²éѯ£¬SQLÓï¾ä¿ÉÄܲ»Í¬£¬ÕâÑù¾Í»á±àд´óÁ¿µÄ´æ´¢¹ý³Ì£¬ËùÒÔÓÐÈËÌá³öÁ˵ڶþÖÖ·½°¸£º²ÎÊý»¯SQLÓï¾ä¡£ÀýÈçÎÒÃÇÔÚ±¾ÆªÖд´½¨µÄ±íUserInfoÖвéÕÒËùÓÐÅ®ÐÔÓû§£¬ÄÇôͨ³£Çé¿öÏÂÎÒÃǵÄSQLÓï¾ä¿ÉÄÜÊÇÕâÑù£º
select * from UserInfo where sex=0
ÔÚ²ÎÊý»¯SQLÓï¾äÖÐÎÒÃǽ«ÊýÖµÒÔ²ÎÊý»¯µÄÐÎʽÌṩ£¬¶ÔÓÚÉÏÃæµÄ²éѯ£¬ÎÒÃÇÓòÎÊý»¯SQLÓï¾ä±íʾΪ£º
select * from UserInfo where sex=@sex
ÎÒÃÇÔÙ¶Ô´úÂëÖжÔÕâ¸öSQLÓï¾äÖеIJÎÊý½øÐи³Öµ£¬¼ÙÈçÎÒÃÇÒª²éÕÒUserInfo±íÖÐËùÓÐÄêÁä´óÓÚ30ËêµÄÄÐÐÔÓû§£¬Õâ¸ö²ÎÊý»¯SQLÓï¾ä¿ÉÒÔÕâôд£º
select * from UserInfo where sex=@sex and age>@age
ÏÂÃæÊÇÖ´ÐÐÕâ¸ö²éѯ²¢ÇÒ½«²éѯ½á¹û¼¯ÒÔDataTableµÄ·½Ê½·µ»ØµÄ´úÂ룺
C# code
//ʵÀý»¯Connection¶ÔÏó
SqlConnection connection = new SqlConnection("Data Source=(local);Initial Catalog=AspNetStudy;Persist Security Info=True;User ID=sa;Password=sa");
//ʵÀý»¯Command¶ÔÏó
SqlCommand command = new SqlCommand("select * from UserInfo where sex=@sex and age>@age", connection);
//µÚÒ»ÖÖÌí¼Ó²éѯ²ÎÊýµÄÀý×Ó
command.Parameters.AddWithValue("@sex", true);
//µÚ¶þÖÖÌí¼Ó²éѯ²ÎÊýµÄÀý×Ó
SqlParameter parameter = new SqlParameter("@age", SqlDbType.Int);//×¢ÒâUserInfo±íÀïage×Ö¶ÎÊÇintÀàÐ͵Ä
parameter.Value = 30;
command.Parameters.Add(parameter);//Ìí¼Ó²ÎÊý
//ʵÀý»¯DataAdapter
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataTable data = new DataTable();
Ïà¹ØÎĵµ£º
ÔÎĵØÖ·£ºhttp://www.eygle.com/case/Use.sql_trace.to.Diagnose.database.htm
SQL_TRACEÊÇOracleÌṩµÄÓÃÓÚ½øÐÐSQL¸ú×ÙµÄÊֶΣ¬ÊÇÇ¿ÓÐÁ¦µÄ¸¨ÖúÕï¶Ï¹¤¾ß.ÔÚÈÕ³£µÄÊý¾Ý¿âÎÊÌâÕï¶ÏºÍ½â¾öÖУ¬SQL_TRACEÊǷdz£³£Óõķ½·¨¡£
±¾ÎľÍSQL_TRACEµÄʹÓÃ×÷¼òµ¥Ì½ÌÖ£¬²¢Í¨¹ý¾ßÌå°¸Àý¶Ôsql_traceµÄʹÓýøÐÐ˵Ã÷.
Ò»¡¢ »ù´¡½éÉÜ
(a) ......
ÓÐÐí¶à²»Í¬ÀàÐ͵ÄÊý¾Ý¿â¹ÜÀíÔ±¡£ һЩÀàÐ͵ÄÊý¾Ý¿â¹ÜÀíÔ±ÖÂÁ¦ÓÚÓÚ¿ª·¢ÁìÓò£¬¶øÆäËûµÄÒ»²¿·Ö¸üÖØÊÓÊý¾Ý¿âÐÔÄܵĵ÷ÕûÒÔ¼°ÈÔÈ»ÓÐÒ»²¿·ÖÊý¾Ý¿â¹ÜÀíÔ±ÔòÖÂÁ¦ÓÚ¹ÜÀíSQL ServerµÄÒµÎñ¡£ ÒÀ¾ÝÊý¾Ý¿â¹ÜÀíÔ±µÄ¹¤×÷»·¾³²»Í¬£¬ËûÃǽ«Ö´ÐÐÒ»¶¨ÊýÁ¿µÄ²»Í¬µÄÈÎÎñ¡£ÎªÁËÇø·ÖËùÓв»Í¬µÄÈÎÎñ£¬Êý¾Ý¿â¹ÜÀíÔ±¿ÉÄÜÒªÖ´ÐÐÎÒÇåµ¥ÉÏËùÁеÄÈÎÎñ¡£
¡¡ ......
ÎÒÃǶ¼ÖªµÀÔÚOracleÖÐÿÌõSQLÓï¾äÔÚÖ´ÐÐ֮ǰ¶¼ÐèÒª¾¹ý½âÎö£¬ÕâÀïÃæÓÖ·ÖΪÈí½âÎöºÍÓ²½âÎö¡£ÔÚOracleÖдæÔÚÁ½ÖÖÀàÐ͵ÄSQLÓï¾ä£¬Ò»ÀàΪ
DDLÓï¾ä£¨Êý¾Ý¶¨ÒåÓïÑÔ£©£¬ËûÃÇÊÇ´ÓÀ´²»»á¹²ÏíʹÓõģ¬Ò²¾ÍÊÇÿ´ÎÖ´Ðж¼ÐèÒª½øÐÐÓ²½âÎö¡£»¹ÓÐÒ»Àà¾ÍÊÇDMLÓï¾ä£¨Êý¾Ý²Ù×ÝÓïÑÔ£©£¬ËûÃÇ»á¸ù¾ ......
Five basic search conditions are summarized here:
1) Comparison test
2) Range test
3) Set membership test
4) Pattern matching test (Like)
The pattern matching test checks to see whether the data value in a column matches a specified pattern
% mathes any se ......