{"id":199957,"date":"2025-05-06T08:52:49","date_gmt":"2025-05-06T00:52:49","guid":{"rendered":"https:\/\/server.hk\/cnblog\/199957\/"},"modified":"2025-05-06T08:52:49","modified_gmt":"2025-05-06T00:52:49","slug":"oracle%e6%95%b0%e6%8d%ae%e5%ba%93%e5%bc%80%e5%8f%91%ef%bc%9a%e5%88%9b%e5%bb%ba%e5%ad%98%e5%82%a8%e8%bf%87%e7%a8%8b%e4%bb%a5%e6%a3%80%e6%9f%a5%e8%a1%a8%e6%98%af%e5%90%a6%e5%ad%98%e5%9c%a8","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/199957\/","title":{"rendered":"Oracle\u6570\u636e\u5e93\u5f00\u53d1\uff1a\u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\u4ee5\u68c0\u67e5\u8868\u662f\u5426\u5b58\u5728"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>Oracle\u6570\u636e\u5e93\u5f00\u53d1\uff1a\u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\u4ee5\u68c0\u67e5\u8868\u662f\u5426\u5b58\u5728<\/h1>\n<p>\u4e3b\u673a\u5b9d\u8d1d\u4eca\u5929\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u662f\u6b63\u5728\u5b66\u4e60\u6216\u8005\u5df2\u7ecf\u662f\u5927\u4f6c\u7ea7\u522b\u4e86\uff0c\u90fd\u975e\u5e38\u6b22\u8fce\u4e5f\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u7ed9\u6211\u5efa\u8bae\u8bc4\u8bba\u54c8~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff01<\/p>\n<p>\u5728Oracle\u6570\u636e\u5e93\u5f00\u53d1\u4e2d\uff0c\u7f16\u5199\u5b58\u50a8\u8fc7\u7a0b\u6765\u5224\u65ad\u8868\u662f\u5426\u5b58\u5728\u662f\u4e00\u9879\u5e38\u89c1\u7684\u4efb\u52a1\u3002\u5728\u6570\u636e\u5e93\u5f00\u53d1\u4e2d\uff0c\u5b58\u50a8\u8fc7\u7a0b\u662f\u4e00\u6bb5\u9884\u5148\u7f16\u8bd1\u7684\u4ee3\u7801\u5757\uff0c\u7528\u4e8e\u5b9e\u73b0\u7279\u5b9a\u7684\u529f\u80fd\u6216\u903b\u8f91\u3002\u901a\u8fc7\u7f16\u5199\u5b58\u50a8\u8fc7\u7a0b\u6765\u5224\u65ad\u8868\u662f\u5426\u5b58\u5728\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5bf9\u6570\u636e\u5e93\u8fdb\u884c\u7ba1\u7406\u548c\u64cd\u4f5c\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5728Oracle\u6570\u636e\u5e93\u4e2d\u7f16\u5199\u5b58\u50a8\u8fc7\u7a0b\u6765\u5224\u65ad\u8868\u662f\u5426\u5b58\u5728\uff0c\u5e76\u63d0\u4f9b\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<p>\u5728Oracle\u6570\u636e\u5e93\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u7cfb\u7edf\u8868 <code>ALL_TABLES<\/code> \u6765\u67e5\u8be2\u6570\u636e\u5e93\u4e2d\u662f\u5426\u5b58\u5728\u67d0\u5f20\u8868\u3002 <code>ALL_TABLES<\/code> \u8868\u5305\u542b\u4e86\u5f53\u524d\u7528\u6237\u53ef\u8bbf\u95ee\u7684\u6240\u6709\u8868\u7684\u4fe1\u606f\uff0c\u5176\u4e2d\u5305\u62ec\u8868\u7684\u540d\u79f0\u3001\u6240\u6709\u8005\u7b49\u3002\u901a\u8fc7\u67e5\u8be2 <code>ALL_TABLES<\/code> \u8868\uff0c\u6211\u4eec\u53ef\u4ee5\u5224\u65ad\u6307\u5b9a\u7684\u8868\u662f\u5426\u5b58\u5728\u4e8e\u6570\u636e\u5e93\u4e2d\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\u7684\u5b58\u50a8\u8fc7\u7a0b\uff0c\u7528\u4e8e\u5224\u65ad\u6307\u5b9a\u8868\u662f\u5426\u5b58\u5728\uff1a<\/p>\n<pre>CREATE OR REPLACE PROCEDURE check_table_exists (p_table_name IN VARCHAR2)\nIS\n    v_count INT;\nBEGIN\n    SELECT COUNT(*)\n    INTO v_count\n    FROM all_tables\n    WHERE table_name = p_table_name;\n\n    IF v_count &gt; 0 THEN\n        DBMS_OUTPUT.PUT_LINE('Table ' || p_table_name || ' exists in the database.');\n    ELSE\n        DBMS_OUTPUT.PUT_LINE('Table ' || p_table_name || ' does not exist in the database.');\n    END IF;\nEXCEPTION\n    WHEN NO_DATA_FOUND THEN\n        DBMS_OUTPUT.PUT_LINE('Table ' || p_table_name || ' does not exist in the database.');\n    WHEN OTHERS THEN\n        DBMS_OUTPUT.PUT_LINE('An error occurred: ' || SQLERRM);\nEND;\n\/<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a <code>check_table_exists<\/code> \u7684\u5b58\u50a8\u8fc7\u7a0b\uff0c\u8be5\u5b58\u50a8\u8fc7\u7a0b\u63a5\u53d7\u4e00\u4e2a\u8868\u540d\u4f5c\u4e3a\u8f93\u5165\u53c2\u6570\u3002\u5b58\u50a8\u8fc7\u7a0b\u9996\u5148\u67e5\u8be2 <code>ALL_TABLES<\/code> \u8868\uff0c\u7edf\u8ba1\u8868\u540d\u7b49\u4e8e\u8f93\u5165\u53c2\u6570\u7684\u8868\u7684\u6570\u91cf\uff0c\u5e76\u5c06\u7ed3\u679c\u5b58\u50a8\u5728 <code>v_count<\/code> \u53d8\u91cf\u4e2d\u3002\u7136\u540e\u6839\u636e <code>v_count<\/code> \u53d8\u91cf\u7684\u503c\u8f93\u51fa\u76f8\u5e94\u7684\u4fe1\u606f\uff0c\u5224\u65ad\u6307\u5b9a\u8868\u662f\u5426\u5b58\u5728\u3002<\/p>\n<p>\u5728\u5b58\u50a8\u8fc7\u7a0b\u7684\u4e3b\u4f53\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 <code>SELECT COUNT(*) INTO v_count FROM all_tables WHERE table_name = p_table_name;<\/code> \u8fdb\u884c\u8868\u7684\u67e5\u627e\uff0c\u5e76\u6839\u636e\u67e5\u8be2\u7ed3\u679c\u8fdb\u884c\u903b\u8f91\u5224\u65ad\u8f93\u51fa\u76f8\u5e94\u7684\u4fe1\u606f\u3002\u540c\u65f6\uff0c\u6211\u4eec\u8fd8\u5bf9\u53ef\u80fd\u53d1\u751f\u7684\u5f02\u5e38\u60c5\u51b5\u8fdb\u884c\u4e86\u5904\u7406\uff0c\u4f8b\u5982\u5f53\u8868\u4e0d\u5b58\u5728\u65f6\u6355\u83b7 <code>NO_DATA_FOUND<\/code> \u5f02\u5e38\uff0c\u5e76\u8f93\u51fa\u76f8\u5e94\u63d0\u793a\u4fe1\u606f\uff1b\u5bf9\u5176\u4ed6\u5f02\u5e38\u60c5\u51b5\u4e5f\u8fdb\u884c\u4e86\u6355\u83b7\u548c\u5904\u7406\u3002<\/p>\n<p>\u5728\u4f7f\u7528\u8fd9\u4e2a\u5b58\u50a8\u8fc7\u7a0b\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u5982\u4e0b\u65b9\u5f0f\u8c03\u7528\uff1a<\/p>\n<pre>BEGIN\n    check_table_exists('YOUR_TABLE_NAME');\nEND;<\/pre>\n<p>\u901a\u8fc7\u4e0a\u8ff0\u7684\u4ee3\u7801\u793a\u4f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u5f88\u65b9\u4fbf\u5730\u7f16\u5199\u5b58\u50a8\u8fc7\u7a0b\u6765\u5224\u65adOracle\u6570\u636e\u5e93\u4e2d\u6307\u5b9a\u7684\u8868\u662f\u5426\u5b58\u5728\u3002\u8fd9\u6837\u7684\u5b58\u50a8\u8fc7\u7a0b\u5728\u6570\u636e\u5e93\u5f00\u53d1\u4e2d\u5177\u6709\u4e00\u5b9a\u7684\u5b9e\u7528\u6027\u548c\u7075\u6d3b\u6027\uff0c\u80fd\u591f\u5e2e\u52a9\u5f00\u53d1\u4eba\u5458\u66f4\u597d\u5730\u7ba1\u7406\u548c\u64cd\u4f5c\u6570\u636e\u5e93\u3002<\/p>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300aOracle\u6570\u636e\u5e93\u5f00\u53d1\uff1a\u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\u4ee5\u68c0\u67e5\u8868\u662f\u5426\u5b58\u5728\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8eOracle,\u5b58\u50a8\u8fc7\u7a0b,\u8868\u5b58\u5728\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>Oracle\u6570\u636e\u5e93\u5f00\u53d1\uff1a\u521b\u5efa\u5b58\u50a8&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-199957","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199957","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"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=199957"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/199957\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=199957"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=199957"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=199957"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}