¹ØÓÚOracleµÄÐòÁУ¨Sequence£©Ê¹ÓÃ
OracleûÓÐ×Ô¶¯Ôö³¤µÄÊý¾ÝÀàÐÍ£¬ÎÒÃÇÐèÒª½¨Á¢Ò»¸ö×Ô¶¯Ôö³¤µÄÐòÁкţ¬²åÈë¼Ç¼ʱҪ°ÑÐòÁкŵÄÏÂÒ»¸öÖµ¸³ÓÚ´Ë×ֶΣ¡
create sequence type_id increment by 1 start with 1;
Õâ¾äÖУ¬type_idΪÐòÁкŵÄÃû³Æ£¬Ã¿´ÎÔö³¤Îª1£¬ÆðʼÐòºÅΪ1¡£
Èç¹ûҪɾ³ýÐòÁУ¬ÓÃdrop sequence ÐòÁÐÃû¾Í¿ÉÒÔÁË£¡£¡
ÐòÁпÉÒÔ±£Ö¤¶à¸öÓû§¶ÔͬһÕűí½øÐвÙ×÷ʱÉú³ÉΨһµÄÕûÊý,ÀûÓÃÐòÁпÉÒÔ×Ô¶¯Éú³ÉÖ÷¹Ø¼ü×Ö,ÐòÁÐÖ»´æÔÚÓÚÊý¾Ý×ÖµäÖÐ.
CREATE SEQUENCE sequence
[INCREMENT BY n]
[START WITH n]
[{MAXVALUE n|NOMAXVALUE}]
[{MINVALUE n|NOMINVALUE}]
[{CYCLE |NOCYCLE}]
[{CACHE n|NOCACHE}];
INCREMENT BY--Ö¸¶¨²½³¤
START WITH--Ö¸¶¨³õʼֵ
MAXVALUE--¶¨ÒåÐòÁÐÉú³ÉµÄ×î´ó±àºÅ.ĬÈϵÄMAXVALUE¾ÍÊÇNOMAXVALUE,¶ÔÓÚµÝÔöÐòÁÐΪ10^27,¶ÔÓڵݼõÐòÁÐΪ-1
MINVALUE--¶¨ÒåÐòÁеÄ×îС±àºÅ,ĬÈϵÄMINVALUEΪNOMINVALUE,¶ÔÓÚµÝÔöÐòÁÐΪ1,µÝ¼õÐòÁÐΪ-10^26.
CYCLE--ÅäÖÃÐòÁÐÔÚ´ïµ½½çÏÞֵʱÖظ´±àºÅ
NOCYCLE--´ïµ½½çÏÞֵʱ²»Öظ´±àºÅ,ÕâÊÇĬÈÏÖµ,µ±ÄãÊÔͼÉú³ÉMAXVALUE+1ʱ½«·µ»ØÒì³£.
CACHE--¶¨ÒåÔÚÄÚ´æÖб£ÁôµÄÐòÁбàºÅ¿éµÄ´óС,ĬÈÏֵΪ20.
NOCACHE--Ç¿ÖÆÊý¾Ý´Êµä¶ÔÓÚÉú³ÉµÄÿ¸öÐòÁбàºÅ½øÐиüÐÂ,±£Ö¤ÔÚÉú³ÉµÄ±àºÅÖÐûÓпÕȱ,µ«ÕâÑù»á½µµÍÐÔÄÜ.
Éú³ÉÒ»¸öÐòÁÐ
CREATE SEQUENCE dept_deptid_seq
INCREAMENT BY 10
START WITH 120
MAXVALUE 9999
NOCACHE
NOCYCLE;
//Èç¹ûÊÇÓÃÀ´Éú³ÉÖ÷¼üÖµµÄ»°,²»ÒªÓÃCYCLEÑ¡Ïî,¶øÇÒÃüÃûÐòÁÐʱ×îºÃÄÜÌåÏÖËüµÄDZÔÚÓÃ;ÒÔ±ãÓÚÀí½â.
È·ÈÏÐòÁÐ
SELECT sequence_name,min_value,max_value,increament_by,last_number
from user_sequences;
//Èç¹ûÄãÖ¸¶¨ÁËNOCACHEÑ¡Ïî,ÄÇôLAST_NUMBERÁн«ÏÔʾÏÂÒ»¿ÉÓõÄÐòÁкÅ.
ʹÓÃNEXTVAL¿ÉÒÔ·ÃÎÊÐòÁÐÖеÄÏÂÒ»¸ö±àºÅ,µ«ÎÊÌâ³£³£³öÏÖÔڻỰ³õʼÐòÁÐ֮ǰ²éѯÆ䵱ǰÐòÁкÅCURRVAL
CREATE SEQUENCE emp_seq
NOMAXVALUE
NOCYCLE;
È»ºó²éѯ
SELECT emp_seq.currval
from dual;
½«·µ»Ø´íÎó,ÎÊÌâ¾ÍÔÚÓÚÄãÊÓͼÒýÓÃCURRVAL֮ǰ,ÔÚÄãµÄ»á»°Öв¢Ã»ÓÐʹÓÃNEXTVALÏȳõʼ»¯´ËÐòÁÐ.
SELECT emp_seq.nextval
from dual;
ÕâÑùÔÙ²éѯCURRVAL¾Í²»»á³ö´íÁË.
ʹÓÃÐòÁÐ
INSERT INTO departments(department_id,department_name,location_id)
VALUES (dept_deptid_seq.NEXTVAL,'Support',2500);
¶ÔÐòÁнøÐлº³å´æ´¢¿ÉÒÔÌá¸ßÐÔÄÜ,ÒòΪÕâÑù¾Í²»±Ø¶Ôÿ¸öÉú³ÉµÄ±àºÅ¶¼¸üÐÂÊý¾Ý×Öµä±í,Ö»ÐèÒª¶Ôÿһ×é±àºÅ½øÐиüÐ
Ïà¹ØÎĵµ£º
oracle±í¿Õ¼ä²Ù×÷Ïê½â
1
2
3×÷Õߣº À´Ô´£º ¸üÐÂÈÕÆÚ£º2006-01-04
5
6
7½¨Á¢±í¿Õ¼ä
8
9CREATE TABLESPACE data01
10DATAFILE '/ora ......
1. ASCII
·µ»ØÓëÖ¸¶¨µÄ×Ö·û¶ÔÓ¦µÄÊ®½øÖÆÊý;
SQL> select ascii(A) A,ascii(a) a,ascii(0) zero,ascii( ) space from dual;
A A ZERO SPACE
--------- --------- --------- ---------
65 97 48 32
2. CHR
¸ø³öÕûÊý,·µ»Ø¶ÔÓ¦µÄ×Ö·û;
SQL> select chr(54740) zhao,chr(65) chr65 from dual;
ZH ......
1. ASCII: ·µ»ØÓëÖ¸¶¨µÄ×Ö·û¶ÔÓ¦µÄÊ®½øÖÆÊý;
SQL> select ascii('A') A,ascii('a') a,ascii(0) zero,ascii('') space from dual;
A A ZERO SPACE
--------- --------- --------- ---------
65 97 48
2. CHR:¸ø³öÕûÊý,·µ»Ø¶ÔÓ¦µÄ×Ö·û;
SQ ......
¹Ø¼ü×Ö: oracle job ¼ä¸ôʱ¼ä trunc
¼ÙÉèÄãµÄ´æ´¢¹ý³ÌÃûΪPROC_RAIN_JM
ÔÙдһ¸ö´æ´¢¹ý³ÌÃûΪPROC_JOB_RAIN_JM
ÄÚÈÝÊÇ£º
Create Or Replace Procedure PROC_JOB_RAIN_JM Is li_jobno Number; &nb ......
ÏÂÎçÈ¥²Î¼ÓÒ»¸öOracleÓйغ£Á¿Êý¾Ý´æ´¢¼¼ÊõµÄÅàѵ½²×ùÁË¡£
µØÖ·ÔÚ¹ãÖÝÊÐÁÖºÍÎ÷·101ºÅÌìºÓÇø¼Æ¾´óÂ¥Î÷²àÈýÂ¥¡£
Åàѵ·¢Æð»ú¹¹Îª£º¹ãÖÝÖÐî£ÐÅÏ¢¼¼ÊõÓÐÏÞ¹«Ë¾¡£
ÏÂÃæ¾Í¼òÒª×ܽáÒ»ÏÂËùÌýµ½µÄһЩ¶«Î÷£¬Ò²ËãÊÇѧµ½µÄÕâЩ¼¼Êõ¡£²»¹ýÓеĶ«Î÷²»ÖªµÀ×ܽáµÄ¶Ô²»¶Ô£¬ÔÝÇÒàñàðÍÌÔæ°É¡£
OracleµÄ´æ´¢¼¼Êõ
´óÌåÉÏ· ......