±ÜÃâSQL×¢ÈëºÍÌØÊâ×Ö·ûµÄÒ»ÖÖ·½·¨
µÝ¹éС̸×Ô±¸C#¸¨Öúº¯Êý
ʮ08
±ÜÃâSQL×¢ÈëºÍÌØÊâ×Ö·ûµÄÒ»ÖÖ·½·¨
C#Add comments
±ÜÃâSQL×¢ÈëºÍÌØÊâ×Ö·ûµÄ°ì·¨Óкܶ࣬²»Í¬Êý¾Ý¿âÒ²Óв»Í¬Êý¾Ý¿âµÄ½â¾ö·½°¸£¬ADO.NETÖÐʹÓÃDbCommand.Parameters½â¾öÕâ¸öÎÊÌ⣬ΪÁËÁ˽âËûµÄÔÀí£¬ÎÒ²éÁËÒ»ÏÂ.NETÖÐSQLCommandµÄÔ´´úÂëºÍMySQL.NETÖÐMySQLCommandµÄÔ´´úÂë¡£
.NETÔ´´úÂ볬¼¶ÄѸú×Ù£¬Ã²ËÆÊÇÓÃÁËSQL Server¶ÀÓеÄÌØÐÔ£¬°Ñ²ÎÊýµÄÃû³Æ¡¢ÀàÐÍ¡¢°ÑÖµµÄ¶þ½øÖƶ¼´«¸øÁËSQL Server API£¬¾ßÌåûÓиúµ½¡£
MySQLʵÏ־ͺܼòµ¥ÁË£¬Ëû»á°Ñ×Ö·û´®ÀàÐ͵IJÎÊývalueʹÓÃÒ»¸ö¹ýÂËÊý×éÀ´¹ýÂË£¬ÔÚ¹ýÂË×Ö·ûÇ°Ãæ¼ÓÉÏ“\”£¬ÎÒÈÏΪÕâÊÇÒ»ÖÖͨÓõÄ×ö·¨£¬ËäȻЧÂÊÉϲ»ÈçSQLCommandºÃ£¬µ«ÊǺÍÈÝÒ×ÒÆÖ²¸üÈÝÒ׿´¶®£¡
ʹÓÃPHP+MySQL×öÍøÕ¾µÄͬѧҲ¿ÉÒÔÀûÓÃ×ÅÀàËƵÄ˼ÏëÉú³É°²È«µÄSQLÁ¬½Ó´®£¬ÎÒ¿´ÁËPHPWindÊý¾Ý¿â´¦Àíº¯Êý£¬Ã²ËƲ¢Ã»ÓжÔËùÓеĹýÂË×Ö·û½øÐд¦Àí£¬Õâ¾Í´æÔÚ×ÅһЩ°²È«Òþ»¼¡£
Ô´´úÂë
private static string stringOfBackslashChars = "\u005c\u00a5\u0160\u20a9\u2216\ufe68\uff3c";
private static string stringOfQuoteChars =
"\u0027\u00b4\u02b9\u02ba\u02bb\u02bc\u02c8\u02ca\u02cb\u02d9\u0300\u0301\u2018\u2019\u201a\u2032\u2035\u275b\u275c\uff07";
/// <summary>
/// Escapes the string.
/// </summary>
/// <param name="value" />The string to escape</param>
/// <returns>The string with all quotes escaped.</returns>
public static string EscapeString(string value)
{
StringBuilder sb = new StringBuilder();
foreach (char c in value)
{
if (stringOfQuoteChars.IndexOf(c) >= 0 ||
stringOfBackslashChars.IndexOf(c) >= 0)
sb.Append("\\");
sb.Append(c);
}
return sb.ToString();
}
ÈçºÎÔÚVS2008ÖпªÆô.NETÔ´´úÂëµ÷ÊÔ
¹¤¾ß->Ñ¡Ïî->
µ÷ÊÔ->ÆôÓÃÔ´·þÎñÆ÷Ö§³Ö
·ûºÅ->Ìí¼ÓPDBλÖÃhttp://referencesource.microsoft.com/symbols
±¾µØ»º´æĿ¼
Ïà¹ØÎĵµ£º
ÔÚʹÓÃSQL*PlusÉú³É±¨¸æÎļþµÄʱºò£¬ÍùÍù»áÒòΪÆäĬÈϵÄÉèÖõ¼ÖÂÊä³öµÄ½á¹û·Ç³£µÄûÓпɶÁÐÔ£¬ÏÂÃæ½éÉÜÒ»¸öÈÕ³£ÖлᱻÓõ½µÄÒ»¸ö½Å±¾£¬ÆäÖаüº¬Ò»Ð©¸ñʽ»¯
Êä³öµÄsetÃüÁî
£¬ÎªÁË·½±ãÀí½â£¬ÎÒ»áÔÚÿһÌõsetÃüÁîÖ®ºó½ô¸ú×ÅÒ»¸ö¼òµ¥µÄ½âÊÍ£¬ÇëÂýÂýÌå»á¡£
sqlplus -s user_name/user_password << EOF >/dev/n ......
1 :ÆÕͨSQLÓï¾ä¿ÉÒÔÓÃexecÖ´ÐÐ
Select * from tableName
exec('select * from tableName')
exec sp_executesql N'select * from tableName' -- Çë×¢Òâ×Ö·û´®Ç°Ò»¶¨Òª¼ÓN
2:×Ö¶ÎÃû£¬±íÃû£¬Êý¾Ý¿âÃûÖ®Àà×÷Ϊ±äÁ¿Ê±£¬±ØÐëÓö¯Ì¬SQL
declare @fname varchar(20)
set @fname = 'FiledName'
Select @fname fr ......
ÒòΪÑöÍûORACLE£¬ËùÒÔÒ»Ö±¶¼ÒÔΪSQL SERVERºÜ±¿¡£
¾Ý´«SQL 2005ÓÐÁËRowIDµÄ¶«Î÷£¬¿ÉÒÔ½â¾öTOPÅÅÐòµÄÎÊÌâ¡£¿Éϧ»¹Ã»Óлú»áÌåÑé¡£ÔÚSQL 2000ÖÐд´æ´¢¹ý³Ì£¬×Ü»áÓöµ½ÐèÒªTOPµÄµØ·½£¬¶øÒ»µ©Óöµ½TOP£¬ÒòΪû°ì·¨°ÑTOPºóÃæµÄÊý×Ö×÷Ϊ±äÁ¿Ð´µ½Ô¤±àÒëµÄÓï¾äÖÐÈ¥£¬ËùÒÔÖ»Äܹ»Ê¹Óù¹Ôì SQL£¬Ê¹ÓÃExecÀ´Ö´ÐС£²»ËµÐ§ÂʵÄÎÊÌ⣠......
ÈÕÆÚÀàÐ͸ÅÊö
SQL ServerÖеÄÈÕÆÚÀàÐÍ°üÀ¨datetimeºÍsmalldatetime£¬½öÄÜ´¦Àí¿ÉÒÔʶ±ðΪ1753Äê¡«9999Äê¼äµÄÈÕÆÚµÄÖµ£¬Ã»Óе¥¶ÀµÄÈÕÆÚÐÍ»òʱ¼äÐÍ¡£
1£®datetime
datetimeÀàÐÍ´¦Àí´Ó1753Äê1ÔÂ1ÈÕ¡«9999Äê12ÔÂ31ÈÕµÄÈÕÆÚºÍʱ¼äÊý¾Ý£¬¾«È·¶ÈΪ°Ù·ÖÖ®ÈýÃë¡£
¼´£º¶ÔÓÚ0.000¡«0.001¡¢0.009µÄÈÕÆÚÖµ£¬µ÷ÕûΪ0.000£»¶ÔÓÚ ......
ʮһ¡¢ÒÔÉϺ¯ÊýµÄ²¿·ÖʵÀý
1:replace º¯Êý
µÚÒ»¸ö²ÎÊýÄãµÄ×Ö·û´®£¬µÚ¶þ¸ö²ÎÊýÄãÏëÌæ»»µÄ²¿·Ö£¬µÚÈý¸ö²ÎÊýÄãÒªÌæ»»³Éʲô
select replace('lihan','a','b')
& ......