SQLServerÖÐÓõıȽ϶àµÄº¯Êý
ÏÂÃæÊÇÎÒÔÚSQLServerÖÐÓõıȽ϶àµÄº¯Êý£¬Ä㻹ÓÃЩʲôº¯Êý£¿»òÕ߶ÔÄĸöº¯ÊýÓбȽϺÃÓ÷¨£¿»òÕßÄã²»ÓÃÄÄЩº¯Êý£¿
LEFT ( character_expression , integer_expression )
·µ»Ø´Ó×Ö·û´®×ó±ß¿ªÊ¼Ö¸¶¨¸öÊýµÄ×Ö·û¡£
Àý:
select left('my name is viwo',4)
my n
RIGHT ( character_expression , integer_expression )
·µ»Ø×Ö·û´®ÖдÓÓұ߿ªÊ¼Ö¸¶¨¸öÊýµÄ integer_expression ×Ö·û¡£
Àý:
select right('my name is viwo',4)
viwo
CAST ( expression AS data_type )
½«Ä³ÖÖÊý¾ÝÀàÐ͵ıí´ïʽÏÔʽת»»ÎªÁíÒ»ÖÖÊý¾ÝÀàÐÍ¡£CAST ºÍ CONVERT ÌṩÏàËƵŦÄÜ¡£
Àý:
select cast(2 as varchar(10))+cast(11 as varchar(10))
211
CONVERT (data_type[(length)], expression [, style])
½«Ä³ÖÖÊý¾ÝÀàÐ͵ıí´ïʽÏÔʽת»»ÎªÁíÒ»ÖÖÊý¾ÝÀàÐÍ¡£CAST ºÍ CONVERT ÌṩÏàËƵŦÄÜ¡£
Àý:
select convert(varchar,getdate(),112)
20070328
DATEADD ( datepart , number, date )
ÔÚÏòÖ¸¶¨ÈÕÆÚ¼ÓÉÏÒ»¶Îʱ¼äµÄ»ù´¡ÉÏ£¬·µ»ØÐ嵀 datetime Öµ¡£
Àý:
select dateadd(month,2,getdate())
2007-05-28 14:24:37.280
COALESCE ( expression [ ,...n ] )
·µ»ØÆä²ÎÊýÖеÚÒ»¸ö·Ç¿Õ±í´ïʽ¡£
Àý:
select coalesce(null,null,0)
0
select coalesce(2,3,0)
2
CHARINDEX ( expression1 , expression2 [ , start_location ] )
·µ»Ø×Ö·û´®ÖÐÖ¸¶¨±í´ïʽµÄÆðʼλÖá£
Àý:
select charindex('ab','eabcd')
2
LTRIM ( character_expression )
ɾ³ýÆðʼ¿Õ¸ñºó·µ»Ø×Ö·û±í´ïʽ¡£
Àý:
select ltrim(' abc ')
abc
RTRIM ( character_expression )
½Ø¶ÏËùÓÐβËæ¿Õ¸ñºó·µ»ØÒ»¸ö×Ö·û´®¡£
Àý:
select rtrim(' abc ')
abc
ROUND ( numeric_expression , length [ , function ] )
·µ»ØÊý×Ö±í´ïʽ²¢ËÄÉáÎåÈëΪָ¶¨µÄ³¤¶È»ò¾«¶È¡£
Àý:
select ROUND(748.585, 2)
748.590
FLOOR ( numeric_expression )
·µ»ØСÓÚ»òµÈÓÚËù¸øÊý×Ö±í´ïʽµÄ×î´óÕûÊý¡£
Àý:
select floor(748.585)
748
CEILING ( numeric_expression )
·µ»Ø´óÓÚ»òµÈÓÚËù¸øÊý×Ö±í´ïʽµÄ×îСÕûÊý¡£
Àý:
select ceiling(748.585)
749
REPLACE ( 'string_expression1' , 'string_expression2' , 'string_expression3' )
ÓõÚÈý¸ö±í´ïʽÌæ»»µÚÒ»¸ö×Ö·û´®±í´ïʽÖ
Ïà¹ØÎĵµ£º
ÔÚÁÙʱ±í
create table #T (…)
ºÍ±í±äÁ¿
declare @T table (…)
Ö®¼äÖ÷ÒªÓÐ3¸öÀíÂÛÉϵIJ»Í¬¡£
µÚÒ»¸ö²»Í¬Ê¹ÊÂÎñÈÕÖ¾²»»á¼Ç¼±í±äÁ¿¡£Òò´Ë£¬ËüÃÇÍÑÀëÁËÊÂÎñ»úÖƵķ¶Î§£¬´ÓÏÂÃæµÄÀý×Ó¿ÉÏÔ¶øÒ×¼û£º
create table #T (s varchar(128))
declare @T table (s varchar(128))
insert into #T select 'old va ......
¡¡È·Êµ£¬Êý¾Ý¿âµÄά»¤³£³£½»¸øÄÇЩרҵµÄÊý¾Ý¿â¹ÜÀíÔ±£¬µ«ÊÇ×÷Ϊһ¸ö¿ª·¢Õߣ¬ÄãÒ²Ðíż¶ûÐèÒªÔÝʱ´ÓÊÂÕâ¸ö¹¤×÷¡£ËùÒÔ£¬ÊÔÒ»ÊÔÕâÁ½¸öSQL·þÎñÆ÷ά»¤¼¼ÇÉ£ºÇáËɸıäÊý¾Ý¿âÓµÓÐÕß¡¢ÕûÀíË÷ÒýËéƬ¡£Ë»áÏëµ½ÄãÉõÖÁ¿ÉÒÔ¸øÄÇЩÊý¾Ý¿â¹ÜÀíÔ±½ÌÉÏÒ»Á½¸öм¼ÇÉÄØ£¿ÖØÖ¸¶¨Êý¾Ý¿âÓµÓÐÕßµ±»Ø¸´»òÕßн¨Êý¾Ý¿âʱ£¬ÄãÓÐûÓÐ×¢Òâµ½SQL Server° ......
Ë÷ÒýµÄÖØÒªÐÔ
¡¡¡¡Êý¾Ý¿âÐÔÄÜÓÅ»¯ÖÐË÷Òý¾ø¶ÔÊÇÒ»¸öÖØÁ¿¼¶µÄÒòËØ£¬¿ÉÒÔ˵£¬Ë÷ÒýʹÓò»µ±£¬ÆäËüÓÅ»¯´ëÊ©½«ºÁÎÞÒâÒå¡£
¡¡¡¡¾Û´ØË÷Òý(Clustered Index)ºÍ·Ç¾Û´ØË÷Òý (Non- Clustered Index)¡¡
¡¡¡¡×îͨË׵ĽâÊÍÊÇ:¾Û´ØË÷ÒýµÄ˳Ðò¾ÍÊÇÊý¾ÝµÄÎïÀí´æ´¢Ë³Ðò£¬¶ø¶Ô·Ç¾Û´ØË÷ÒýµÄË÷Òý˳ÐòÓëÊý¾ÝÎïÀíÅÅÁÐ˳ÐòÎ޹ء£¾ÙÀýÀ´Ëµ£¬Äã·µ½Ð ......
/*
--´´½¨ÊÓͼ
create view RandomView as select re=rand()
--×Ô¶¨Ò庯Êý:È¡µÃÖ¸¶¨·¶Î§µÄËæ»úÊý
create function RandData(
@a int,
@b int)
returns decimal(38,0)
as
begin
declare @r decimal(38,0)
select @r=cast(re*(@b-@a)+@a as decimal(38,0)) from RandomView
return(@r)
end
go
s ......
sqlserverºÍoracle³£Óú¯Êý¶Ô±È
Êýѧº¯Êý
¡¡¡¡1.¾ø¶ÔÖµ
¡¡¡¡S:select abs(-1) value
¡¡¡¡O:select abs(-1) value from dual
¡¡¡¡2.È¡Õû(´ó)
¡¡¡¡S:select ceiling(-1.001) value
¡¡¡¡O:select ceil(-1.001) value from dual
¡¡¡¡3.È¡Õû£¨Ð¡£©
¡¡¡¡S:select floor(-1.001) value
¡¡¡¡O:select floor(-1.0 ......