Oracle dead lock deep research.
Update SQLS will lead dead lock exception. Because by default, it use optimistic lock but not pessimistic lock.
Below description is exceprted from the attachment(It exceeds my image that this blog can not upload the attachment,hehe)
Optimistic locking offers an elegant solution to the problems outlined above. Optimistic locking does
not lock records when they are read, and proceeds on the assumption that the data being updated has not
changed since the read. Since no locks are taken out during the read, it doesn’t matter if the user goes to
lunch after starting a transaction, and deadlocks are all but eliminated since users should never have to
wait on each other’s locks
There are some ways to resolve this problem.
1. Create a pessimistic lock. Change the sql like below formal.
First: select … from … for update nowait
Second: update the resultSet.
2. Execute the SQL again after a random duration when program meets this kind of exception. (It will consume lot of db server resource. I don't think it is the better way)
3. Schedule the SQL executed sequenced or split data without interfere.
Ïà¹ØÎĵµ£º
OracleÖÐto_date()Óë24Ð¡Ê±ÖÆ±íʾ·¨¼°mm·ÖÖÓµÄÏÔʾ£º
ÔÚʹÓÃOracleµÄto_dateº¯ÊýÀ´×öÈÕÆÚת»»Ê±£¬ºÜ¶àJava³ÌÐòÔ±Ò²Ðí»áºÍÎÒÒ»Ñù£¬Ö±¾õµÄ²ÉÓÓyyyy-MM-dd HH:mm:ss”µÄ¸ñʽ
×÷Ϊ¸ñʽ½øÐÐת»»£¬µ«ÊÇÔÚOracleÖлáÒýÆð´íÎ󣺓ORA 01810 ¸ñʽ´úÂë³öÏÖÁ½´Î”¡£È磺
to_date('2005-01-01 13:14:20 ......
SELECT
DECODE(ÁÐ,0,'Q'1,'P',2,'O')¡¡AS ret
from dual
--·ÖÎö: µ± ÁÐ=0ʱ,½«"Q"¸³Öµ
--µ± ÁÐ =1ʱ,½«"P"¸³Öµ
--µ± ÁÐ=2ʱ,½«"O"¸³Öµ
--NVL()º¯Êý:
--NVL(ARG,VALUE)´ï±êÈç¹ûÇ°ÃæµÄARGֵΪNULLÄÇô·µ»ØµÄֵΪºóÃæµÄVALUE¶þÕß½áºÏʹÓÃ:
DECODE(NVL(±äÁ¿ ''),'','-','OK')
//·ÖÎö:
--Èô ±äÁ¿ ÊÇ·ñΪ¿Õ.ÈôΪ¿Õ¸³¸ø¿ ......
oracle grant
ÊÚȨÓï¾ä--select * from dba_users; ²éѯÊý¾Ý¿âÖеÄËùÓÐÓû§
--alter user TEST_SELECT account lock; Ëø×¡Óû§
--alter user TEST_SELECT account unlock; ¸øÓû§½âËø
--create user xujin identified by xujin; ½¨Á¢Óû§
--grant create tablespace to xujin; ÊÚȨ
--grant select ......
Âò±¾Êé ÏÈ´Ó°²×°¿ªÊ¼°É È»ºóÂò±¾PLSQL ѧѧÓï·¨ ÕâÊÇ×î»ù±¾µÄ ½ÓÏÂÀ´¾ÍÑо¿¹ÊÕϺóÔõôÐÞ¸´ ÔÙ¾ÍÊDZ¸·Ý ÓÅ»¯ ¼¯Èº È»ºó»¹ÒªÑ§Ï°LINUX²Ù×÷ ÕâÊÇÒ»¶¨ÒªµÄ ×°WINDOWSÉϵÄORACLE²»¶à ÔÙ»¨2WÈ¥¿¼¸öOCP ¾ÍÐÐÁË
oracleµÄ¹Ù·½½Ì²ÄµÄ˳ÐòÊÇsql»ù´¡£¬½á¹¹£¬±¸·Ý»Ö¸´£¬ÐÔÄÜÓÅ»¯¡£
sqlÓï¾äµÄ»ù´¡»¹ÊǺÜÖØÒªµÄ¡£Èç¹ûÄãÏë×ö¿ª·¢pl/sqlÒ» ......
ÎÄÕÂÒ»£ºSCNÊÇʲô£¿The System Change Number
system change number (SCN)ÊÇÒ»¸ö·Ç³£ÖØÒªµÄ±ê¼Ç£¬OracleʹÓÃËüÀ´±ê¼ÇÊý¾Ý¿âÔÚ¹ýȥʱ¼äÄÚµÄ״̬ºÍ¹ì¼£¡£
OracleʹÓÃSCNÀ´±£´æËùÓб仯µÄ¹ì¼£¡£SCNÊÇÒ»¸öÂ߼ʱÖÓÀ´¼Ç¼Êý¾Ý¿âʼþ¡£Ëü·Ç³£µÄÖØÒª£¬²¢²»ÊÇÖ»ÊÇΪÁ˻ָ´¡£
SCNÓеãÀàËÆÓÚsequence£¬OracleÔÚSGAÖÐÔ ......