{"id":88012,"date":"2024-10-18T05:51:17","date_gmt":"2024-10-17T21:51:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/88012\/"},"modified":"2024-10-18T05:51:18","modified_gmt":"2024-10-17T21:51:18","slug":"ora-22957-null-%e6%98%af-powermultiset-%e5%92%8c-collect-%e5%87%bd%e6%95%b8%e7%9a%84%e7%84%a1%e6%95%88%e8%bc%b8%e5%85%a5-oracle-%e5%a0%b1%e9%8c%af-%e6%95%85%e9%9a%9c%e4%bf%ae%e5%be%a9-%e9%81%a0","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/88012\/","title":{"rendered":"ORA-22957: NULL \u662f powermultiset \u548c COLLECT \u51fd\u6578\u7684\u7121\u6548\u8f38\u5165 ORACLE \u5831\u932f \u6545\u969c\u4fee\u5fa9 \u9060\u7a0b\u8655\u7406"},"content":{"rendered":"<h1 id=\"ora-22957-null-%e6%98%af-powermultiset-%e5%92%8c-collect-%e5%87%bd%e6%95%b8%e7%9a%84%e7%84%a1%e6%95%88%e8%bc%b8%e5%85%a5-oracle-%e5%a0%b1%e9%8c%af-%e6%95%85%e9%9a%9c%e4%bf%ae%e5%be%a9-%e9%81%a0-VNDJShLmBf\">ORA-22957: NULL \u662f powermultiset \u548c COLLECT \u51fd\u6578\u7684\u7121\u6548\u8f38\u5165 ORACLE \u5831\u932f \u6545\u969c\u4fee\u5fa9 \u9060\u7a0b\u8655\u7406<\/h1>\n<p>\u5728\u4f7f\u7528 Oracle \u6578\u64da\u5eab\u6642\uff0c\u958b\u767c\u8005\u548c\u6578\u64da\u5eab\u7ba1\u7406\u54e1\u53ef\u80fd\u6703\u9047\u5230\u5404\u7a2e\u932f\u8aa4\u4ee3\u78bc\uff0c\u5176\u4e2d\u4e4b\u4e00\u5c31\u662f <strong>ORA-22957<\/strong>\u3002\u9019\u500b\u932f\u8aa4\u901a\u5e38\u51fa\u73fe\u5728\u4f7f\u7528 <code>COLLECT<\/code> \u6216 <code>POWERMULTISET<\/code> \u51fd\u6578\u6642\uff0c\u7576\u9019\u4e9b\u51fd\u6578\u7684\u8f38\u5165\u5305\u542b NULL \u503c\u6642\uff0cOracle \u6703\u5831\u544a\u6b64\u932f\u8aa4\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e\u9019\u500b\u932f\u8aa4\u7684\u539f\u56e0\u3001\u5f71\u97ff\u4ee5\u53ca\u5982\u4f55\u9032\u884c\u6545\u969c\u4fee\u5fa9\u3002<\/p>\n<h2 id=\"ora-22957-%e9%8c%af%e8%aa%a4%e7%9a%84%e5%8e%9f%e5%9b%a0-VNDJShLmBf\">ORA-22957 \u932f\u8aa4\u7684\u539f\u56e0<\/h2>\n<p>\u7576\u4f7f\u7528 <code>COLLECT<\/code> \u6216 <code>POWERMULTISET<\/code> \u51fd\u6578\u6642\uff0c\u9019\u4e9b\u51fd\u6578\u7684\u4e3b\u8981\u529f\u80fd\u662f\u5c07\u591a\u884c\u6578\u64da\u805a\u5408\u6210\u4e00\u500b\u96c6\u5408\u3002\u5982\u679c\u5728\u9019\u500b\u904e\u7a0b\u4e2d\u9047\u5230 NULL \u503c\uff0cOracle \u5c07\u7121\u6cd5\u6b63\u78ba\u8655\u7406\u9019\u4e9b\u6578\u64da\uff0c\u5f9e\u800c\u5f15\u767c <strong>ORA-22957<\/strong> \u932f\u8aa4\u3002<\/p>\n<ul>\n<li><strong>COLLECT \u51fd\u6578\uff1a<\/strong>\u6b64\u51fd\u6578\u7528\u65bc\u5c07\u67e5\u8a62\u7d50\u679c\u4e2d\u7684\u591a\u884c\u6578\u64da\u805a\u5408\u6210\u4e00\u500b\u96c6\u5408\u3002\u7576\u5176\u4e2d\u4e00\u884c\u7684\u503c\u70ba NULL \u6642\uff0c\u6574\u500b\u805a\u5408\u904e\u7a0b\u5c07\u5931\u6557\u3002<\/li>\n<li><strong>POWERMULTISET \u51fd\u6578\uff1a<\/strong>\u6b64\u51fd\u6578\u985e\u4f3c\u65bc COLLECT\uff0c\u4f46\u5b83\u5141\u8a31\u91cd\u8907\u7684\u5143\u7d20\u3002\u5982\u679c\u8f38\u5165\u4e2d\u5305\u542b NULL \u503c\uff0c\u5247\u6703\u5c0e\u81f4\u932f\u8aa4\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e4%bf%ae%e5%be%a9-ora-22957-%e9%8c%af%e8%aa%a4-VNDJShLmBf\">\u5982\u4f55\u4fee\u5fa9 ORA-22957 \u932f\u8aa4<\/h2>\n<p>\u4fee\u5fa9 <strong>ORA-22957<\/strong> \u932f\u8aa4\u7684\u7b2c\u4e00\u6b65\u662f\u78ba\u5b9a NULL \u503c\u7684\u4f86\u6e90\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684\u89e3\u6c7a\u65b9\u6848\uff1a<\/p>\n<h3 id=\"1-%e6%aa%a2%e6%9f%a5%e6%95%b8%e6%93%9a%e6%ba%90-VNDJShLmBf\">1. \u6aa2\u67e5\u6578\u64da\u6e90<\/h3>\n<p>\u9996\u5148\uff0c\u6aa2\u67e5\u67e5\u8a62\u4e2d\u4f7f\u7528\u7684\u6578\u64da\u6e90\uff0c\u78ba\u4fdd\u6c92\u6709 NULL \u503c\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b SQL \u67e5\u8a62\u4f86\u6aa2\u67e5\uff1a<\/p>\n<pre><code>SELECT * FROM your_table WHERE your_column IS NULL;<\/code><\/pre>\n<p>\u5982\u679c\u67e5\u8a62\u7d50\u679c\u8fd4\u56de\u4e86\u884c\uff0c\u5247\u9700\u8981\u8003\u616e\u5982\u4f55\u8655\u7406\u9019\u4e9b NULL \u503c\uff0c\u4f8b\u5982\u4f7f\u7528 <code>NVL<\/code> \u51fd\u6578\u5c07\u5176\u66ff\u63db\u70ba\u5176\u4ed6\u503c\u3002<\/p>\n<h3 id=\"2-%e4%bd%bf%e7%94%a8-nvl-%e5%87%bd%e6%95%b8-VNDJShLmBf\">2. \u4f7f\u7528 NVL \u51fd\u6578<\/h3>\n<p>\u5728\u4f7f\u7528 <code>COLLECT<\/code> \u6216 <code>POWERMULTISET<\/code> \u51fd\u6578\u6642\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>NVL<\/code> \u51fd\u6578\u4f86\u66ff\u63db NULL \u503c\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>SELECT COLLECT(NVL(your_column, 'default_value')) FROM your_table;<\/code><\/pre>\n<p>\u9019\u6a23\u53ef\u4ee5\u78ba\u4fdd\u5728\u805a\u5408\u904e\u7a0b\u4e2d\u4e0d\u6703\u51fa\u73fe NULL \u503c\u3002<\/p>\n<h3 id=\"3-%e4%bd%bf%e7%94%a8-case-%e8%aa%9e%e5%8f%a5-VNDJShLmBf\">3. \u4f7f\u7528 CASE \u8a9e\u53e5<\/h3>\n<p>\u5982\u679c\u9700\u8981\u66f4\u8907\u96dc\u7684\u908f\u8f2f\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>CASE<\/code> \u8a9e\u53e5\u4f86\u8655\u7406 NULL \u503c\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>SELECT COLLECT(CASE WHEN your_column IS NULL THEN 'default_value' ELSE your_column END) FROM your_table;<\/code><\/pre>\n<h2 id=\"%e9%81%a0%e7%a8%8b%e8%99%95%e7%90%86-ora-22957-%e9%8c%af%e8%aa%a4-VNDJShLmBf\">\u9060\u7a0b\u8655\u7406 ORA-22957 \u932f\u8aa4<\/h2>\n<p>\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0c\u53ef\u80fd\u9700\u8981\u9060\u7a0b\u8655\u7406\u6b64\u932f\u8aa4\u3002\u9019\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u6b65\u9a5f\u5be6\u73fe\uff1a<\/p>\n<ul>\n<li><strong>\u9060\u7a0b\u9023\u63a5\uff1a<\/strong>\u4f7f\u7528 Oracle \u7684\u9060\u7a0b\u9023\u63a5\u529f\u80fd\uff0c\u9023\u63a5\u5230\u51fa\u73fe\u932f\u8aa4\u7684\u6578\u64da\u5eab\u3002<\/li>\n<li><strong>\u57f7\u884c\u4fee\u5fa9\u67e5\u8a62\uff1a<\/strong>\u5728\u9060\u7a0b\u6578\u64da\u5eab\u4e0a\u57f7\u884c\u4e0a\u8ff0\u4fee\u5fa9\u67e5\u8a62\uff0c\u6aa2\u67e5\u548c\u8655\u7406 NULL \u503c\u3002<\/li>\n<li><strong>\u6e2c\u8a66\uff1a<\/strong>\u5728\u4fee\u5fa9\u5f8c\uff0c\u91cd\u65b0\u57f7\u884c\u539f\u59cb\u67e5\u8a62\u4ee5\u78ba\u4fdd\u554f\u984c\u5df2\u89e3\u6c7a\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-VNDJShLmBf\">\u7e3d\u7d50<\/h2>\n<p>\u5728 Oracle \u6578\u64da\u5eab\u4e2d\uff0c<strong>ORA-22957<\/strong> \u932f\u8aa4\u901a\u5e38\u662f\u7531\u65bc\u4f7f\u7528 <code>COLLECT<\/code> \u6216 <code>POWERMULTISET<\/code> \u51fd\u6578\u6642\u9047\u5230 NULL \u503c\u6240\u5f15\u8d77\u7684\u3002\u901a\u904e\u6aa2\u67e5\u6578\u64da\u6e90\u3001\u4f7f\u7528 <code>NVL<\/code> \u51fd\u6578\u6216 <code>CASE<\/code> \u8a9e\u53e5\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u4fee\u5fa9\u6b64\u932f\u8aa4\u3002\u6b64\u5916\uff0c\u9060\u7a0b\u8655\u7406\u4e5f\u53ef\u4ee5\u5e6b\u52a9\u89e3\u6c7a\u554f\u984c\u3002\u5c0d\u65bc\u9700\u8981\u7a69\u5b9a\u548c\u9ad8\u6548\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\uff0c\u8003\u616e\u4f7f\u7528 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u670d\u52d9\uff0c\u4ee5\u78ba\u4fdd\u60a8\u7684\u61c9\u7528\u7a0b\u5e8f\u904b\u884c\u9806\u5229\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u89e3\u6c7a ORA-22957 \u932f\u8aa4\uff0c\u4e86\u89e3 NULL \u5728 powermultiset \u548c COLLECT \u51fd\u6578\u4e2d\u7684\u7121\u6548\u6027\uff0c\u63d0\u4f9b\u6545\u969c\u4fee\u5fa9\u548c\u9060\u7a0b\u8655\u7406\u65b9\u6848\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-88012","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/88012","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=88012"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/88012\/revisions"}],"predecessor-version":[{"id":88013,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/88012\/revisions\/88013"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=88012"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=88012"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=88012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}