{"id":160099,"date":"2024-11-03T20:16:21","date_gmt":"2024-11-03T12:16:21","guid":{"rendered":"https:\/\/server.hk\/cnblog\/160099\/"},"modified":"2024-11-03T20:16:22","modified_gmt":"2024-11-03T12:16:22","slug":"oceanbase-%e6%95%99%e7%a8%8b%ef%bc%9aoceanbase-create-sequence","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/160099\/","title":{"rendered":"OceanBase \u6559\u7a0b\uff1aOceanBase CREATE SEQUENCE"},"content":{"rendered":"<h1 id=\"oceanbase-%e6%95%99%e7%a8%8b%ef%bc%9aoceanbase-create-sequence-rzyNwteQEB\">OceanBase \u6559\u7a0b\uff1aOceanBase CREATE SEQUENCE<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\u4e2d\uff0c\u5e8f\u5217\uff08Sequence\uff09\u662f\u4e00\u500b\u975e\u5e38\u91cd\u8981\u7684\u529f\u80fd\uff0c\u7279\u5225\u662f\u5728\u9700\u8981\u751f\u6210\u552f\u4e00\u6a19\u8b58\u7b26\u7684\u60c5\u6cc1\u4e0b\u3002OceanBase \u4f5c\u70ba\u4e00\u500b\u9ad8\u6027\u80fd\u7684\u5206\u4f48\u5f0f\u6578\u64da\u5eab\uff0c\u63d0\u4f9b\u4e86 CREATE SEQUENCE \u7684\u529f\u80fd\uff0c\u8b93\u7528\u6236\u80fd\u5920\u8f15\u9b06\u5730\u5275\u5efa\u548c\u7ba1\u7406\u5e8f\u5217\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e OceanBase \u4e2d\u7684 CREATE SEQUENCE \u8a9e\u6cd5\u53ca\u5176\u4f7f\u7528\u65b9\u6cd5\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e5%ba%8f%e5%88%97%ef%bc%88sequence%ef%bc%89%ef%bc%9f-rzyNwteQEB\">\u4ec0\u9ebc\u662f\u5e8f\u5217\uff08Sequence\uff09\uff1f<\/h2>\n<p>\u5e8f\u5217\u662f\u4e00\u7a2e\u6578\u64da\u5eab\u5c0d\u8c61\uff0c\u7528\u65bc\u751f\u6210\u552f\u4e00\u7684\u6574\u6578\u503c\u3002\u9019\u4e9b\u503c\u901a\u5e38\u7528\u4f5c\u4e3b\u9375\u6216\u5176\u4ed6\u9700\u8981\u552f\u4e00\u6a19\u8b58\u7684\u5834\u666f\u3002\u5e8f\u5217\u7684\u4e3b\u8981\u7279\u9ede\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u81ea\u52d5\u589e\u9577\uff1a\u5e8f\u5217\u7684\u503c\u6703\u81ea\u52d5\u589e\u52a0\uff0c\u7121\u9700\u624b\u52d5\u5e72\u9810\u3002<\/li>\n<li>\u552f\u4e00\u6027\uff1a\u6bcf\u6b21\u751f\u6210\u7684\u503c\u90fd\u662f\u552f\u4e00\u7684\uff0c\u907f\u514d\u4e86\u91cd\u8907\u3002<\/li>\n<li>\u53ef\u914d\u7f6e\u6027\uff1a\u7528\u6236\u53ef\u4ee5\u6839\u64da\u9700\u6c42\u8a2d\u7f6e\u8d77\u59cb\u503c\u3001\u589e\u91cf\u3001\u6700\u5c0f\u503c\u548c\u6700\u5927\u503c\u7b49\u5c6c\u6027\u3002<\/li>\n<\/ul>\n<h2 id=\"oceanbase-%e4%b8%ad%e7%9a%84-create-sequence-%e8%aa%9e%e6%b3%95-rzyNwteQEB\">OceanBase \u4e2d\u7684 CREATE SEQUENCE \u8a9e\u6cd5<\/h2>\n<p>\u5728 OceanBase \u4e2d\uff0c\u5275\u5efa\u5e8f\u5217\u7684\u57fa\u672c\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>CREATE SEQUENCE sequence_name\n    [INCREMENT BY increment_value]\n    [START WITH start_value]\n    [MINVALUE min_value]\n    [MAXVALUE max_value]\n    [CYCLE | NO CYCLE]\n    [CACHE cache_size];<\/code><\/pre>\n<h3 id=\"%e5%8f%83%e6%95%b8%e8%a7%a3%e9%87%8b-rzyNwteQEB\">\u53c3\u6578\u89e3\u91cb<\/h3>\n<ul>\n<li><strong>sequence_name<\/strong>\uff1a\u5e8f\u5217\u7684\u540d\u7a31\uff0c\u5fc5\u9808\u662f\u552f\u4e00\u7684\u3002<\/li>\n<li><strong>INCREMENT BY<\/strong>\uff1a\u6bcf\u6b21\u751f\u6210\u7684\u5e8f\u5217\u503c\u7684\u589e\u91cf\uff0c\u9ed8\u8a8d\u70ba 1\u3002<\/li>\n<li><strong>START WITH<\/strong>\uff1a\u5e8f\u5217\u7684\u8d77\u59cb\u503c\uff0c\u9ed8\u8a8d\u70ba 1\u3002<\/li>\n<li><strong>MINVALUE<\/strong>\uff1a\u5e8f\u5217\u7684\u6700\u5c0f\u503c\u3002<\/li>\n<li><strong>MAXVALUE<\/strong>\uff1a\u5e8f\u5217\u7684\u6700\u5927\u503c\u3002<\/li>\n<li><strong>CYCLE<\/strong>\uff1a\u7576\u5e8f\u5217\u9054\u5230\u6700\u5927\u503c\u5f8c\uff0c\u662f\u5426\u91cd\u65b0\u5f9e\u6700\u5c0f\u503c\u958b\u59cb\uff1b<strong>NO CYCLE<\/strong> \u5247\u8868\u793a\u4e0d\u5faa\u74b0\u3002<\/li>\n<li><strong>CACHE<\/strong>\uff1a\u6307\u5b9a\u5728\u5167\u5b58\u4e2d\u9810\u5148\u751f\u6210\u7684\u5e8f\u5217\u503c\u7684\u6578\u91cf\uff0c\u4ee5\u63d0\u9ad8\u6027\u80fd\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%a4%ba%e4%be%8b%ef%bc%9a%e5%89%b5%e5%bb%ba%e4%b8%80%e5%80%8b%e5%ba%8f%e5%88%97-rzyNwteQEB\">\u793a\u4f8b\uff1a\u5275\u5efa\u4e00\u500b\u5e8f\u5217<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u5275\u5efa\u5e8f\u5217\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>CREATE SEQUENCE my_sequence\n    INCREMENT BY 1\n    START WITH 1\n    MINVALUE 1\n    MAXVALUE 1000\n    NO CYCLE\n    CACHE 10;<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u5275\u5efa\u4e86\u4e00\u500b\u540d\u70ba <code>my_sequence<\/code> \u7684\u5e8f\u5217\uff0c\u5f9e 1 \u958b\u59cb\uff0c\u6bcf\u6b21\u589e\u52a0 1\uff0c\u6700\u5927\u503c\u70ba 1000\uff0c\u4e26\u4e14\u4e0d\u6703\u5faa\u74b0\uff0c\u9084\u8a2d\u7f6e\u4e86\u7de9\u5b58\u5927\u5c0f\u70ba 10\u3002<\/p>\n<h2 id=\"%e4%bd%bf%e7%94%a8%e5%ba%8f%e5%88%97%e7%94%9f%e6%88%90%e5%80%bc-rzyNwteQEB\">\u4f7f\u7528\u5e8f\u5217\u751f\u6210\u503c<\/h2>\n<p>\u5275\u5efa\u5e8f\u5217\u5f8c\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>NEXTVAL<\/code> \u548c <code>CURRVAL<\/code> \u4f86\u7372\u53d6\u5e8f\u5217\u7684\u503c\u3002<code>NEXTVAL<\/code> \u7528\u65bc\u7372\u53d6\u4e0b\u4e00\u500b\u5e8f\u5217\u503c\uff0c\u800c <code>CURRVAL<\/code> \u7528\u65bc\u7372\u53d6\u7576\u524d\u5e8f\u5217\u503c\u3002<\/p>\n<pre><code>SELECT my_sequence.NEXTVAL FROM DUAL;<\/code><\/pre>\n<p>\u9019\u689d\u8a9e\u53e5\u5c07\u8fd4\u56de\u5e8f\u5217\u7684\u4e0b\u4e00\u500b\u503c\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c<code>CURRVAL<\/code> \u53ea\u80fd\u5728\u8abf\u7528\u904e <code>NEXTVAL<\/code> \u4e4b\u5f8c\u4f7f\u7528\u3002<\/p>\n<h2 id=\"%e5%88%aa%e9%99%a4%e5%ba%8f%e5%88%97-rzyNwteQEB\">\u522a\u9664\u5e8f\u5217<\/h2>\n<p>\u5982\u679c\u4e0d\u518d\u9700\u8981\u67d0\u500b\u5e8f\u5217\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>DROP SEQUENCE<\/code> \u8a9e\u53e5\u5c07\u5176\u522a\u9664\uff1a<\/p>\n<pre><code>DROP SEQUENCE my_sequence;<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-rzyNwteQEB\">\u7e3d\u7d50<\/h2>\n<p>OceanBase \u7684 CREATE SEQUENCE \u529f\u80fd\u70ba\u7528\u6236\u63d0\u4f9b\u4e86\u4e00\u7a2e\u7c21\u55ae\u800c\u6709\u6548\u7684\u65b9\u5f0f\u4f86\u751f\u6210\u552f\u4e00\u7684\u6574\u6578\u503c\uff0c\u9019\u5728\u8a31\u591a\u61c9\u7528\u5834\u666f\u4e2d\u90fd\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u3002\u901a\u904e\u9748\u6d3b\u7684\u53c3\u6578\u8a2d\u7f6e\uff0c\u7528\u6236\u53ef\u4ee5\u6839\u64da\u5be6\u969b\u9700\u6c42\u4f86\u914d\u7f6e\u5e8f\u5217\u7684\u884c\u70ba\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6027\u80fd\u548c\u9ad8\u53ef\u7528\u6027\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\uff0cOceanBase \u662f\u4e00\u500b\u503c\u5f97\u8003\u616e\u7684\u9078\u64c7\u3002\u5982\u679c\u60a8\u5c0d\u65bc <a href=\"https:\/\/server.hk\">\u9999\u6e2f VPS<\/a> \u6216\u5176\u4ed6 <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a> \u89e3\u6c7a\u65b9\u6848\u611f\u8208\u8da3\uff0c\u6b61\u8fce\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to create sequences in OceanBase with our comprehensive tutorial, covering syntax, examples, and best practices for efficient database management.<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-160099","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/160099","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=160099"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/160099\/revisions"}],"predecessor-version":[{"id":160100,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/160099\/revisions\/160100"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=160099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=160099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=160099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}