锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
set of rows ,rather than performing single row-by-row processing.
濡傛灉浣犵殑紼嬪簭閲屼竴瀹氳涓鏉′竴鏉$殑鎵ц錛岄偅涔堜竴瀹氳鍏堣冭檻浣跨敤濡倃hile寰幆錛屽瓙鏌ヨ錛?br /> 涓存椂琛紝琛ㄥ彉閲忕瓑絳夛紝濡傛灉榪欎簺閮戒笉鑳芥弧瓚寵姹傦紝鍦ㄨ冭檻浣跨敤娓告爣銆?br />
T-SQL涓父鏍囩殑鐢熷瓨鍛ㄦ湡錛?br /> 1.鐢ㄨ繑鍥炰竴涓湁鏁堢粨鏋滈泦鐨剆ql璇彞鏉ュ畾涔変竴涓父鏍囥?br /> a cursor is defined via a SQL statement that returns a valid result set.
2. 鎵撳紑娓告爣
3. 涓鏃︽父鏍囪鎵撳紑灝卞彲浠ヤ粠娓告爣涓瘡嬈″彇鍑轟竴琛屾暟鎹紝瑕佹牴鎹父鏍囩殑瀹氫箟鍙互鍚戝墠鍘繪暟鎹垨
鍚戝悗鍙栨暟鎹?br /> the rows can be fetched moving forword or backword ,depending on the original cursor definition.
4. 鏍規嵁娓告爣鐨勭被鍨嬶紝鏁版嵁鍙互琚慨鏀規垨鑰呭彧鑳借銆?br /> 5.鏈鍚庯紝鐢ㄥ畬娓告爣鍚庯紝蹇呴』琚樉紺虹殑鍏抽棴錛屽茍涓斾粠鍐呭瓨涓Щ闄ゃ?br />
娓告爣瀹氫箟鏍煎紡錛?br /> declare cursor_name cursor
[local|global]
[forword_only|scroll]
[static|keyset|dynamic|fast_forword]
[read_only| scroll_locks|optimistic]
[type_warning]
for select_statement[for update [of column[,...]]]
The select_statement argument is the query used to define the data within the cursor. Avoid
using a query that hasmore columns and rows than will actually be used, because cursors, while
open, are kept inmemory. The UPDATE [OF column_name [,...n]] is used to specify those columns
that are allowed to be updated by the cursor.
]]>
1.case鍑芥暟浠ヤ竴涓〃杈懼紡浣滀負杈撳叆錛屼竴涓間綔涓鴻緭鍑?br />鏍煎紡錛歝ase 鍚庨潰鏈夎緭鍏ヨ〃杈懼紡錛寃hen鍚庨潰鐨勭殑姣忎竴涓〃杈懼紡閮戒細鍜宑ase鍚庨潰鐨勮緭鍏ヨ〃杈懼紡榪涜姣旇緝榪愮畻
濡傛灉鐩哥瓑錛屽垯榪斿洖錛屽惁鍒欒繑鍥瀍lse鍚庨潰鐨勮〃杈懼紡錛屽鏋滄病鏈塭lse鍒欒繑鍥濶ULL銆?br />case input_expression
when when_expression then result_expression
[...n]
[else else_result_expression]
end
case鐨勭浜岀鎯呭喌錛?br />case鍚庨潰娌℃湁琛ㄨ揪寮忥紝when鍚庨潰璺熺殑鏄痓ool琛ㄨ揪寮忋傝繑鍥炵涓涓獁hen鍚庨潰璁$畻涓簍rue鐨勮〃杈懼紡
鏍煎紡涓猴細
case
when bool_expression then result_expression
[...n]
else result_expression
end
2. if....else...鐨勬牸寮?br />if bool_expression
{sql_statement|sql_block}
[else
{sql_statement|sql_block}
]
3.begin ....end 鐩稿綋浜巆++涓殑{...}鐢ㄦ潵褰㈡垚涓涓唬鐮佸潡
4.鏉′歡寰幆
return,while,goto,waitfor
return
return 鐢ㄤ簬緇撴潫褰撳墠鐨剆ql鍧?鏌ヨ錛屽瓨鍌ㄨ繃紼嬨?br />綾諱技浜巆++涓殑return銆?br />return 鍙互榪斿洖涓涓暟瀛?/p>
while 綾諱技c++涓殑while錛屽悓鏍鋒敮鎸乥reak錛宑ontinue錛宐reak鏉ョ粨鏉熷綋鍓嶅唴灞傚驚鐜紝continue緇х畫褰撳墠寰幆
waitfor鏍煎紡
waitfor
delay 'time_to_pass'//鎵ц鍓嶇瓑寰呯殑鏃墮棿錛氭牸寮忎負00:00:00灝忔椂錛氬垎閽燂細縐?br /> |time 'time_to_execute'//璁劇疆瀹為檯鎵ц鐨勬椂闂?br /> |錛坮eceive_statement錛塠,TimeOUT timeout]
鍙互鍒╃敤waitfor灝嗘煇浜涘鏉傜殑鎵ц璁懼畾涓哄湪鐩稿絀洪棽鐨勬椂闂村唴榪涜銆?/p>
SQL Server 瀵規暟鎹被鍨嬩嬌鐢ㄤ互涓嬩紭鍏堢駭欏哄簭錛?/p>
鐢ㄦ埛瀹氫箟鏁版嵁綾誨瀷錛堟渶楂橈級
sql_variant
xml
datetimeoffset
datetime2
datetime
smalldatetime
date
time
float
real
decimal
money
smallmoney
bigint
int
smallint
tinyint
bit
ntext
text
image
timestamp
uniqueidentifier
nvarchar錛堝寘鎷?nvarchar(max)錛?/p>
nchar
varchar錛堝寘鎷?varchar(max)錛?/p>
char
varbinary錛堝寘鎷?varbinary(max)錛?/p>
binary錛堟渶浣庯級