{"id":5017,"date":"2024-11-14T11:37:09","date_gmt":"2024-11-14T03:37:09","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5017\/"},"modified":"2024-11-14T11:37:09","modified_gmt":"2024-11-14T03:37:09","slug":"oracle%e6%80%8e%e4%b9%88%e8%ae%be%e7%bd%ae%e8%87%aa%e5%a2%9e%e5%ba%8f%e5%88%97","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5017\/","title":{"rendered":"oracle\u600e\u4e48\u8bbe\u7f6e\u81ea\u589e\u5e8f\u5217"},"content":{"rendered":"<blockquote><p>\n  oracle \u81ea\u589e\u5e8f\u5217\u7528\u4e8e\u751f\u6210\u552f\u4e00\u9012\u589e\u7684\u6570\u5b57\uff0c\u4ee5\u6807\u8bc6\u6570\u636e\u5e93\u8bb0\u5f55\u3002\u8bbe\u7f6e\u6b65\u9aa4\u5982\u4e0b\uff1a\u521b\u5efa\u5e8f\u5217\uff1acreate sequence sequence_name start with start_value increment by increment_value cache size;\u5728\u8868\u4e2d\u63d2\u5165\u65b0\u8bb0\u5f55\uff1ainsert into table_name (id_column) values (sequence_name.nextval);\u5220\u9664\u5e8f\u5217\uff1adrop sequence sequence_name;\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/21\/2024052110512179711.jpg\" class=\"aligncenter\" title=\"oracle\u600e\u4e48\u8bbe\u7f6e\u81ea\u589e\u5e8f\u5217\u63d2\u56fe\" alt=\"oracle\u600e\u4e48\u8bbe\u7f6e\u81ea\u589e\u5e8f\u5217\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u8bbe\u7f6e Oracle \u4e2d\u7684\u81ea\u589e\u5e8f\u5217<\/strong><\/p>\n<p>Oracle \u4e2d\u7684\u81ea\u589e\u5e8f\u5217\u662f\u4e00\u79cd\u7279\u6b8a\u7c7b\u578b\u7684\u6570\u636e\u5bf9\u8c61\uff0c\u53ef\u7528\u4e8e\u751f\u6210\u552f\u4e00\u4e14\u6309\u987a\u5e8f\u9012\u589e\u7684\u6570\u5b57\u3002\u8fd9\u5bf9\u4e8e\u6807\u8bc6\u6570\u636e\u5e93\u8868\u4e2d\u7684\u8bb0\u5f55\u975e\u5e38\u6709\u7528\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u521b\u5efa\u4e00\u4e2a\u81ea\u589e\u5e8f\u5217\uff1a<\/p>\n<p><strong>1. \u521b\u5efa\u5e8f\u5217<\/strong><\/p>\n<pre>CREATE SEQUENCE sequence_name\nSTART WITH start_value\nINCREMENT BY increment_value\n[CACHE size]\n[NOORDER]\n[NOMINVALUE]\n[CYCLE];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li> <strong>sequence_name\uff1a<\/strong>\u5e8f\u5217\u7684\u540d\u79f0\u3002<\/li>\n<li> <strong>start_value\uff1a<\/strong>\u5e8f\u5217\u5f00\u59cb\u7684\u503c\u3002<\/li>\n<li> <strong>increment_value\uff1a<\/strong>\u6bcf\u6b21\u8c03\u7528\u5e8f\u5217\u65f6\u81ea\u589e\u7684\u91cf\u3002\u9ed8\u8ba4\u503c\u4e3a 1\u3002<\/li>\n<li> <strong>CACHE size\uff1a<\/strong>\u6307\u5b9a\u8981\u7f13\u5b58\u5728\u5185\u5b58\u4e2d\u7684\u5e8f\u5217\u503c\u7684\u6570\u91cf\u3002<\/li>\n<li> <strong>NOORDER\uff1a<\/strong>\u7981\u7528\u6309\u5e8f\u751f\u6210\u5e8f\u5217\u503c\u3002\u8fd9\u53ef\u4ee5\u63d0\u9ad8\u6027\u80fd\uff0c\u4f46\u5b83\u4e0d\u518d\u662f\u4e25\u683c\u9012\u589e\u7684\u3002<\/li>\n<li> <strong>NOMINVALUE\uff1a<\/strong>\u6307\u5b9a\u5e8f\u5217\u6ca1\u6709\u6700\u5c0f\u503c\u3002<\/li>\n<li> <strong>CYCLE\uff1a<\/strong>\u5141\u8bb8\u5e8f\u5217\u5728\u8fbe\u5230\u6700\u5927\u503c\u540e\u91cd\u65b0\u5f00\u59cb\u4ece\u5f00\u59cb\u503c\u9012\u589e\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>CREATE SEQUENCE customer_id_seq\nSTART WITH 1\nINCREMENT BY 1\nCACHE 10;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a &#8220;customer_id_seq&#8221; \u7684\u81ea\u589e\u5e8f\u5217\uff0c\u4ece 1 \u5f00\u59cb\uff0c\u6bcf\u6b21\u8c03\u7528\u65f6\u9012\u589e 1\uff0c\u5e76\u5728\u5185\u5b58\u4e2d\u7f13\u5b58 10 \u4e2a\u503c\u3002<\/p>\n<p><strong>2. \u4f7f\u7528\u5e8f\u5217<\/strong><\/p>\n<p>\u5728\u8868\u4e2d\u63d2\u5165\u65b0\u8bb0\u5f55\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5e8f\u5217\u6765\u751f\u6210\u552f\u4e00\u4e14\u9012\u589e\u7684 ID\uff1a<\/p>\n<pre>INSERT INTO table_name (id_column) VALUES (sequence_name.NEXTVAL);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>INSERT INTO customers (id, name) VALUES (customer_id_seq.NEXTVAL, 'John Doe');<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u5411 &#8220;customers&#8221; \u8868\u4e2d\u63d2\u5165\u4e00\u4e2a\u65b0\u8bb0\u5f55\uff0c\u5176\u4e2d &#8220;id&#8221; \u5217\u7684\u503c\u7531 &#8220;customer_id_seq&#8221; \u5e8f\u5217\u751f\u6210\u3002<\/p>\n<p><strong>3. \u5220\u9664\u5e8f\u5217<\/strong><\/p>\n<p>\u4e0d\u518d\u9700\u8981\u5e8f\u5217\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\u5c06\u5176\u5220\u9664\uff1a<\/p>\n<pre>DROP SEQUENCE sequence_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>DROP SEQUENCE customer_id_seq;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u8bbe\u7f6e\u81ea\u589e\u5e8f\u5217\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>oracle \u81ea\u589e\u5e8f\u5217\u7528\u4e8e\u751f\u6210\u552f\u4e00\u9012\u589e\u7684\u6570\u5b57\uff0c\u4ee5\u6807\u8bc6\u6570\u636e\u5e93\u8bb0\u5f55\u3002\u8bbe\u7f6e\u6b65\u9aa4\u5982\u4e0b\uff1a\u521b\u5efa\u5e8f\u5217\uff1acreate sequence sequence_name start with start_value increment by increment_value cache size;\u5728\u8868\u4e2d\u63d2\u5165\u65b0\u8bb0\u5f55\uff1ainsert into table_name (id_column) values (sequence_name.nextval);\u5220\u9664\u5e8f\u5217\uff1adrop sequence sequence_name; \u5982\u4f55\u8bbe\u7f6e Oracle \u4e2d\u7684\u81ea\u589e\u5e8f\u5217 Oracle \u4e2d\u7684\u81ea\u589e\u5e8f\u5217\u662f\u4e00\u79cd\u7279\u6b8a\u7c7b\u578b\u7684\u6570\u636e\u5bf9\u8c61\uff0c\u53ef\u7528\u4e8e\u751f\u6210\u552f\u4e00\u4e14\u6309\u987a\u5e8f\u9012\u589e\u7684\u6570\u5b57\u3002\u8fd9\u5bf9\u4e8e\u6807\u8bc6\u6570\u636e\u5e93\u8868\u4e2d\u7684\u8bb0\u5f55\u975e\u5e38\u6709\u7528\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u521b\u5efa\u4e00\u4e2a\u81ea\u589e\u5e8f\u5217\uff1a 1. \u521b\u5efa\u5e8f\u5217 CREATE SEQUENCE sequence_name START WITH start_value INCREMENT BY increment_value [CACHE size] [NOORDER] [NOMINVALUE] [CYCLE]; \u767b\u5f55\u540e\u590d\u5236 sequence_name\uff1a\u5e8f\u5217\u7684\u540d\u79f0\u3002 start_value\uff1a\u5e8f\u5217\u5f00\u59cb\u7684\u503c\u3002 increment_value\uff1a\u6bcf\u6b21\u8c03\u7528\u5e8f\u5217\u65f6\u81ea\u589e\u7684\u91cf\u3002\u9ed8\u8ba4\u503c\u4e3a 1\u3002 CACHE size\uff1a\u6307\u5b9a\u8981\u7f13\u5b58\u5728\u5185\u5b58\u4e2d\u7684\u5e8f\u5217\u503c\u7684\u6570\u91cf\u3002 NOORDER\uff1a\u7981\u7528\u6309\u5e8f\u751f\u6210\u5e8f\u5217\u503c\u3002\u8fd9\u53ef\u4ee5\u63d0\u9ad8\u6027\u80fd\uff0c\u4f46\u5b83\u4e0d\u518d\u662f\u4e25\u683c\u9012\u589e\u7684\u3002 NOMINVALUE\uff1a\u6307\u5b9a\u5e8f\u5217\u6ca1\u6709\u6700\u5c0f\u503c\u3002 CYCLE\uff1a\u5141\u8bb8\u5e8f\u5217\u5728\u8fbe\u5230\u6700\u5927\u503c\u540e\u91cd\u65b0\u5f00\u59cb\u4ece\u5f00\u59cb\u503c\u9012\u589e\u3002 \u793a\u4f8b\uff1a CREATE SEQUENCE customer_id_seq START [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5017","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5017","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=5017"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5017\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5017"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5017"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5017"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}