{"id":108,"date":"2010-12-28T23:22:01","date_gmt":"2010-12-28T15:22:01","guid":{"rendered":"http:\/\/www.royalwzy.com\/?p=108"},"modified":"2013-12-30T10:58:18","modified_gmt":"2013-12-30T02:58:18","slug":"create-sequence-command","status":"publish","type":"post","link":"http:\/\/www.royalwzy.com\/?p=108","title":{"rendered":"CREATE SEQUENCE command"},"content":{"rendered":"<p style=\"color: #333333; font-family: Arial; font-size: 14px; font-style: normal; font-variant: normal;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span style=\"font-weight: bold;\">PURPOSE:<\/span><\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 To create a sequence. A sequence is a database object from which multiple users may generate unique integers. You can use sequences to automatically generate primary key values.<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span style=\"font-weight: bold;\">SYNTAX:<\/span><\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">CREATE SEQUENCE [schema.]sequence<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 [INCREMENT BY integer]<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 [START WITH integer]<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 [MAXVALUE integer | NOMAXVALUE]<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 [MINVALUE integer | NOMINVALUE]<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 [CYCLE | NOCYCLE]<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 [CACHE integer | NOCACHE]<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 [ORDER | NOORDER]<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt; font-weight: bold;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">where:<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt; font-weight: bold;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">schema<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 is the schema to contain the sequence. If you omit schema, Oracle creates the sequence in your own schema.<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span style=\"font-weight: bold;\">sequence<\/span><\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 is the name of the sequence to be created.<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span style=\"font-weight: bold;\">INCREMENT BY<\/span><\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 specifies the interval between sequence numbers. This value can be any positive or negative Oracle integer, but it cannot be 0. If this value is negative, then the sequence descends. If the increment is positive, then the sequence ascends. If you omit this clause, the interval defaults to 1.<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span style=\"font-weight: bold;\">MINVALUE<\/span><\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 specifies the sequence&#8217;s minimum value.<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span style=\"font-weight: bold;\">NOMINVALUE<\/span><\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 specifies a minimum value of 1 for an ascending sequence or -10 for a descending sequence.<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 The default is NOMINVALUE.<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt; font-weight: bold;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt; font-weight: bold;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">MAXVALUE<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 specifies the maximum value the sequence can generate.<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span style=\"font-weight: bold;\">NOMAXVALUE<\/span><\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 specifies a maximum value of 10 for a descending sequence.<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"en-US\">\u00a0\u00a0\u00a0\u00a0<\/span><span lang=\"zh-CN\">The default is NOMAXVALUE.<\/span><\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt; font-weight: bold;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt; font-weight: bold;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">START WITH<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 specifies the first sequence number to be generated. You can use this option to start an ascending sequence at a value greater than its minimum or to start a descending sequence at a value less than its maximum. For ascending sequences, the default value is the sequence&#8217;s minimum value. For descending sequences, the default value is the sequence&#8217;s maximum value.<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span style=\"font-weight: bold;\">CYCLE<\/span><\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 specifies that the sequence continues to generate values after reaching either its maximum or minimum value. After an ascending sequence reaches its maximum value, it generates its minimum value. After a descending sequence reaches its minimum, it generates its maximum.<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span style=\"font-weight: bold;\">NOCYCLE<\/span><\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 specifies that the sequence cannot generate more values after reaching its maximum or minimum value.<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 The default is NOCYCLE.<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span style=\"font-weight: bold;\">CACHE<\/span><\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 specifies how many values of the sequence Oracle preallocates and keeps in memory for faster access. The minimum value for this parameter is 2. For sequences that cycle, this value must be less than the number of values in the cycle.<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt; font-weight: bold;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span style=\"font-weight: bold;\">NOCACHE<\/span><\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 specifies that values of the sequence are not preallocated. If you omit both the CACHE parameter and the NOCACHE option, Oracle caches 20 sequence numbers by default. However, if you are using Oracle with the Parallel Server option in parallel mode and you specify the ORDER option, sequence values are never cached, regardless of whether you specify the CACHE parameter or the NOCACHE option.<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt; font-weight: bold;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">ORDER<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"zh-CN\">\u00a0\u00a0\u00a0<\/span><span lang=\"en-US\">\u00a0guarantees that sequence numbers are generated in order of request. You may want to use this option if you are using the sequence numbers as timestamps. Guaranteeing order is usually not important for sequences used to generate primary keys.<\/span><\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt; font-weight: bold;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">NOORDER<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"zh-CN\">\u00a0\u00a0\u00a0<\/span><span lang=\"zh-CN\">\u00a0does not guarantee sequence numbers are generated in order of\u00a0<\/span><span lang=\"en-US\">request. If you omit both the ORDER and NOORDER options, Oracle chooses NOORDER by default. Note that the ORDER option is only necessary to guarantee ordered generation if you are using Oracle with the\u00a0<\/span><span lang=\"zh-CN\">Parallel Server option in parallel mode. If you are using exclusive mode, sequence numbers are always generated in order.<\/span><\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\">\u00a0<\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span style=\"font-weight: bold;\">PREREQUISITES:<\/span><\/span><\/span><\/p>\n<p style=\"font-family: Arial; font-style: normal; font-variant: normal; margin: 0in; color: black; font-size: 10pt;\"><span style=\"font-family: 'courier new', courier;\"><span style=\"font-size: small;\"><span lang=\"zh-CN\">\u00a0\u00a0\u00a0<\/span><span lang=\"en-US\">\u00a0To create a sequence in your own schema, you must have CREATE SEQUENCE privilege. To create a sequence in another user&#8217;s schema, you must have CREATE ANY SEQUENCE privilege. If you are using Trusted Oracle in DBMS MAC mode, your DBMS label must dominate the creation label of the owner of the schema to contain the sequence.<\/span><\/span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PURPOSE: \u00a0\u00a0\u00a0 To create a sequence. A sequence is a data [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[34,2],"class_list":["post-108","post","type-post","status-publish","format-standard","hentry","category-oracle","tag-oracle","tag-oracle_basics"],"_links":{"self":[{"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/posts\/108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=108"}],"version-history":[{"count":0,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=\/wp\/v2\/posts\/108\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=108"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.royalwzy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}