Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Linq to SQL Like Operator(×ªÔØ)


As a response for customer's question, I decided to write about using Like Operator in Linq to SQL queries.
Starting from a simple query from Northwind Database;
var query = from c in ctx.Customers
            where c.City == "London"
            select c;
The query that will be sent to the database will be:
SELECT CustomerID, CompanyName, ...
from    dbo.Customers
WHERE  City = [London]
There are some ways to write a Linq query that reaults in using Like Operator in the SQL statement:
1. Using String.StartsWith or String.Endswith
Writing the following query:
var query = from c in ctx.Customers
            where c.City.StartsWith("Lo")
            select c;
will generate this SQL statement:
SELECT CustomerID, CompanyName, ...
from    dbo.Customers
WHERE  City LIKE [Lo%]
which is exactly what we wanted. Same goes with String.EndsWith.
But, what is we want to query the customer with city name like "L_n%"? (starts with a Capital 'L', than some character, than 'n' and than the rest of the name). Using the query
var query = from c in ctx.Customers
            where c.City.StartsWith("L") && c.City.Contains("n")
            select c;
generates the statement:
SELECT CustomerID, CompanyName, ...
from    dbo.Customers
WHERE  City LIKE [L%]
AND      City LIKE [%n%]
which is not exactly what we wanted, and a little more complicated as well.
2. Using SqlMethods.Like method
Digging into System.Data.Linq.SqlClient namespace, I found a little helper class called SqlMethods, which can be very usefull in such scenarios. SqlMethods


Ïà¹ØÎĵµ£º

64λwin7°²×°Ê¹ÓÃPL/SQL developerÁ¬½ÓOracle 10g±¸Íü

ÔÚÍøÉÏËÑË÷Á˰ëÌ죬Ö÷ÒªÔ­ÒòÊÇoci.dllÊÇ64λµÄ,¶øPL/SQL developerÖ»ÓÐ32λµÄ,ÔÚʹÓÃ64λoci.dllÎļþʱ³ö´í.
ÔÚÍøÉÏÕÒÁ˺ܶà×ÊÁÏ,×î·½±ãµÄ½â¾ö·½°¸ÈçÏÂ:
1.µ½oracle¹ÙÍøÏÂÔØOracle InstantClient,ÎÒϵÄÊÇinstantclient-basiclite-win32-10.2.0.4.zip,°ÑËü½âѹËõµ½
oracle°²×°Ä¿Â¼productÏÂ,ÆäÖл¹ÓÐÒ»¸öĿ¼Ϊ10.2.0. ......

sql ²é±í¿Õ¼äÓï¾ä

SELECT UPPER(F.TABLESPACE_NAME) "±í¿Õ¼äÃû",
       D.TOT_GROOTTE_MB "±í¿Õ¼ä´óС(M)",
       D.TOT_GROOTTE_MB - F.TOTAL_BYTES "ÒÑʹÓÿռä(M)",
       TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_G ......

ASP.NET2.0·ÖÒ³¼¼Êõ֮ʹÓô¿sqlÓï¾äµÄË«top·Öҳƪ

RepeaterÔÚǰ̨ʹÓñȽÏÁé»î×ÔÓÉ£¬µ«ÓÐÒ»¸öÎÊÌâ¾ÍÊÇRepeater²»Ö§³ÖÖ±½Ó·ÖÒ³£¬Õâ¸öºÜ¶àÈË¿´ÆðÀ´¾ÍÓе㲻ÏëÓÃÁË£¬µ«ÎÒÏë´ó¼Ò¶¼ÖªµÀGridView¿Ø¼þ»òDataGrid¿Ø¼þÔÚÆôÓÃ×Ô´ø·ÖÒ³µÄʱºòÆäʵЧÂÊÊǷdz£µÍµÄ£¬´óµÄ²»Ëµ£¬Ò»µ«µ½Á˰ÙÍò¼¶Êý¾ÝÒԺ󣬾ͻá¸Ð¾õÊǶàôµÄÍ´¿àºÍÎÞÄÍÁË£¬ËùÒÔ¼´Ê¹ÊÇÓÃDataGrid(GridView)¿Ø¼þ£¬¸ßÊÖÃÇ»¹ÊÇÖ»»á ......

¡¾Oracle¡¿SQLÓÅ»¯µÄÖØÒª¹¤¾ß AUTOTRACE

¡¾AUTOTRACE¡¿SQLÓÅ»¯µÄÖØÒª¹¤¾ß--AUTOTRACE
Ìáµ½SQLÓÅ»¯£¬²»Äܲ»ÌáAUTOTRACEµÄÇ¿´ó¹¦ÄÜ¡£Ê¹ÓÃÆðÀ´·Ç³£±ã½Ý£¬²»¹ýÔÚÊÇʹÓÃ֮ǰ£¬ÐèÒª×öһЩÅäÖõŤ×÷¡£¼òÒªµÄÃèÊöÒ»ÏÂÕâ¸ö¹ý³Ì£¬¹©Ã»ÓÐʹÓùýµÄÅóÓѲο¼¡£
1.ʹÓÃsysÓû§Ö´ÐÐplustrce½Å±¾
sys@ora10g> @?/sqlplus/admin/plustrce
sys@ora10g> drop role plustrace ......

SQL Server±¸·ÝÊÂÎñÈÕÖ¾½áβ(Tail)

ÊÂÎñÈÕÖ¾½áβ¾­³£Ìá½»Êý¾Ý¿âδ±¸·ÝµÄÊÂÎñÈÕÖ¾ÄÚÈÝ¡£»ù±¾ÉÏ£¬Ã¿Ò»´ÎÄãÖ´ÐÐÊÂÎñÈÕÖ¾±¸·Ýʱ£¬Äã¶¼ÔÚÖ´ÐÐÊÂÎñÈÕÖ¾½áβµÄ±¸·Ý¡£
ÄÇΪʲô»áÕâôÉè¼ÆÄØ£¿ÒòΪҲÐíÓÉÓÚ½éÖʵÄË𻵣¬µ±Êý¾Ý¿âÒѾ­²»ÔÙ¿ÉÓÃʱ£¬Âé·³¾ÍÀ´ÁË¡£Èç¹ûÏÂÒ»¸öÂß¼­²½ÖèÕýºÃ¾ÍÊÇÒª±¸·Ýµ±Ç°ÊÂÎñÈÕÖ¾µÄ»°£¬¿ÉÒÔÓ¦ÓÃÕâ¸ö±¸·ÝÀ´Ê¹Êý¾Ý¿â´¦Óڵȴý(Standby)״̬¡£ÄãÉ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ