SQLÊý¾Ý¿â
CURSOR
==================================
l SQL ÓαêCURSORµÄʹÓÃ
ʹÓÃÆðÀ´ºÜ¼òµ¥£¬Ïȶ¨Ò壬Ȼºó¸³¸öÖµ£¬´ò¿ª£¬Í¨¹ýWhile Loop Ò»¸öÒ»¸ö¶ÁÏÂÈ¥£¬×îºó¹Ø±Õ£¬ÊÍ·ÅÄÚ´æ¡£»ù±¾Ì×·ÈçÏ£º
DECLARE MyCursor cursor /* ÉùÃ÷Óα꣬ĬÈÏΪµ¥´¿ÏòÇ°µÄÓαꡣÈç¹ûÏëҪǰºóÌøÀ´ÌøÈ¥µÄ£¬Ð´³ÉScroll Cursor¼´¿É */
FOR
SELECT Column1, Column2 from ijij±í
Where ijijÌõ¼þ
OPEN MyCursor /* ´ò¿ªÓαê */
FETCH NEXT from MyCursor Into @A, @B /* ¶ÁÈ¡µÚ1ÐÐÊý¾Ý*/
WHILE @@FETCH_STATUS = 0 /* ÓÃWHILEÑ»·¿ØÖÆÓαê */
BEGIN /*BEGIN-END ¿é*/
//ÔÚÕâÀï,ÓÃ@A,@B×öµãÊÂ,»òÕ߸ÄÒ»¸ÄֵʲôµÄ.
FETCH NEXT from MyCursor Into @A, @B /* ×¥ÏÂÒ»ÐÐ */
END
CLOSE MyCursor /* ¹Ø±ÕÓαê */
DEALLOCATE MyCursor /* ɾ³ýÓαê,ÊÍ·ÅÄÚ´æ */
ÉùÃ÷Óαê///////////////////////
USE pubs
GO
DECLARE authors_cursor CURSOR FOR
SELECT au_id,au_fname,au_lname
from authors
GO
USE pubs
GO
DECLARE authors_cursor1 CURSOR FOR
SELECT au_id,au_fname,au_lname
from authors
FOR READ ONLY
GO
USE pubs
GO
DECLARE authors_cursor2 CURSOR FOR
SELECT au_id,au_fname,au_lname
from authors
FOR UPDATE
GO
´ò¿ªÓαê////////////
DECLARE mancursor CURSOR FOR
SELECT *
from db_manpowerinfo.dbo.ÈËʱí
WHERE 񅧏='00019'
OPEN mancursor
FETCH NEXT from mancursor
CLOSE mancursor
¶ÁÈ¡ÓαêÖеÄÊý¾Ý/////////////////////
DECLARE mancursor1 CURSOR FOR
SELECT ±àºÅ,ÐÕÃû,ÐÔ±ð,Éí·ÝÖ¤ºÅ
from db_manpowerinfo.dbo.ÈËʱí
OPEN mancursor1
FETCH NEXT from mancursor1
WHILE @@FETCH_STATUS=0
BEGIN
FETCH NEXT from mancursor1
END
CLOSE mancursor1
DEALLOCATE mancursor1
¹Ø±Õ²¢ÊÍ·ÅÓαê//////////////////
USE ÏúÊÛ¹ÜÀíϵͳ
GO
DECLARE mycursor CURSOR FOR
SELECT ¿Í»§È«³Æ,count(*) as ÏúÊۼǼÊý,sum(ÊýÁ¿)as ÏúÊÛÊýÁ¿ from ÏúÊÛ±í WHERE ÊýÁ¿ >100 Group BY ¿Í»§È«³Æ
OPEN mycursor
FETCH NEXT from mycursor
WHILE @@FETCH_STATUS = 0 -- ÅжÏÊÇ·ñ»¹ÓÐÐëÒª¶ÁÈ¡µÄ¼Ç¼
BEGIN
FETCH NEXT from mycursor --¶ÁÈ¡¼Ç¼µ½Óαê
END
CLOSE mycursor
DEALLOCATE mycurso
Ïà¹ØÎĵµ£º
1.Ñ¡Ôñ×îÓÐЧÂʵıíÃû˳Ðò(Ö»ÔÚ»ùÓÚ¹æÔòµÄÓÅ»¯Æ÷ÖÐÓÐЧ)¡¡¡¡
¡¡¡¡ SQLSERVERµÄ½âÎöÆ÷°´ÕÕ´ÓÓÒµ½×óµÄ˳Ðò´¦Àífrom×Ó¾äÖеıíÃû£¬Òò´Ëfrom×Ó¾äÖÐдÔÚ×îºóµÄ±í£¨»ù´¡±ídriving table£©½«±»×îÏÈ´¦Àí£¬ÔÚfrom×Ó¾äÖаüº¬¶à¸ö±íµÄÇé¿öÏ£¬±ØÐëÑ¡Ôñ¼Ç¼ÌõÊý×îÉٵıí×÷Ϊ»ù´¡±í£¬µ±SQLSERVER´¦Àí¶à¸ö±íʱ£¬»áÔËÓÃÅÅÐò¼°ºÏ²¢µÄ·½Ê½Á ......
1¡¢ÎļþºÍÎļþ×éµÄº¬ÒåÓë¹Øϵ
ÿ¸öÊý¾Ý¿âÓÐÒ»¸öÖ÷Êý¾ÝÎļþ.ºÍÈô¸É¸ö´ÓÎļþ¡£ÎļþÊÇÊý¾Ý¿âµÄÎïÀíÌåÏÖ¡£ Îļþ×é¿ÉÒÔ°üÀ¨·Ö²¼ÔÚ¶à¸öÂß¼·ÖÇøµÄÎļþ£¬ÊµÏÖ¸ºÔØƽºâ¡£Îļþ×éÔÊÐí¶ÔÎļþ½øÐзÖ×飬ÒÔ±ãÓÚ¹ÜÀíºÍÊý¾ÝµÄ·ÖÅ䣯·ÅÖá£ÀýÈ磬¿ÉÒÔ·Ö±ðÔÚÈý¸öÓ²ÅÌÇý¶¯Æ÷ÉÏ´´½¨Èý¸öÎļþ£¨Data1.ndf¡¢Data2.ndf&nb ......
¼ÙÈçÄãд¹ýºÜ¶à³ÌÐò£¬Äã¿ÉÄÜż¶û»áÅöµ½ÒªÈ·¶¨×Ö·û»ò×Ö·û´Ü´®·ñ°üº¬ÔÚÒ»¶ÎÎÄ×ÖÖУ¬ÔÚÕâƪÎÄÕÂÖУ¬ÎÒ½«ÌÖÂÛʹÓÃCHARINDEXºÍPATINDEXº¯ÊýÀ´ËÑË÷ÎÄ×ÖÁкÍ×Ö·û´®¡£ÎÒ½«¸æËßÄãÕâÁ½¸öº¯ÊýÊÇÈçºÎÔËתµÄ£¬½âÊÍËûÃǵÄÇø±ð¡£Í¬Ê±ÌṩһЩÀý×Ó£¬Í¨¹ýÕâЩÀý×Ó£¬Äã¿ÉÒÔ¿ÉÒÔ¿¼ÂÇʹÓÃÕâÁ½¸öº¯ÊýÀ´½â¾öºÜ¶à²»Í¬µÄ×Ö·ûËÑË÷µÄÎÊÌâ¡£
&nb ......
×ö¿ª·¢¹ý³ÌÖУ¬¾³£»áÓõ½½«ExcelÖÐÊý¾Ýµ¼³öµ½SQL ServerÖеÄÇé¿ö£¬Äã¿ÉÒÔÀûÓÃSQL SERVER ÖÐ×Ô´øµÄµ¼ÈëÊý¾ÝµÄ·½Ê½£¬µ«ÕâÖÖ·½Ê½£¬ÓÐʱ»á·¢ÏÖÊý¾Ýµ¼Èëºó£¬¿ÉÄÜΪ¿Õ£¬¿ÉÄÜ¿ªÍ·ÉÙ¸öÁ㣬´ËÖÖÇé¿ö¶à³öÏÖÓÚÊýÖµÐ͵ÄÁУ¬½ñÌìÔÚCSDNÉÏÏй䣬ż¶û·¢ÏÖÁËÒ»¸öÌû×Ó£¬½éÉܵÄÒÔÏÂÕâÖÖ·½·¨£¬±¾ÈËÇ¡ÆßÒò×î½ü¹«Ë¾×¼±¸ÉÏÊУ¬Éó¼Æ¾ÖÔÚ×öÉó¼Æ£¬¼¼ ......
1. SELECT
ʵÀý105
SELECT ID "±àºÅ",Name ÐÕÃû,
Math_Score 'Êýѧ³É¼¨', //ÔõôÓеÄÓÐAS,ÓеÄûÓÐ
Music_Score AS ÒôÀֳɼ¨,
English_Score AS Ó¢Îijɼ¨
f ......