sql ÓαêµÄ»ù±¾Ó÷¨
1. ¶¨ÒåÓα궨Òå
ÓαêÓï¾äµÄºËÐÄÊǶ¨ÒåÁËÒ»¸öÓαê±êʶÃû£¬²¢°ÑÓαê±êʶÃûºÍÒ»¸ö²éѯÓï¾ä¹ØÁªÆðÀ´¡£DECLAREÓï¾äÓÃÓÚÉùÃ÷Óα꣬Ëüͨ¹ýSELECT²éѯ¶¨ÒåÓαê´æ´¢µÄÊý¾Ý¼¯ºÏ¡£Óï¾ä¸ñʽΪ£º
DECLARE ÓαêÃû³Æ [INSENSITIVE] [SCROLL]
CURSOR FOR selectÓï¾ä
[FOR{READ ONLY|UPDATE[OF ÁÐÃû×Ö±í]}]
²ÎÊý˵Ã÷£º
INSENSITIVEÑ¡Ï˵Ã÷Ëù¶¨ÒåµÄÓαêʹÓÃSELECTÓï¾ä²éѯ½á¹ûµÄ¿½±´£¬¶ÔÓαêµÄ²Ù×÷¶¼»ùÓڸÿ½±´½øÐС£Òò´Ë£¬ÕâÆÚ¼ä¶ÔÓαê»ù±¾±íµÄÊý¾ÝÐ޸IJ»ÄÜ·´Ó³µ½ÓαêÖС£ÕâÖÖÓαêÒ²²»ÔÊÐíͨ¹ýËüÐ޸Ļù±¾±íµÄÊý¾Ý¡£
SCROLLÑ¡Ïָ¶¨¸ÃÓαê¿ÉÓÃËùÓеÄÓαêÊý¾Ý¶¨Î»·½·¨ÌáÈ¡Êý¾Ý£¬Óα궨λ·½·¨°üÀ¨PRIOR¡¢FIRST¡¢LAST¡¢ABSOLUTE n ºÍRELATIVE n Ñ¡Ïî¡£
SelectÓï¾ä£ºÎª±ê×¼µÄSELECT²éѯÓï¾ä£¬Æä²éѯ½á¹ûΪÓαêµÄÊý¾Ý¼¯ºÏ£¬¹¹³ÉÓαêÊý¾Ý¼¯ºÏµÄÒ»¸ö»ò¶à¸ö±í³Æ×÷ÓαêµÄ»ù±í¡£
ÔÚÓαêÉùÃ÷Óï¾äÖУ¬ÓÐÏÂÁÐÌõ¼þ֮һʱ£¬ÏµÍ³×Ô¶¯°ÑÓα궨ÒåΪINSENSITIVEÓα꣺
SELECTÓï¾äÖÐʹÓÃÁËDISTINCT¡¢UNION¡¢ GROUP BY»òHAVINGµÈ¹Ø¼ü×Ö£»
ÈÎÒ»¸öÓαê»ù±íÖв»´æÔÚΨһË÷Òý¡£
ÆäËû
READ ONLYÑ¡Ï˵Ã÷¶¨ÒåÖ»¶ÁÓαꡣ
UPDATE [OF ÁÐÃû×Ö±í]Ñ¡Ï¶¨ÒåÓαê¿ÉÐ޸ĵÄÁС£Èç¹ûʹÓÃOF ÁÐÃû×Ö±íÑ¡Ï˵Ã÷Ö»ÔÊÐíÐÞ¸ÄËùÖ¸¶¨µÄÁУ¬·ñÔò£¬ËùÓÐÁоù¿ÉÐ޸ġ£
ÀýÈ磬²éѯ½ÌʦÃû×ÖºÍËù½ÌµÄ¿Î³ÌÃû£¬¶¨ÒåÓαêTCURSORµÄÓï¾äÈçÏ £º
DECLARE TCURSOR CURSOR FOR
SELECT tname, cname
from teacher ,couse
WHERE teacher.tno = couse.tno
2. ´ò¿ªÓαê
´ò¿ªÓαêÓï¾äÖ´ÐÐÓα궨ÒåÖеIJéѯÓï¾ä£¬²éѯ½á¹û´æ·ÅÔÚÓα껺³åÇøÖС£²¢Ê¹ÓαêÖ¸ÕëÖ¸ÏòÓαêÇøÖеĵÚÒ»¸öÔª×飬×÷ΪÓαêµÄȱʡ·ÃÎÊλÖᣲéѯ½á¹ûµÄÄÚÈÝÈ¡¾öÓë²éѯÓï¾äµÄÉèÖúͲéѯÌõ¼þ¡£
´ò¿ªÓαêµÄÓï¾ä¸ñʽ£º
EXEC SQL OPEN ¡´ÓαêÃû¡µ
Èç¹û´ò¿ªµÄÓαêΪINSENSITIVEÓα꣬ÔÚ´ò¿ªÊ±½«²úÉúÒ»¸öÁÙʱ±í£¬½«¶¨ÒåµÄÓαêÊý¾Ý¼¯ºÏ´ÓÆä»ù±íÖп½±´¹ýÀ´¡£
SQL ServerÖÐ,Óαê´ò¿ªºó£¬¿ÉÒÔ´ÓÈ«¾Ö±äÁ¿@@CURSOR_ROWSÖжÁÈ¡Óαê½á¹û¼¯ºÏÖеÄÐÐÊý¡£
Àý1£º´ò¿ªÇ°ÃæËù´´½¨µÄ²éѯ½ÌʦÐÕÃûºÍËù½Ì¿ÎÃû³ÆµÄÓαꡣ
OPEN tcursor
Àý2£ºÏÔʾÓαê½á¹û¼¯ºÏÖÐÊý¾ÝÐÐÊý
SELECT Êý¾ÝÐÐÊý = @@CURSOR_ROWS
3. ¶ÁÓαêÇøÖеĵ±Ç°Ôª×é
¶ÁÓαêÇøÊý¾ÝÓï¾äÊǶÁÈ¡ÓαêÇøÖе±Ç°Ôª×éµÄÖµ£¬²¢½«¸÷·ÖÁ¿ÒÀ´Î¸³¸øÖ¸¶¨µÄ¹²ÏíÖ÷±äÁ¿¡£FETCHÓï¾äÓÃÓÚ¶ÁÈ¡ÓαêÖеÄÊý¾Ý£¬Óï¾ä¸ñʽΪ£º
FETCH [[NEXT|PRIOR|FIRST|LAST| ABSOLUTE n| RELATIVE n]
from ] ÓαêÃû
[INTO @
Ïà¹ØÎĵµ£º
µ¼³ö.sqlÎļþ
1.½«Êý¾Ý¿âtransfer_server_dbµ¼³öµ½transfSRV.sqlÎļþÖУº
mysqldump -u root -p transfer_server_db > /home/eric/transfSRV.sql
2.½«Êý¾Ý¿âtransfer_server_dbÖеÄdevice_info_tableµ¼³öµ½table.sqlÎļþÖУº
mysqldump -u root -p transfer_server_db device_info_table > /home/eric/ta ......
ÈçºÎÔ¶³ÌÅжÏOracleÊý¾Ý¿âµÄ°²×°Æ½Ì¨
¡¡¡¡select * from v$version;
¡¡¡¡²é¿´±í¿Õ¼äµÄʹÓÃÇé¿ö
¡¡¡¡select sum(bytes)/(1024*1024) as free_space,tablespace_name
¡¡¡¡from dba_free_space
¡¡¡¡group by tablespace_name;
¡¡¡¡SELECT A.TABLESPACE_NAME,A.BYTES TOTAL,B.BYTES ......
//--Ìí¼Ó·þÎñÆ÷
EXEC sp_addlinkedserver
@server='LQXLSJ-600A5A60',--±»·ÃÎʵķþÎñÆ÷±ðÃû
@srvproduct='',
@provider='SQLOLEDB',
@datasrc='LQXLSJ-600A5A60' --Òª·ÃÎ ......