{"id":682,"date":"2012-07-20T10:51:41","date_gmt":"2012-07-20T02:51:41","guid":{"rendered":"http:\/\/j178.mtgbb.com\/?p=682"},"modified":"2012-07-20T10:51:41","modified_gmt":"2012-07-20T02:51:41","slug":"%e9%97%9c%e6%96%bc-pipe-row-%e6%87%89%e7%94%a8-split-or-merge-%e5%ad%97%e4%b8%b2","status":"publish","type":"post","link":"https:\/\/j178.mtgbb.com\/?p=682","title":{"rendered":"\u95dc\u65bc pipe row \u61c9\u7528, split or merge \u5b57\u4e32"},"content":{"rendered":"<p>Oralce \u6709\u7a2e pipelining \u7684\u6280\u8853, \u53ef\u4ee5\u57f7\u884c SQL \u6642\u53ef\u4ee5\u7522\u751f\u4e00\u500b\u865b\u64ec Table,<\/p>\n<p>\u9019\u9805\u6280\u8853\u53ef\u7528\u4f86\u5f4c\u88dc function \u50b3\u503c\u6642\u7684\u9650\u5236<\/p>\n<p>\u7a0b\u5f0f\u78bc:<\/p>\n<pre lang=\"oracle8\">\r\n  -- \u5ba3\u544a\u985e\u578b\r\n  CREATE OR REPLACE TYPE xx_split_tbl IS TABLE OF VARCHAR2 (4000);\r\n\r\n  -----------------------------------------------------------\r\n  -- \u50b3\u5165\u5b57\u4e32 + \u5206\u9694\u7b26\u865f, \u50b3\u56de \u55ae\u4e00\u6b04\u4f4d\u7684 table, \u6b04\u4f4d\u540d: column_value\r\n  -----------------------------------------------------------\r\n  FUNCTION get_split_tbl(p_list VARCHAR2, p_del VARCHAR2 DEFAULT ';')\r\n    RETURN xx_split_tbl\r\n    PIPELINED IS\r\n    v_idx  PLS_INTEGER;\r\n    v_list VARCHAR2(32767) := p_list;\r\n  BEGIN\r\n    LOOP\r\n      v_idx := instr(v_list, p_del);\r\n      IF v_idx > 0 THEN\r\n        PIPE ROW(substr(v_list, 1, v_idx - 1));\r\n        v_list := substr(v_list, v_idx + length(p_del));\r\n      ELSE\r\n        PIPE ROW(v_list);\r\n        EXIT;\r\n      END IF;\r\n    END LOOP;\r\n    RETURN;\r\n  EXCEPTION\r\n    WHEN OTHERS THEN\r\n      RAISE;\r\n  END get_split_tbl;\r\n\r\n  -----------------------------------------------------------\r\n  -- \u50b3\u5165\u55ae\u4e00\u6b04\u4f4d\u7684 table + \u5206\u9694\u7b26\u865f, \u50b3\u56de\u7d44\u5408\u7684\u5b57\u4e32\r\n  -----------------------------------------------------------\r\n  FUNCTION get_merge_str(p_cursor SYS_REFCURSOR,\r\n                         p_del    VARCHAR2 DEFAULT ';') RETURN VARCHAR2 IS\r\n    v_value  VARCHAR2(32767);\r\n    v_result VARCHAR2(32767);\r\n  BEGIN\r\n    LOOP\r\n      FETCH p_cursor\r\n        INTO v_value;\r\n      EXIT WHEN p_cursor%NOTFOUND;\r\n      IF v_result IS NOT NULL THEN\r\n        v_result := v_result || p_del;\r\n      END IF;\r\n      v_result := v_result || v_value;\r\n    END LOOP;\r\n    CLOSE p_cursor;\r\n    RETURN v_result;\r\n  EXCEPTION\r\n    WHEN OTHERS THEN\r\n      RAISE;\r\n  END get_merge_str;\r\n<\/pre>\n<p>\u4f7f\u7528\u7bc4\u4f8b:<\/p>\n<pre lang=\"oracle8\">\r\n1. \u5b57\u4e32\u62c6\u89e3\u6210 table\r\nSELECT column_value\r\n  FROM TABLE(xxutlpkg.get_split_tbl('01;02;03;04;09;11;12', ';'));\r\n\r\n2. table \u67d0\u6b04\u4f4d\u7d44\u6210 \u5b57\u4e32+\u5206\u9694\u7b26\u865f\r\nSELECT xxutlpkg.get_merge_str(CURSOR (SELECT wafer_id\r\n                                 FROM xxwip_clot_line l\r\n                                WHERE l.sub_lot_id = 'FP8312.1'\r\n                                ORDER BY wafer_id),\r\n                              ';')\r\n  FROM dual;\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Oralce \u6709\u7a2e pipelining \u7684\u6280\u8853, \u53ef\u4ee5\u57f7\u884c SQL \u6642\u53ef\u4ee5\u7522\u751f\u4e00\u500b\u865b\u64ec Table, \u9019\u9805\u6280 &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[23],"class_list":["post-682","post","type-post","status-publish","format-standard","hentry","category-database","tag-oracle-db"],"_links":{"self":[{"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=\/wp\/v2\/posts\/682","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=682"}],"version-history":[{"count":0,"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=\/wp\/v2\/posts\/682\/revisions"}],"wp:attachment":[{"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=682"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}