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

SQLº¯ÊýÖ®ËÄÉáÎåÈë

SQLº¯ÊýÖ®ËÄÉáÎåÈ루ת×Ôhttp://ln1058.javaeye.com/blog/191502£©
ÎÊÌâ1£º
SELECT CAST('123.456' as decimal) ½«»áµÃµ½ 123£¨Ð¡ÊýµãºóÃæµÄ½«»á±»Ê¡ÂÔµô£©¡£
Èç¹ûÏ£ÍûµÃµ½Ð¡ÊýµãºóÃæµÄÁ½Î»¡£
ÔòÐèÒª°ÑÉÏÃæµÄ¸ÄΪ
SELECT CAST('123.456' as decimal(38, 2)) ===>123.46
×Ô¶¯ËÄÉáÎåÈëÁË£¡ ÎÊÌâ2£º
SELECT ROUND(123.75633, 2, 1), ROUND(123.75633, 2)
ÉÏÃæµÄSQLµÃµ½µÄ2¸öÖµÊDz»Ò»ÑùµÄ£¬Ç°Ò»¸öÊÇ£º123.75000£¬ºóÒ»¸öÊÇ£º123.76000¡£
ÒòΪǰÕßÔÚ½øÐÐËÄÉáÎåÈë֮ǰ£¬Ð¡ÊýµãºóÒѾ­±»½ØÈ¡£¬±£ÁôÁË2λ¡£
¶øºóÕßÔòûÓб»½ØÈ¡£¬ËÄÉáÎåÈëʱ×ÔÈ»¾Í»áµÃµ½123.76000 ROUND
·µ»ØÊý×Ö±í´ïʽ²¢ËÄÉáÎåÈëΪָ¶¨µÄ³¤¶È»ò¾«¶È¡£ Óï·¨
ROUND ( numeric_e-xpression , length [ , function ] ) ²ÎÊý
numeric_e-xpression ¾«È·Êý×Ö»ò½üËÆÊý×ÖÊý¾ÝÀàÐÍÀà±ðµÄ±í´ïʽ£¨bit Êý¾ÝÀàÐͳýÍ⣩¡£ length ÊÇ numeric_e-xpression ½«ÒªËÄÉáÎåÈëµÄ¾«¶È¡£length ±ØÐëÊÇ tinyint¡¢smallint »òint¡£µ± length ΪÕýÊýʱ£¬numeric_e-xpression ËÄÉáÎåÈëΪ length ËùÖ¸¶¨µÄСÊýλÊý¡£µ± length Ϊ¸ºÊýʱ£¬numeric_e-xpression Ôò°´ length ËùÖ¸¶¨µÄÔÚСÊýµãµÄ×ó±ßËÄÉáÎåÈë¡£ function ÊÇÒªÖ´ÐеIJÙ×÷ÀàÐÍ¡£function ±ØÐëÊÇ tinyint¡¢smallint »ò int¡£Èç¹ûÊ¡ÂÔ function »ò function µÄֵΪ 0£¨Ä¬ÈÏ£©£¬numeric_e-xpression ½«ËÄÉáÎåÈë¡£µ±Ö¸¶¨ 0 ÒÔÍâµÄֵʱ£¬½«½Ø¶Ï numeric_e-xpression¡£ ·µ»ØÀàÐÍ
·µ»ØÓë numeric_e-xpression ÏàͬµÄÀàÐÍ¡£ ×¢ÊÍ
ROUND ʼÖÕ·µ»ØÒ»¸öÖµ¡£Èç¹û length ÊǸºÊýÇÒ´óÓÚСÊýµãÇ°µÄÊý×Ö¸öÊý£¬ROUND ½«·µ»Ø 0¡£ ʾÀý ½á¹û
ROUND(748.58, -4) 0 µ± length ÊǸºÊýʱ£¬ÎÞÂÛʲôÊý¾ÝÀàÐÍ£¬ROUND ¶¼½«·µ»ØÒ»¸öËÄÉáÎåÈëµÄ numeric_e-xpression¡£ ʾÀý ½á¹û
ROUND(748.58, -1) 750.00
ROUND(748.58, -2) 700.00
ROUND(748.58, -3) 1000.00 ʾÀý
A. ʹÓà ROUND ºÍ¹À¼ÆÖµ
ÏÂÀýÏÔʾÁ½¸ö±í´ïʽ£¬ËµÃ÷ʹÓà ROUND º¯ÊýÇÒ×îºóÒ»¸öÊý×ÖʼÖÕÊǹÀ¼ÆÖµ¡£ Select ROUND(123.9994, 3), ROUND(123.9995, 3)
GO ÏÂÃæÊǽá¹û¼¯£º ----------- -----------
123.9990    124.0000   B. ʹÓà ROUND ºÍËÄÉáÎåÈëµÄ½üËÆÖµ
ÏÂÀýÏÔʾËÄÉáÎåÈëºÍ½üËÆÖµ¡£ Óï¾ä ½á¹û
Select ROUND(123.454


Ïà¹ØÎĵµ£º

SQL ServerÖеÄͨÅä·û

ͨÅä·û_
"_"ºÅ±íʾÈÎÒâµ¥¸ö×Ö·û,¸Ã·ûºÅÖ»ÄÜÆ¥ÅäÒ»¸ö×Ö·û."_"¿ÉÒÔ·ÅÔÚ²éѯÌõ¼þµÄÈÎÒâλÖÃ,ÇÒÖ»ÄÜ´ú±íÒ»¸ö×Ö·û.Ò»¸öºº×ÖֻʹÓÃÒ»¸ö"_"±íʾ.
Àý×Ó£º
if PATINDEX('%[ß¹-×ö]%','ÐèÒªÅжϵÄ×Ö·û')>0 -- ÅжÏÊÇ·ñÓÐ×Ö·û
print 'Óкº×Ö'
else
print 'ÎÞºº×Ö'
ͨÅä·û%
"%"·ûºÅÊÇ×Ö·ûÆ¥Åä·û,ÄÜÆ¥Åä0¸ö»ò¸ü¶à×Ö·ûµÄÈÎÒⳤ¶ ......

SQL Server ¾­³£Óõ½µÄ¼¸¸öÉèÖÃÑ¡Ïî

1. SET DEADLOCK_PRIORITY
˵Ã÷£º¿ØÖÆÔÚ·¢ÉúËÀËøÇé¿öʱ»á»°µÄ·´Ó¦·½Ê½¡£Èç¹ûÁ½¸ö½ø³Ì¶¼Ëø¶¨Êý¾Ý£¬²¢ÇÒÖ±µ½ÆäËü½ø³ÌÊÍ·Å×Ô¼ºµÄËøʱ£¬Ã¿¸ö½ø³Ì²ÅÄÜÊÍ·Å×Ô¼ºµÄËø£¬¼´·¢ÉúËÀËøÇé¿ö¡£
Óï·¨£ºSET DEADLOCK_PRIORITY { LOW | NORMAL | @deadlock_var }
²ÎÊý£ºLOW   ......

asp.net´Ósql server2005ÖвéѯÊý¾Ý

 Ê×ÏÈÒªÌí¼Ó
using System.Data;
using System.Data.SqlClient;    
½ÓÏÂÀ´£º
          SqlConnection conn = new SqlConnection("server=QLPC\\SQL2005;uid=sa;pwd=£¨ÄãµÄÃÜÂ룩;database=£¨ÄãµÄÊý¾Ý±í£©");     &n ......

¶¯Ì¬SQL»ù±¾Óï·¨

 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µÄÓ²½âÎöºÍÈí½âÎö


 
˵µ½Èí½âÎö£¨soft prase£©ºÍÓ²½âÎö£¨hard prase£©£¬¾Í²»Äܲ»ËµÒ»ÏÂOracle¶ÔsqlµÄ´¦Àí¹ý³Ì¡£µ±Äã·¢³öÒ»ÌõsqlÓï¾ä½»¸¶Oracle£¬ÔÚÖ´ÐкͻñÈ¡½á¹ûÇ°£¬Oracle¶Ô´Ësql½«½øÐм¸¸ö²½ÖèµÄ´¦Àí¹ý³Ì£º
    1¡¢Óï·¨¼ì²é£¨syntax check£©
    ¼ì²é´ËsqlµÄƴдÊÇ·ñÓï ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ