{"id":4257,"date":"2021-03-08T20:22:29","date_gmt":"2021-03-08T12:22:29","guid":{"rendered":"http:\/\/pipingpig.com\/index.php\/2021\/03\/08\/smart3d-0140\/"},"modified":"2026-08-20T18:19:52","modified_gmt":"2026-08-20T10:19:52","slug":"smart3d-0140","status":"publish","type":"post","link":"https:\/\/www.pipingpig.com\/index.php\/2021\/03\/08\/smart3d-0140\/","title":{"rendered":"SQL Query to Return System Parent at Any Depth"},"content":{"rendered":"<div class=\"content\">\n<p style=\"text-align: center\">x x x x x x x x x<\/p>\n<p style=\"text-align: center\">x\u00a0x x x x x x x x<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" class=\"rich_pages\" data-ratio=\"0.3410931174089069\" data-s=\"300,640\" data-src=\"https:\/\/www.pipingpig.com\/wp-content\/uploads\/2026\/08\/0140_img_0000.png\" data-type=\"png\" data-w=\"988\" src=\"https:\/\/www.pipingpig.com\/wp-content\/uploads\/2026\/08\/0140_img_0000.png\" \/><\/p>\n<p style=\"text-align: center\">x x x x x x x x x<\/p>\n<p>SQL Query to Return System Parent at Any Depth<\/p>\n<p>SQL\u00a0\u67e5\u8be2\u51fa\u5bf9\u8c61\u7684\u4efb\u610f\u5c42\u7ea7\u6df1\u5ea6\u7684\u7236\u7ea7<\/p>\n<p style=\"text-align: center\">x x x x x x<\/p>\n<p>Issue<\/p>\n<p>Query to return the name of a parent object on the Systemhierarchy of a specific object type given the OID of a child object of aspecific object type. The depth of the child below the parent is unknown andmay vary within the model.<\/p>\n<p>\u00a0\u5728\u5f97\u5230\u67d0\u4e00\u79cd\u5bf9\u8c61\u7684oid\u4e4b\u540e\uff0c\u4f7f\u7528sql\u67e5\u8be2\u8fd4\u56de\u5bf9\u8c61\u7684\u4efb\u4e00\u79cd\u7236\u7ea7\u5bf9\u8c61\u7684\u540d\u5b57\u3002\u5b50\u7ea7\u5bf9\u8c61\u4e0e\u7236\u7ea7\u5bf9\u8c61\u7684\u76f8\u5bf9\u6df1\u5ea6\u5728\u9879\u76ee\u6a21\u578b\u4e2d\u4e0d\u4e00\u5b9a\u3002<\/p>\n<p>Environment<\/p>\n<p>Not version specific<\/p>\n<p>\u00a0<\/p>\n<p>Resolution<\/p>\n<p>\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<p>Since the child&#8217;s depth below the parent is variable, thesolution requires a SQL query using the function REPORTGetAllParentsInHierarchyfor SQL databases or RPTAllParentsInHierarchy for Oracle databases. The examplebelow returns the name of the parent equipment of a child shape.<\/p>\n<p>\u00a0<\/p>\n<p>For SQL databases:<\/p>\n<p>\u00a0\u9002\u7528\u4e8eSQL\u6570\u636e\u5e93\u5e73\u53f0\uff1a<\/p>\n<p>select<\/p>\n<p>j2.oid ShapeOID,<\/p>\n<p>j2.ItemName ShapeName,<\/p>\n<p>j4.oid EquipOID,<\/p>\n<p>j4.ItemName EquipName<\/p>\n<p>from JPrimitiveShape j1<\/p>\n<p>join JNamedItem j2 on j2.Oid = j1.Oid<\/p>\n<p>cross applydbo.REPORTGetAllParentsInHierarchy(j1.Oid,&#8217;SystemHierarchy&#8217;) s1<\/p>\n<p>join JSmartEquipmentOcc j3 on j3.Oid = s1.oidParent<\/p>\n<p>join JNamedItem j4 on j4.Oid = j3.Oid<\/p>\n<p>\u00a0<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" class=\"rich_pages\" data-ratio=\"0.46826222684703434\" data-s=\"300,640\" data-src=\"https:\/\/www.pipingpig.com\/wp-content\/uploads\/2026\/08\/0140_img_0001.png\" data-type=\"png\" data-w=\"961\" src=\"https:\/\/www.pipingpig.com\/wp-content\/uploads\/2026\/08\/0140_img_0001.png\" \/><\/p>\n<p>For Oracle databases:<\/p>\n<p>\u00a0\u9002\u7528\u4e8eOracel\u6570\u636e\u5e93\u5e73\u53f0\u3002<\/p>\n<p>select<\/p>\n<p>j2.oid ShapeOID,<\/p>\n<p>j2.ItemName ShapeName,<\/p>\n<p>j4.oid EquipOID,<\/p>\n<p>j4.ItemName EquipName<\/p>\n<p>from JPrimitiveShape j1<\/p>\n<p>join JNamedItem j2 on j2.Oid = j1.Oid<\/p>\n<p>cross joinTABLE(RPTAllParentsInHierarchy(j1.Oid,&#8217;SystemHierarchy&#8217;)) s1<\/p>\n<p>join JSmartEquipmentOcc j3 on j3.Oid = s1.oidParent<\/p>\n<p>join JNamedItem j4 on j4.Oid = j3.Oid<\/p>\n<p>\u00a0<\/p>\n<p>Cause<\/p>\n<p>Informational<\/p>\n<p><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>x x x x x x x x x x\u00a0x x x x x x x x x x x x x x x x x S [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4255,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[9,10],"tags":[],"class_list":["post-4257","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-smart3d","category-10"],"_links":{"self":[{"href":"https:\/\/www.pipingpig.com\/index.php\/wp-json\/wp\/v2\/posts\/4257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pipingpig.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pipingpig.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pipingpig.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pipingpig.com\/index.php\/wp-json\/wp\/v2\/comments?post=4257"}],"version-history":[{"count":3,"href":"https:\/\/www.pipingpig.com\/index.php\/wp-json\/wp\/v2\/posts\/4257\/revisions"}],"predecessor-version":[{"id":7907,"href":"https:\/\/www.pipingpig.com\/index.php\/wp-json\/wp\/v2\/posts\/4257\/revisions\/7907"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pipingpig.com\/index.php\/wp-json\/wp\/v2\/media\/4255"}],"wp:attachment":[{"href":"https:\/\/www.pipingpig.com\/index.php\/wp-json\/wp\/v2\/media?parent=4257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pipingpig.com\/index.php\/wp-json\/wp\/v2\/categories?post=4257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pipingpig.com\/index.php\/wp-json\/wp\/v2\/tags?post=4257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}