{"id":93772,"date":"2024-10-19T16:47:19","date_gmt":"2024-10-19T08:47:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/93772\/"},"modified":"2024-10-19T16:47:19","modified_gmt":"2024-10-19T08:47:19","slug":"oracle-10g-%e5%ba%8f%e5%88%97%e7%ae%a1%e7%90%86%e5%9f%ba%e7%a4%8e%ef%bc%9a%e5%89%b5%e5%bb%ba%e8%88%87%e4%bf%ae%e6%94%b9","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/93772\/","title":{"rendered":"Oracle 10g \u5e8f\u5217\u7ba1\u7406\u57fa\u790e\uff1a\u5275\u5efa\u8207\u4fee\u6539"},"content":{"rendered":"<h1 id=\"oracle-10g-%e5%ba%8f%e5%88%97%e7%ae%a1%e7%90%86%e5%9f%ba%e7%a4%8e%ef%bc%9a%e5%89%b5%e5%bb%ba%e8%88%87%e4%bf%ae%e6%94%b9-phKzmsxSln\">Oracle 10g \u5e8f\u5217\u7ba1\u7406\u57fa\u790e\uff1a\u5275\u5efa\u8207\u4fee\u6539<\/h1>\n<p>\u5728\u8cc7\u6599\u5eab\u7ba1\u7406\u4e2d\uff0c\u5e8f\u5217\u662f\u4e00\u7a2e\u975e\u5e38\u91cd\u8981\u7684\u7269\u4ef6\uff0c\u7279\u5225\u662f\u5728 Oracle 10g \u4e2d\u3002\u5e8f\u5217\u7528\u65bc\u751f\u6210\u552f\u4e00\u7684\u6578\u5b57\uff0c\u901a\u5e38\u7528\u65bc\u4e3b\u9375\u7684\u81ea\u52d5\u589e\u91cf\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 Oracle 10g \u4e2d\u5275\u5efa\u548c\u4fee\u6539\u5e8f\u5217\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u5be6\u7528\u7684\u7bc4\u4f8b\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e5%ba%8f%e5%88%97%ef%bc%9f-phKzmsxSln\">\u4ec0\u9ebc\u662f\u5e8f\u5217\uff1f<\/h2>\n<p>\u5e8f\u5217\u662f\u4e00\u7a2e\u6578\u64da\u5eab\u7269\u4ef6\uff0c\u7528\u65bc\u751f\u6210\u552f\u4e00\u7684\u6574\u6578\u503c\u3002\u9019\u4e9b\u503c\u901a\u5e38\u7528\u65bc\u6a19\u8b58\u8cc7\u6599\u8868\u4e2d\u7684\u884c\uff0c\u4f8b\u5982\u4e3b\u9375\u3002\u5e8f\u5217\u7684\u4e3b\u8981\u7279\u9ede\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u81ea\u52d5\u751f\u6210\uff1a\u5e8f\u5217\u53ef\u4ee5\u81ea\u52d5\u751f\u6210\u6578\u5b57\uff0c\u7121\u9700\u624b\u52d5\u63d2\u5165\u3002<\/li>\n<li>\u552f\u4e00\u6027\uff1a\u6bcf\u6b21\u751f\u6210\u7684\u6578\u5b57\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\u5e8f\u5217\u7684\u8d77\u59cb\u503c\u3001\u589e\u91cf\u3001\u6700\u5c0f\u503c\u548c\u6700\u5927\u503c\u7b49\u5c6c\u6027\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%89%b5%e5%bb%ba%e5%ba%8f%e5%88%97-phKzmsxSln\">\u5275\u5efa\u5e8f\u5217<\/h2>\n<p>\u5728 Oracle 10g \u4e2d\uff0c\u5275\u5efa\u5e8f\u5217\u7684\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>CREATE SEQUENCE sequence_name\n    START WITH start_value\n    INCREMENT BY increment_value\n    [MINVALUE min_value]\n    [MAXVALUE max_value]\n    [CYCLE | NOCYCLE]\n    [CACHE cache_size];<\/code><\/pre>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u5275\u5efa\u5e8f\u5217\u7684\u7bc4\u4f8b\uff1a<\/p>\n<pre><code>CREATE SEQUENCE employee_seq\n    START WITH 1\n    INCREMENT BY 1\n    MINVALUE 1\n    MAXVALUE 1000\n    NOCYCLE\n    CACHE 20;<\/code><\/pre>\n<p>\u5728\u9019\u500b\u7bc4\u4f8b\u4e2d\uff0c\u6211\u5011\u5275\u5efa\u4e86\u4e00\u500b\u540d\u70ba <code>employee_seq<\/code> \u7684\u5e8f\u5217\uff0c\u5f9e 1 \u958b\u59cb\uff0c\u6bcf\u6b21\u589e\u52a0 1\uff0c\u6700\u5c0f\u503c\u70ba 1\uff0c\u6700\u5927\u503c\u70ba 1000\uff0c\u4e26\u4e14\u4e0d\u6703\u5faa\u74b0\u4f7f\u7528\u5df2\u7d93\u751f\u6210\u7684\u6578\u5b57\uff0c\u4e26\u4e14\u7de9\u5b58 20 \u500b\u503c\u4ee5\u63d0\u9ad8\u6027\u80fd\u3002<\/p>\n<h2 id=\"%e4%bd%bf%e7%94%a8%e5%ba%8f%e5%88%97-phKzmsxSln\">\u4f7f\u7528\u5e8f\u5217<\/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\uff1a<\/p>\n<ul>\n<li><code>NEXTVAL<\/code>\uff1a\u8fd4\u56de\u5e8f\u5217\u7684\u4e0b\u4e00\u500b\u503c\u4e26\u81ea\u52d5\u589e\u52a0\u5e8f\u5217\u7684\u503c\u3002<\/li>\n<li><code>CURRVAL<\/code>\uff1a\u8fd4\u56de\u5e8f\u5217\u7684\u7576\u524d\u503c\uff0c\u4f46\u5fc5\u9808\u5728\u540c\u4e00\u6703\u8a71\u4e2d\u8abf\u7528 <code>NEXTVAL<\/code> \u4e4b\u5f8c\u624d\u80fd\u4f7f\u7528\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528\u5e8f\u5217\u7684\u7bc4\u4f8b\uff1a<\/p>\n<pre><code>INSERT INTO employees (id, name)\nVALUES (employee_seq.NEXTVAL, 'John Doe');<\/code><\/pre>\n<p>\u5728\u9019\u500b\u7bc4\u4f8b\u4e2d\uff0c\u6211\u5011\u5c07\u4f7f\u7528 <code>employee_seq.NEXTVAL<\/code> \u4f86\u7372\u53d6\u4e00\u500b\u65b0\u7684\u54e1\u5de5 ID\uff0c\u4e26\u63d2\u5165\u5230 <code>employees<\/code> \u8868\u4e2d\u3002<\/p>\n<h2 id=\"%e4%bf%ae%e6%94%b9%e5%ba%8f%e5%88%97-phKzmsxSln\">\u4fee\u6539\u5e8f\u5217<\/h2>\n<p>\u5982\u679c\u9700\u8981\u4fee\u6539\u5df2\u5b58\u5728\u7684\u5e8f\u5217\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>ALTER SEQUENCE<\/code> \u8a9e\u53e5\u3002\u5176\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>ALTER SEQUENCE sequence_name\n    [INCREMENT BY increment_value]\n    [MINVALUE min_value]\n    [MAXVALUE max_value]\n    [CYCLE | NOCYCLE]\n    [CACHE cache_size];<\/code><\/pre>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u4fee\u6539\u5e8f\u5217\u7684\u7bc4\u4f8b\uff1a<\/p>\n<pre><code>ALTER SEQUENCE employee_seq\n    INCREMENT BY 2\n    MAXVALUE 2000;<\/code><\/pre>\n<p>\u5728\u9019\u500b\u7bc4\u4f8b\u4e2d\uff0c\u6211\u5011\u5c07 <code>employee_seq<\/code> \u7684\u589e\u91cf\u4fee\u6539\u70ba 2\uff0c\u4e26\u5c07\u6700\u5927\u503c\u4fee\u6539\u70ba 2000\u3002<\/p>\n<h2 id=\"%e5%88%aa%e9%99%a4%e5%ba%8f%e5%88%97-phKzmsxSln\">\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\u4f86\u522a\u9664\u5b83\uff1a<\/p>\n<pre><code>DROP SEQUENCE sequence_name;<\/code><\/pre>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre><code>DROP SEQUENCE employee_seq;<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-phKzmsxSln\">\u7e3d\u7d50<\/h2>\n<p>\u5e8f\u5217\u5728 Oracle 10g \u4e2d\u662f\u4e00\u500b\u5f37\u5927\u7684\u5de5\u5177\uff0c\u7528\u65bc\u751f\u6210\u552f\u4e00\u7684\u6578\u5b57\uff0c\u7279\u5225\u662f\u5728\u8655\u7406\u4e3b\u9375\u6642\u3002\u901a\u904e\u5275\u5efa\u3001\u4f7f\u7528\u548c\u4fee\u6539\u5e8f\u5217\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u9748\u6d3b\u5730\u7ba1\u7406\u6578\u64da\u5eab\u4e2d\u7684\u6578\u64da\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u6578\u64da\u8655\u7406\u7684\u61c9\u7528\uff0c\u4e86\u89e3\u5e8f\u5217\u7684\u4f7f\u7528\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u53ef\u9760\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\u4ee5\u6eff\u8db3\u60a8\u7684\u9700\u6c42\u3002\u7121\u8ad6\u662f\u6578\u64da\u5eab\u7ba1\u7406\u9084\u662f\u5176\u4ed6\u61c9\u7528\uff0c\u6211\u5011\u7684 <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a> \u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u7a69\u5b9a\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2Oracle 10g\u5e8f\u5217\u7ba1\u7406\u7684\u57fa\u790e\u77e5\u8b58\uff0c\u5305\u62ec\u5982\u4f55\u5275\u5efa\u548c\u4fee\u6539\u5e8f\u5217\uff0c\u63d0\u5347\u6578\u64da\u5eab\u64cd\u4f5c\u6548\u7387\u3002<\/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-93772","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/93772","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=93772"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/93772\/revisions"}],"predecessor-version":[{"id":93773,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/93772\/revisions\/93773"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=93772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=93772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=93772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}