Ⅰ 鏁版嵁搴扑腑镄勪竴寮犺〃閲岄溃链塈D瀛楁 浣嗘湭璧嫔 镐庝箞鎻掑叆id镊澧炲 灏卞儚id瀛楁佃嚜澧炴晥鏋滀竴镙
insert into PRODUCT (浣犲缓镄勫簭鍒.NEXTVAL,PRD_DESCRIPTION) values (id,description锛
鍦ㄦ疮娆℃彃鍏ユ暟鎹镄勬椂鍊欙纴id閮戒细鎸変綘寤虹殑搴忓垪镄勫为噺镊锷ㄥ炲姞銆
sequence灏辨槸镓璋撶殑搴忓垪鍙凤纴姣忔″彇镄勬椂鍊椤畠浼氲嚜锷ㄥ炲姞锛屼竴鑸鐢ㄥ湪闇瑕佹寜
搴忓垪鍙锋帓搴忕殑鍦版柟銆
1銆 create sequence
浣犻栧厛瑕佹湁create sequence鎴栬卌reate any sequence𨱒冮檺锛
create sequence emp_sequence
INCREMENT BY 1 -- 姣忔″姞鍑犱釜
START WITH 1 -- 浠1寮濮嬭℃暟
NOMAXVALUE -- 涓嶈剧疆链澶у
NOCYCLE -- 涓鐩寸疮锷狅纴涓嶅惊鐜
CACHE 10;
涓镞﹀畾涔変简emp_sequence锛屼綘灏卞彲浠ョ敤CURRVAL锛孨EXTVAL
CURRVAL=杩斿洖sequence镄勫綋鍓嶅
NEXTVAL=澧炲姞sequence镄勫硷纴铹跺悗杩斿洖sequence鍊
姣斿傦细
emp_sequence.CURRVAL
emp_sequence.NEXTVAL
鍙浠ヤ娇鐢╯equence镄勫湴鏂癸细
- 涓嶅寘钖瀛愭煡璇銆乻napshot銆乂IEW镄 SELECT 璇鍙
- INSERT璇鍙ョ殑瀛愭煡璇涓
- NSERT璇鍙ョ殑VALUES涓
- UPDATE 镄 SET涓
鍙浠ョ湅濡备笅渚嫔瓙锛
INSERT INTO emp VALUES
(empseq.nextval, 'LEWIS', 'CLERK',7902, SYSDATE, 1200, NULL, 20);
SELECT empseq.currval FROM DUAL;
浣嗘槸瑕佹敞镒忕殑鏄锛
- 绗涓娆NEXTVAL杩斿洖镄勬槸鍒濆嫔硷绂闅忓悗镄凬EXTVAL浼氲嚜锷ㄥ炲姞浣犲畾涔夌殑INCREMENT BY鍊硷纴
铹跺悗杩斿洖澧炲姞钖庣殑鍊笺侰URRVAL 镐绘槸杩斿洖褰揿墠sequence镄勫硷纴浣嗘槸鍦ㄧ涓娆NEXTVAL
鍒濆嫔寲涔嫔悗镓嶈兘浣跨敤CURRVAL锛屽惁鍒欎细鍑洪敊銆备竴娆NEXTVAL浼氩炲姞涓娆sequence镄勫硷纴
镓浠ュ傛灉浣犲湪钖屼竴涓璇鍙ラ噷闱浣跨敤澶氢釜NEXTVAL锛屽叾鍊煎氨鏄涓崭竴镙风殑銆傛槑锏斤纻
- 濡傛灉鎸囧畾CACHE鍊硷纴oracle灏卞彲浠ラ勫厛鍦ㄥ唴瀛橀噷闱㈡斁缃涓浜泂equence锛岃繖镙峰瓨鍙栫殑蹇
浜涖
cache閲岄溃镄勫彇瀹屽悗锛宱racle镊锷ㄥ啀鍙栦竴缁勫埌cache銆 浣跨敤cache鎴栬镐细璺冲彿锛 姣斿
鏁版嵁搴撶獊铹朵笉姝e父down鎺夛纸shutdown abort),cache涓镄剆equence灏变细涓㈠け. 镓浠ュ彲
浠ュ湪create sequence镄勬椂鍊欑敤nocache阒叉㈣繖绉嶆儏鍐点
2銆 Alter sequence
浣犳垨钥呮槸璇sequence镄刼wner锛屾垨钥呮湁ALTER ANY sequence𨱒冮檺镓嶈兘鏀瑰姩sequence銆 鍙
浠alter闄start鍊间箣澶栫殑镓链塻equence鍙傛暟銆傚傛灉𨱍宠佹敼鍙荣tart鍊硷纴蹇呴’drop sequence
鍐峳e-create銆备緥瀛愶细
ALTER sequence emp_sequence
INCREMENT BY 10
MAXVALUE 10000
CYCLE -- 鍒10000钖庝粠澶村紑濮
NOCACHE;
褰卞搷sequence镄勫埯濮嫔寲鍙傛暟锛
sequence_CACHE_ENTRIES =
璁剧疆鑳藉悓镞惰玞ache镄剆equence鏁扮洰銆
鍙浠ュ緢绠鍗旷殑Drop sequence
DROP sequence order_seq;
缁撴潫
Ⅱ oracle鏁版嵁搴撴庝箞澧炲姞涓涓瀛楁电殑鍊
浣犳槸瑕乻ql璇鍙ヨ缮鏄浠涔堬纻
铹跺悗钖庨溃链変釜"+"鍜"-"鍙 锷犲彿灏辨槸澧炲姞涓鍒椾简銆傚傛灉鏄痵ql璇鍙 altertable 浣犵殑琛ㄥ悕 add 澧炲姞镄勫垪钖 Integer(澧炲姞鍒楃殑瀛楁电被鍨) 甯屾湜鑳藉府鍒颁綘锛