{"id":96678,"date":"2024-10-20T11:27:17","date_gmt":"2024-10-20T03:27:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/96678\/"},"modified":"2024-10-20T11:27:18","modified_gmt":"2024-10-20T03:27:18","slug":"pl-sql%ef%bc%9a%e6%af%94%e8%bc%83%e5%85%a9%e5%80%8b%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e5%b7%ae%e7%95%b0-plsql-%e5%85%a9%e5%80%8b%e6%95%b8%e6%93%9a%e5%ba%ab%e6%af%94%e8%bc%83","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/96678\/","title":{"rendered":"PL\/SQL\uff1a\u6bd4\u8f03\u5169\u500b\u6578\u64da\u5eab\u7684\u5dee\u7570 (plsql \u5169\u500b\u6578\u64da\u5eab\u6bd4\u8f03)"},"content":{"rendered":"<h1 id=\"pl-sql%ef%bc%9a%e6%af%94%e8%bc%83%e5%85%a9%e5%80%8b%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e5%b7%ae%e7%95%b0-xwMPgyOJld\">PL\/SQL\uff1a\u6bd4\u8f03\u5169\u500b\u6578\u64da\u5eab\u7684\u5dee\u7570<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u9a45\u52d5\u6642\u4ee3\uff0c\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff08DBMS\uff09\u626e\u6f14\u8457\u81f3\u95dc\u91cd\u8981\u7684\u89d2\u8272\u3002PL\/SQL\uff08Procedural Language\/Structured Query Language\uff09\u662fOracle\u6578\u64da\u5eab\u7684\u4e00\u7a2e\u7a0b\u5e8f\u8a2d\u8a08\u8a9e\u8a00\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u6578\u64da\u5eab\u7684\u958b\u767c\u548c\u7ba1\u7406\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u4f7f\u7528PL\/SQL\u6bd4\u8f03\u5169\u500b\u6578\u64da\u5eab\u7684\u5dee\u7570\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u5be6\u7528\u7684\u793a\u4f8b\u548c\u4ee3\u78bc\u7247\u6bb5\u3002<\/p>\n<h2 id=\"%e6%95%b8%e6%93%9a%e5%ba%ab%e6%af%94%e8%bc%83%e7%9a%84%e5%bf%85%e8%a6%81%e6%80%a7-xwMPgyOJld\">\u6578\u64da\u5eab\u6bd4\u8f03\u7684\u5fc5\u8981\u6027<\/h2>\n<p>\u5728\u6578\u64da\u5eab\u7ba1\u7406\u4e2d\uff0c\u7d93\u5e38\u9700\u8981\u6bd4\u8f03\u5169\u500b\u6578\u64da\u5eab\u7684\u7d50\u69cb\u548c\u6578\u64da\uff0c\u4ee5\u78ba\u4fdd\u6578\u64da\u7684\u4e00\u81f4\u6027\u548c\u5b8c\u6574\u6027\u3002\u9019\u7a2e\u6bd4\u8f03\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u4eba\u54e1\u548c\u6578\u64da\u5eab\u7ba1\u7406\u54e1\u8b58\u5225\u6578\u64da\u4e0d\u4e00\u81f4\u7684\u554f\u984c\uff0c\u4e26\u9032\u884c\u5fc5\u8981\u7684\u8abf\u6574\u3002\u5e38\u898b\u7684\u6bd4\u8f03\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u8868\u7d50\u69cb\u7684\u5dee\u7570<\/li>\n<li>\u6578\u64da\u5167\u5bb9\u7684\u5dee\u7570<\/li>\n<li>\u7d22\u5f15\u548c\u7d04\u675f\u7684\u5dee\u7570<\/li>\n<\/ul>\n<h2 id=\"%e4%bd%bf%e7%94%a8pl-sql%e9%80%b2%e8%a1%8c%e6%95%b8%e6%93%9a%e5%ba%ab%e6%af%94%e8%bc%83-xwMPgyOJld\">\u4f7f\u7528PL\/SQL\u9032\u884c\u6578\u64da\u5eab\u6bd4\u8f03<\/h2>\n<p>PL\/SQL\u63d0\u4f9b\u4e86\u5f37\u5927\u7684\u529f\u80fd\u4f86\u57f7\u884c\u6578\u64da\u5eab\u64cd\u4f5c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u4f7f\u7528PL\/SQL\u6bd4\u8f03\u5169\u500b\u6578\u64da\u5eab\u7684\u57fa\u672c\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"1-%e9%80%a3%e6%8e%a5%e5%88%b0%e6%95%b8%e6%93%9a%e5%ba%ab-xwMPgyOJld\">1. \u9023\u63a5\u5230\u6578\u64da\u5eab<\/h3>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u9023\u63a5\u5230\u8981\u6bd4\u8f03\u7684\u5169\u500b\u6578\u64da\u5eab\u3002\u9019\u53ef\u4ee5\u901a\u904e\u4f7f\u7528Oracle\u7684DBLINK\u529f\u80fd\u4f86\u5be6\u73fe\u3002\u4ee5\u4e0b\u662f\u9023\u63a5\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>CREATE DATABASE LINK db1_link\n    CONNECT TO user1 IDENTIFIED BY password1\n    USING 'db1';\n\nCREATE DATABASE LINK db2_link\n    CONNECT TO user2 IDENTIFIED BY password2\n    USING 'db2';<\/code><\/pre>\n<h3 id=\"2-%e6%af%94%e8%bc%83%e8%a1%a8%e7%b5%90%e6%a7%8b-xwMPgyOJld\">2. \u6bd4\u8f03\u8868\u7d50\u69cb<\/h3>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u53ef\u4ee5\u6bd4\u8f03\u5169\u500b\u6578\u64da\u5eab\u4e2d\u7684\u8868\u7d50\u69cb\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u793a\u4f8b\u67e5\u8a62\uff0c\u7528\u65bc\u6bd4\u8f03\u5169\u500b\u6578\u64da\u5eab\u4e2d\u67d0\u500b\u8868\u7684\u7d50\u69cb\uff1a<\/p>\n<pre><code>SELECT column_name, data_type, data_length\nFROM all_tab_columns@db1_link\nWHERE table_name = 'YOUR_TABLE_NAME'\nMINUS\nSELECT column_name, data_type, data_length\nFROM all_tab_columns@db2_link\nWHERE table_name = 'YOUR_TABLE_NAME';<\/code><\/pre>\n<p>\u9019\u6bb5\u4ee3\u78bc\u5c07\u8fd4\u56de\u5728\u7b2c\u4e00\u500b\u6578\u64da\u5eab\u4e2d\u5b58\u5728\u4f46\u5728\u7b2c\u4e8c\u500b\u6578\u64da\u5eab\u4e2d\u4e0d\u5b58\u5728\u7684\u5217\u3002<\/p>\n<h3 id=\"3-%e6%af%94%e8%bc%83%e6%95%b8%e6%93%9a%e5%85%a7%e5%ae%b9-xwMPgyOJld\">3. \u6bd4\u8f03\u6578\u64da\u5167\u5bb9<\/h3>\n<p>\u9664\u4e86\u7d50\u69cb\uff0c\u60a8\u9084\u9700\u8981\u6bd4\u8f03\u6578\u64da\u5167\u5bb9\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u793a\u4f8b\u67e5\u8a62\uff0c\u7528\u65bc\u6bd4\u8f03\u5169\u500b\u6578\u64da\u5eab\u4e2d\u67d0\u500b\u8868\u7684\u6578\u64da\uff1a<\/p>\n<pre><code>SELECT * FROM YOUR_TABLE_NAME@db1_link\nMINUS\nSELECT * FROM YOUR_TABLE_NAME@db2_link;<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de\u5728\u7b2c\u4e00\u500b\u6578\u64da\u5eab\u4e2d\u5b58\u5728\u4f46\u5728\u7b2c\u4e8c\u500b\u6578\u64da\u5eab\u4e2d\u4e0d\u5b58\u5728\u7684\u6578\u64da\u884c\u3002<\/p>\n<h3 id=\"4-%e6%af%94%e8%bc%83%e7%b4%a2%e5%bc%95%e5%92%8c%e7%b4%84%e6%9d%9f-xwMPgyOJld\">4. \u6bd4\u8f03\u7d22\u5f15\u548c\u7d04\u675f<\/h3>\n<p>\u6700\u5f8c\uff0c\u60a8\u53ef\u4ee5\u6bd4\u8f03\u7d22\u5f15\u548c\u7d04\u675f\u3002\u4ee5\u4e0b\u662f\u6bd4\u8f03\u7d22\u5f15\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>SELECT index_name\nFROM all_indexes@db1_link\nWHERE table_name = 'YOUR_TABLE_NAME'\nMINUS\nSELECT index_name\nFROM all_indexes@db2_link\nWHERE table_name = 'YOUR_TABLE_NAME';<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-xwMPgyOJld\">\u7e3d\u7d50<\/h2>\n<p>\u901a\u904e\u4f7f\u7528PL\/SQL\uff0c\u60a8\u53ef\u4ee5\u6709\u6548\u5730\u6bd4\u8f03\u5169\u500b\u6578\u64da\u5eab\u7684\u7d50\u69cb\u548c\u6578\u64da\uff0c\u5f9e\u800c\u78ba\u4fdd\u6578\u64da\u7684\u4e00\u81f4\u6027\u548c\u5b8c\u6574\u6027\u3002\u9019\u5c0d\u65bc\u6578\u64da\u5eab\u7684\u7dad\u8b77\u548c\u7ba1\u7406\u81f3\u95dc\u91cd\u8981\u3002\u7121\u8ad6\u60a8\u662f\u958b\u767c\u4eba\u54e1\u9084\u662f\u6578\u64da\u5eab\u7ba1\u7406\u54e1\uff0c\u638c\u63e1\u9019\u4e9b\u6280\u5de7\u90fd\u5c07\u5c0d\u60a8\u7684\u5de5\u4f5c\u5927\u6709\u88e8\u76ca\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u60a8\u7684\u9700\u6c42\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u670d\u52d9\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22PL\/SQL\u6280\u8853\uff0c\u5b78\u7fd2\u5982\u4f55\u6709\u6548\u6bd4\u8f03\u5169\u500b\u6578\u64da\u5eab\u7684\u5dee\u7570\uff0c\u63d0\u5347\u6578\u64da\u7ba1\u7406\u8207\u5206\u6790\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-96678","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/96678","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=96678"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/96678\/revisions"}],"predecessor-version":[{"id":96679,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/96678\/revisions\/96679"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=96678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=96678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=96678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}