oracleËø
Ëø¶¨µÄ¸ÅÄËø¶¨ÊÇÊý¾Ý¿âÓÃÀ´¿ØÖƹ²Ïí×ÊÔ´²¢·¢²¼·ÃÎʵĻúÖÆ¡£ÔÚ¶àÓû§»·¾³Ï£¬¶à¸öÓû§¿Éͬʱ·ÃÎÊÏàͬµÄÊý¾Ý¡£Oracle ÌṩËøÒÔÈ·±£ÔÚ¶àÓû§»·¾³ÏÂÊý¾ÝµÄÍêÕûÐÔºÍÒ»ÖÂÐÔ¡£ÔÚÌá½»»ò»Ø¹öÊÂÎñ֮ǰ£¬Oracle »áËø¶¨Õý±»Ð޸ĵÄÊý¾Ý¡£ÔÚÓû§Íê³É»ò»Ø¹öÊÂÎñÖ®ºó£¬Ëø»á×Ô¶¯ÊÍ·Å¡£Ö»ÓÐÔÚÌá½»»ò»Ø¹öÊÂÎïÖ®ºó£¬ÆäËûÓû§²Å¿ÉÒÔ¸üÐÂÕâЩÊý¾Ý¡£
ËøµÄÁ½ÖÖ¼¶±ðΪ£ºÐм¶ËøºÍ±í¼¶Ëø¡£Ðм¶ËøÖ÷ÒªÓÃÓÚÌض¨µÄÐУ¬±í¼¶ËøÖ÷ÒªÓÃÓÚÕû¸ö±í£¬ÏÂÃæÎÒ¾ÍÐм¶ËøºÍ±í¼¶ËøÀ´¸ö˵Ã÷£º
Ðм¶Ëø
Ðм¶ËøÖ»¶ÔÓû§ÕýÔÚ·ÃÎʵÄÐнøÐÐËø¶¨¡£Èç¹û¸ÃÓû§ÕýÔÚÐÞ¸ÄijÐУ¬ÄÇôÆäËûÓû§¾Í¿ÉÒÔ¸üÐÂͬһ±íÖиÃÐÐÖ®ÍâµÄÊý¾Ý¡£ÀýÈ磺Èç¹ûÓû§1ÕýÔÚ¸üÐÂJobs ±íÖеĵÚÒ»ÐУ¬ÔòÓû§2¿ÉÒÔͬʱÐ޸ĸñíÖеĵڶþÐС£Ò²¾ÍÊÇ˵³ýÁ˸ñíÖеĵÚÒ»ÐУ¬ÆäËûÓû§¿ÉÒÔÐÞ¸ÄÈÎÒâÐУ¬µ«ÊǵÚÒ»ÐеÄÊý¾ÝÆäËûÓû§Ö»ÄÜselect¡£
Ðм¶ËøÊÇÒ»ÖÖÅÅËûËø£¬·ÀÖ¹ÆäËûÊÂÎñÐ޸ĴËÐУ¬µ«ÊDz»»á×èÖ¹¶ÁÈ¡´ËÐеIJÙ×÷¡£ÔÚʹÓÃINSERT¡¢UPDATE¡¢DELETE ºÍSELECT…FOR UPDATE µÈ Óï¾äʱ£¬Oracle »á×Ô¶¯Ó¦ÓÃÐм¶ËøËø¶¨¡£SELECT...FOR UPDATE Óï¾äÔÊÐíÓû§Ã¿´ÎÑ¡Ôñ¶àÐмǼ½øÐиüУ¬ÕâЩ¼Ç¼»á±»Ëø¶¨£¬ÇÒÖ»ÄÜÓÉ·¢Æð²éѯµÄÓû§½øÐб༡£Ö»ÓÐÔڻعö»òÌá½»ÊÂÎñÖ®ºó£¬Ëø¶¨²Å»áÊÍ·Å£¬ÆäËûÓû§²Å¿ÉÒÔ±à ¼ÕâЩ¼Ç¼¡£
SELECT...FOR UPDATE Óï¾äµÄÓï·¨ÈçÏ£º
SELECT ... FOR UPDATE [OF column_list][WAIT n|NOWAIT];
ÆäÖУº
OF ×Ó¾äÓÃÓÚÖ¸¶¨¼´½«¸üеÄÁУ¬¼´Ëø¶¨ÐÐÉϵÄÌض¨ÁС£
WAIT ×Ó¾äÖ¸¶¨µÈ´ýÆäËûÓû§ÊÍ·ÅËøµÄÃëÊý£¬·ÀÖ¹ÎÞÏÞÆڵĵȴý¡£
“ʹÓÃFOR UPDATE WAIT”×Ó¾äµÄÓŵãÈçÏ£º
¢±·ÀÖ¹ÎÞÏÞÆڵصȴý±»Ëø¶¨µÄÐУ»
¢²ÔÊÐíÓ¦ÓóÌÐòÖжÔËøµÄµÈ´ýʱ¼ä½øÐиü¶àµÄ¿ØÖÆ¡£
¢³¶ÔÓÚ½»»¥Ê½Ó¦ÓóÌÐò·Ç³£ÓÐÓã¬ÒòΪÕâЩÓû§²»Äܵȴý²»È·¶¨
¾ÙÀý£º±ÈÈçÒ»¸öÓû§ÔÚSQL PLUSÏÂÊäÈëÕâÌõÓï¾ä£ºSQL>SELECT * from order_master WHERE vencode='V002' FOR UPDATE;
´ËʱÔÙ¿ªÆôÒ»¸öSQL PLUS£¬ÒÔÏàͬµÄÓû§µÇ½£¬Ö´ÐÐÏÂÃæµÄÃüÁî¡£
SQL<> SELECT * from order_master WHERE vencode='V02' FOR UPDATE WAIT 5;
ÓÉÓÚÒª¸üеÄÐÐÒѾ±»Ëø¶¨£¬ÉÏÊöÃüÁîÔڵȴý5ÃëÖÓÖ®ºó·µ»Ø£¬²¢¸ø³öÈçϵĴíÎóÐÅÏ¢£º
ERROR λÓÚµÚ1ÐУ»
ORA-30006£»×ÊÔ´Òѱ»Õ¼Óã»Ö´ÐвÙ×÷ʱ³öÏÖWAIT³¬Ê±¡£
PS£ºÔÙ¿ªÆôµÄSQL PLUS ÊÇÒÔÏàͬÓû§µÇ½µÄ£¬ÓÃÆäËûÓû§µÇ½¸üÊDz»¿ÉÄÜ¡£
±í¼¶Ëø
±í¼¶Ëø
±í¼¶Ëø±»Ëø¶¨µÄ±í£¬ÔÝʱ·ÅÔÚÄÚ´æÖУ¬²»Ìá½»²»½øÈ¥Êý¾Ý¿â£¬Ò²¾ÍÊÇ˵£¬¶à¸öÓÃ
Ïà¹ØÎĵµ£º
¿Î³ÌÊ®Èý ʹÓÃ×éºÏÊý¾ÝÀàÐÍ* Óαê²Ù×ÝÊý¾Ý
¡¡¡¡
¡¡¡¡±¾¿ÎÖص㣺
¡¡¡¡1¡¢´´½¨Óû§×Ô¶¨ÒåµÄPLSQL¼Ç¼
¡¡¡¡2¡¢ÀûÓÃ%ROWTYPEÊôÐÔÀ´´´½¨¼Ç¼
¡¡¡¡3¡¢´´½¨PLSQL±í
¡¡¡¡4¡¢ÃèÊö¼Ç¼¡¢±í¡¢¼Ç¼µÄ±íÖ®¼äµÄÇø±ð
¡¡¡¡×¢Ò⣺ÒÔÏÂʵÀýÖбêµã¾ùΪӢÎÄ°ë½Ç
¡¡¡¡Ò»¡¢ºÏ³ÉÊý¾ÝÀàÐÍ
¡¡¡¡1¡¢ÀàÐÍ·ÖΪPLSQL¼Ç¼ºÍPLSQL±í
¡¡¡¡2¡ ......
×÷Õß: ÈýÊ®¶øÁ¢Ê±¼ä£º2009Äê11ÔÂ08ÈÕ 8:59:25Çë×ðÖØÔ´´×÷Æ·¡£×ªÔØÇë±£³ÖÎÄÕÂÍêÕûÐÔ,²¢ÒÔ³¬Á´½ÓÐÎʽעÃ÷Ôʼ×÷Õß¡°inthirties£¨ÈýÊ®¶øÁ¢£©¡±ºÍ³ö´¦¡±http://blog.csdn.net/inthirties/archive/2009/11/08/4785106.aspx¡±,ÉîÈëÌÖÂÛ¿ÉÒÔÁªÏµinthirties@gmail.com¡£ Êý¾Ý×ֵ䣬µÚÒ»´ÎÌýµ½Õâ¸ö´ÊµÄʱºò£¬»¹ÊǸոÕ̤½øITÐÐÒµ£¬ ......
×÷Õß: ÈýÊ®¶øÁ¢Ê±¼ä£º2009Äê11ÔÂ08ÈÕ 12:15:21Çë×ðÖØÔ´´×÷Æ·¡£×ªÔØÇë±£³ÖÎÄÕÂÍêÕûÐÔ,²¢ÒÔ³¬Á´½ÓÐÎʽעÃ÷Ôʼ×÷Õß¡°inthirties£¨ÈýÊ®¶øÁ¢£©¡±ºÍ³ö´¦¡±http://blog.csdn.net/inthirties/archive/2009/11/08/4786769.aspx¡±,ÉîÈëÌÖÂÛ¿ÉÒÔÁªÏµinthirties@gmail.com¡£ÔÚcsdnÉÏ¿´µ½Ò»¸öÍøÓÑÎʵÄÒ»¸öÎÊÌâ http://topic.csdn.net ......
41.SYSDATE
ÓÃÀ´µÃµ½ÏµÍ³µÄµ±Ç°ÈÕÆÚ
SQL> select to_char(sysdate,dd-mm-yyyy day) from dual;
TO_CHAR(SYSDATE,
-----------------
09-05-2004ÐÇÆÚÈÕ
trunc(date,fmt)°´ÕÕ¸ø³öµÄÒªÇó½«ÈÕÆڽضÏ,È ......