{"id":5043,"date":"2024-11-14T11:16:15","date_gmt":"2024-11-14T03:16:15","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5043\/"},"modified":"2024-11-14T11:16:15","modified_gmt":"2024-11-14T03:16:15","slug":"oracle%e6%80%8e%e4%b9%88%e6%9f%a5%e8%af%a2%e9%80%92%e5%bd%92","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5043\/","title":{"rendered":"oracle\u600e\u4e48\u67e5\u8be2\u9012\u5f52"},"content":{"rendered":"<blockquote><p>\n  oracle\u9012\u5f52\u67e5\u8be2\u662f\u4e00\u79cd\u5305\u542b\u81ea\u6211\u7684\u67e5\u8be2\uff0c\u53ef\u6839\u636e\u7ed3\u679c\u8fed\u4ee3\u3002\u4f7f\u7528connect by\u64cd\u4f5c\u7b26\uff0c\u6309\u5982\u4e0b\u6b65\u9aa4\u8fdb\u884c\uff1a1. \u6307\u5b9a\u8868\u548c\u5217\uff1b2. \u4f7f\u7528connect by\u5173\u8054\u7236-\u5b50\u884c\uff1b3. \u8bbe\u7f6e\u7ec8\u6b62\u6761\u4ef6\uff08\u5982level\uff09\uff1b4. \u53ef\u9009\u5730\u4f7f\u7528start with\u548cprior\u5173\u952e\u5b57\u6307\u5b9a\u904d\u5386\u8d77\u59cb\u70b9\u548c\u7236\u884c\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/21\/2024052112302159170.jpg\" class=\"aligncenter\" title=\"oracle\u600e\u4e48\u67e5\u8be2\u9012\u5f52\u63d2\u56fe\" alt=\"oracle\u600e\u4e48\u67e5\u8be2\u9012\u5f52\u63d2\u56fe\" \/><\/p>\n<p><strong>Oracle\u9012\u5f52\u67e5\u8be2<\/strong><\/p>\n<p><strong>\u4ec0\u4e48\u662f\u9012\u5f52\u67e5\u8be2\uff1f<\/strong><\/p>\n<p>\u9012\u5f52\u67e5\u8be2\u662f\u4e00\u79cd\u67e5\u8be2\uff0c\u5176\u4e2d\u67e5\u8be2\u7ed3\u679c\u5305\u542b\u67e5\u8be2\u672c\u8eab\u3002\u8fd9\u4f7f\u5f97\u67e5\u8be2\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u7ed3\u679c\u8fed\u4ee3\u3002<\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528Oracle\u8fdb\u884c\u9012\u5f52\u67e5\u8be2\uff1f<\/strong><\/p>\n<p>\u4f7f\u7528Oracle\u8fdb\u884c\u9012\u5f52\u67e5\u8be2\u9700\u8981\u4f7f\u7528CONNECT BY\u64cd\u4f5c\u7b26\u3002CONNECT BY\u64cd\u4f5c\u7b26\u5c06\u8fde\u63a5\u5177\u6709\u7279\u5b9a\u5173\u7cfb\u7684\u884c\uff0c\u521b\u5efa\u7236-\u5b50\u5c42\u6b21\u7ed3\u6784\u3002<\/p>\n<p><strong>CONNECT BY\u7684\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>SELECT \n    column_list\nFROM \n    table_name\nCONNECT BY \n    parent_column_name = child_column_name<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u540d\u4e3a&#8221;Employees&#8221;\u7684\u8868\uff0c\u5176\u4e2d\u5305\u542b\u4ee5\u4e0b\u5217\uff1a<\/p>\n<pre>ID | ManagerID | Name\n---------------------\n1   | NULL     | John Smith\n2   | 1        | Jane Doe\n3   | 2        | John Cruz\n4   | 3        | Mary Johnson<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0b\u9012\u5f52\u67e5\u8be2\u5c06\u8fd4\u56de\u6240\u6709\u5458\u5de5\u53ca\u5176\u4e0a\u7ea7\uff1a<\/p>\n<pre>SELECT \n    e1.ID, \n    e1.Name AS EmployeeName, \n    e2.Name AS ManagerName\nFROM \n    Employees e1\nCONNECT BY \n    e1.ManagerID = e2.ID<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u7ed3\u679c\uff1a<\/strong><\/p>\n<pre>ID | EmployeeName | ManagerName\n-----------------------------------\n1   | John Smith   | NULL\n2   | Jane Doe     | John Smith\n3   | John Cruz    | Jane Doe\n4   | Mary Johnson | John Cruz<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u5728\u9012\u5f52\u67e5\u8be2\u4e2d\uff0c\u5fc5\u987b\u6307\u5b9a\u4e00\u4e2a\u7ec8\u6b62\u6761\u4ef6\uff0c\u4ee5\u9632\u6b62\u67e5\u8be2\u65e0\u9650\u904d\u5386\u3002\u901a\u5e38\uff0c\u4f7f\u7528\u4e00\u4e2a\u6216\u591a\u4e2aLEVEL\u6761\u4ef6\u6765\u9650\u5236\u904d\u5386\u7684\u5c42\u6570\u3002<\/li>\n<li>CONNECT BY\u64cd\u4f5c\u7b26\u8fd8\u652f\u6301 START WITH\u548cPRIOR\u5173\u952e\u5b57\uff0c\u7528\u4e8e\u6307\u5b9a\u904d\u5386\u7684\u8d77\u59cb\u70b9\u548c\u7236\u884c\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u67e5\u8be2\u9012\u5f52\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\u9012\u5f52\u67e5\u8be2\u662f\u4e00\u79cd\u5305\u542b\u81ea\u6211\u7684\u67e5\u8be2\uff0c\u53ef\u6839\u636e\u7ed3\u679c\u8fed\u4ee3\u3002\u4f7f\u7528connect by\u64cd\u4f5c\u7b26\uff0c\u6309\u5982\u4e0b\u6b65\u9aa4\u8fdb\u884c\uff1a1. \u6307\u5b9a\u8868\u548c\u5217\uff1b2. \u4f7f\u7528connect by\u5173\u8054\u7236-\u5b50\u884c\uff1b3. \u8bbe\u7f6e\u7ec8\u6b62\u6761\u4ef6\uff08\u5982level\uff09\uff1b4. \u53ef\u9009\u5730\u4f7f\u7528start with\u548cprior\u5173\u952e\u5b57\u6307\u5b9a\u904d\u5386\u8d77\u59cb\u70b9\u548c\u7236\u884c\u3002 Oracle\u9012\u5f52\u67e5\u8be2 \u4ec0\u4e48\u662f\u9012\u5f52\u67e5\u8be2\uff1f \u9012\u5f52\u67e5\u8be2\u662f\u4e00\u79cd\u67e5\u8be2\uff0c\u5176\u4e2d\u67e5\u8be2\u7ed3\u679c\u5305\u542b\u67e5\u8be2\u672c\u8eab\u3002\u8fd9\u4f7f\u5f97\u67e5\u8be2\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u7ed3\u679c\u8fed\u4ee3\u3002 \u5982\u4f55\u4f7f\u7528Oracle\u8fdb\u884c\u9012\u5f52\u67e5\u8be2\uff1f \u4f7f\u7528Oracle\u8fdb\u884c\u9012\u5f52\u67e5\u8be2\u9700\u8981\u4f7f\u7528CONNECT BY\u64cd\u4f5c\u7b26\u3002CONNECT BY\u64cd\u4f5c\u7b26\u5c06\u8fde\u63a5\u5177\u6709\u7279\u5b9a\u5173\u7cfb\u7684\u884c\uff0c\u521b\u5efa\u7236-\u5b50\u5c42\u6b21\u7ed3\u6784\u3002 CONNECT BY\u7684\u8bed\u6cd5\uff1a SELECT column_list FROM table_name CONNECT BY parent_column_name = child_column_name \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b\uff1a \u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u540d\u4e3a&#8221;Employees&#8221;\u7684\u8868\uff0c\u5176\u4e2d\u5305\u542b\u4ee5\u4e0b\u5217\uff1a ID | ManagerID | Name &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; 1 | NULL | John Smith 2 | 1 | Jane Doe 3 | 2 | John Cruz 4 | [&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-5043","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5043","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=5043"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5043\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5043"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5043"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5043"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}