{"id":94808,"date":"2024-10-19T20:49:58","date_gmt":"2024-10-19T12:49:58","guid":{"rendered":"https:\/\/server.hk\/cnblog\/94808\/"},"modified":"2024-10-19T20:49:59","modified_gmt":"2024-10-19T12:49:59","slug":"oracle%e6%9f%a5%e8%a9%a2%e5%bf%bd%e7%95%a5%e5%a4%a7%e5%b0%8f%e5%af%ab%e7%9a%84%e5%af%a6%e7%8f%be%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/94808\/","title":{"rendered":"Oracle\u67e5\u8a62\u5ffd\u7565\u5927\u5c0f\u5beb\u7684\u5be6\u73fe\u65b9\u6cd5"},"content":{"rendered":"<h1 id=\"oracle%e6%9f%a5%e8%a9%a2%e5%bf%bd%e7%95%a5%e5%a4%a7%e5%b0%8f%e5%af%ab%e7%9a%84%e5%af%a6%e7%8f%be%e6%96%b9%e6%b3%95-wdbNGNgdxF\">Oracle\u67e5\u8a62\u5ffd\u7565\u5927\u5c0f\u5beb\u7684\u5be6\u73fe\u65b9\u6cd5<\/h1>\n<p>\u5728\u4f7f\u7528Oracle\u6578\u64da\u5eab\u9032\u884c\u67e5\u8a62\u6642\uff0c\u5927\u5c0f\u5beb\u7684\u654f\u611f\u6027\u53ef\u80fd\u6703\u5f71\u97ff\u67e5\u8a62\u7d50\u679c\u3002\u7279\u5225\u662f\u5728\u8655\u7406\u7528\u6236\u8f38\u5165\u6216\u9700\u8981\u9032\u884c\u6a21\u7cca\u5339\u914d\u7684\u60c5\u6cc1\u4e0b\uff0c\u5982\u4f55\u5be6\u73fe\u5ffd\u7565\u5927\u5c0f\u5beb\u7684\u67e5\u8a62\u6210\u70ba\u4e86\u4e00\u500b\u91cd\u8981\u7684\u8ab2\u984c\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5e7e\u7a2e\u5728Oracle\u4e2d\u5be6\u73fe\u67e5\u8a62\u5ffd\u7565\u5927\u5c0f\u5beb\u7684\u65b9\u6cd5\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u6709\u6548\u5730\u8655\u7406\u6578\u64da\u3002<\/p>\n<h2 id=\"1-%e4%bd%bf%e7%94%a8upper%e6%88%96lower%e5%87%bd%e6%95%b8-wdbNGNgdxF\">1. \u4f7f\u7528UPPER\u6216LOWER\u51fd\u6578<\/h2>\n<p>\u6700\u5e38\u898b\u7684\u89e3\u6c7a\u65b9\u6848\u662f\u4f7f\u7528Oracle\u7684\u5167\u5efa\u51fd\u6578\uff0c\u5982<code>UPPER<\/code>\u6216<code>LOWER<\/code>\uff0c\u5c07\u67e5\u8a62\u4e2d\u7684\u5b57\u7b26\u4e32\u8f49\u63db\u70ba\u7d71\u4e00\u7684\u5927\u5c0f\u5beb\u3002\u9019\u6a23\u53ef\u4ee5\u78ba\u4fdd\u6bd4\u8f03\u6642\u4e0d\u53d7\u5927\u5c0f\u5beb\u5f71\u97ff\u3002<\/p>\n<pre><code>SELECT * FROM users WHERE UPPER(username) = UPPER('exampleUser');\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u7121\u8ad6\u7528\u6236\u8f38\u5165\u7684<code>exampleUser<\/code>\u662f\u5927\u5beb\u9084\u662f\u5c0f\u5beb\uff0c\u67e5\u8a62\u90fd\u80fd\u6b63\u78ba\u5339\u914d\u5230\u76f8\u61c9\u7684\u7528\u6236\u3002<\/p>\n<h2 id=\"2-%e4%bd%bf%e7%94%a8nls_comp%e5%92%8cnls_sort%e5%8f%83%e6%95%b8-wdbNGNgdxF\">2. \u4f7f\u7528NLS_COMP\u548cNLS_SORT\u53c3\u6578<\/h2>\n<p>Oracle\u63d0\u4f9b\u4e86NLS_COMP\u548cNLS_SORT\u53c3\u6578\u4f86\u63a7\u5236\u5b57\u7b26\u4e32\u6bd4\u8f03\u7684\u884c\u70ba\u3002\u901a\u904e\u8a2d\u7f6e\u9019\u4e9b\u53c3\u6578\uff0c\u53ef\u4ee5\u5be6\u73fe\u5927\u5c0f\u5beb\u4e0d\u654f\u611f\u7684\u67e5\u8a62\u3002<\/p>\n<pre><code>ALTER SESSION SET NLS_COMP=LINGUISTIC;\nALTER SESSION SET NLS_SORT=BINARY_CI;\n<\/code><\/pre>\n<p>\u5728\u8a2d\u7f6e\u4e86\u9019\u4e9b\u53c3\u6578\u5f8c\uff0c\u9032\u884c\u67e5\u8a62\u6642\u5c31\u53ef\u4ee5\u76f4\u63a5\u6bd4\u8f03\u5b57\u7b26\u4e32\uff0c\u800c\u4e0d\u9700\u8981\u4f7f\u7528UPPER\u6216LOWER\u51fd\u6578\u3002<\/p>\n<pre><code>SELECT * FROM users WHERE username = 'exampleUser';\n<\/code><\/pre>\n<p>\u9019\u6a23\u7684\u67e5\u8a62\u5c07\u6703\u5ffd\u7565\u5927\u5c0f\u5beb\uff0c\u8fd4\u56de\u6240\u6709\u5339\u914d\u7684\u7528\u6236\u3002<\/p>\n<h2 id=\"3-%e4%bd%bf%e7%94%a8%e6%ad%a3%e5%89%87%e8%a1%a8%e9%81%94%e5%bc%8f-wdbNGNgdxF\">3. \u4f7f\u7528\u6b63\u5247\u8868\u9054\u5f0f<\/h2>\n<p>Oracle\u7684\u6b63\u5247\u8868\u9054\u5f0f\u529f\u80fd\u4e5f\u53ef\u4ee5\u7528\u4f86\u5be6\u73fe\u5927\u5c0f\u5beb\u4e0d\u654f\u611f\u7684\u67e5\u8a62\u3002\u4f7f\u7528<code>REGEXP_LIKE<\/code>\u51fd\u6578\uff0c\u53ef\u4ee5\u6307\u5b9a\u4e00\u500b\u6b63\u5247\u8868\u9054\u5f0f\u4f86\u9032\u884c\u5339\u914d\u3002<\/p>\n<pre><code>SELECT * FROM users WHERE REGEXP_LIKE(username, '^exampleUser$', 'i');\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c<code>'i'<\/code>\u6a19\u8a8c\u8868\u793a\u5ffd\u7565\u5927\u5c0f\u5beb\uff0c\u9019\u6a23\u53ef\u4ee5\u5339\u914d\u6240\u6709\u5f62\u5f0f\u7684<code>exampleUser<\/code>\u3002<\/p>\n<h2 id=\"4-%e4%bd%bf%e7%94%a8collation-wdbNGNgdxF\">4. \u4f7f\u7528COLLATION<\/h2>\n<p>\u5728Oracle 12c\u53ca\u4ee5\u5f8c\u7684\u7248\u672c\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528COLLATION\u4f86\u6307\u5b9a\u5b57\u7b26\u4e32\u7684\u6bd4\u8f03\u898f\u5247\u3002\u9019\u6a23\u53ef\u4ee5\u5728\u5275\u5efa\u8868\u6642\u5c31\u8a2d\u7f6e\u9ed8\u8a8d\u7684\u5927\u5c0f\u5beb\u4e0d\u654f\u611f\u6bd4\u8f03\u3002<\/p>\n<pre><code>CREATE TABLE users (\n    username VARCHAR2(50) COLLATE BINARY_CI\n);\n<\/code><\/pre>\n<p>\u9019\u6a23\u8a2d\u7f6e\u5f8c\uff0c\u6240\u6709\u5c0d<code>username<\/code>\u5b57\u6bb5\u7684\u67e5\u8a62\u90fd\u5c07\u81ea\u52d5\u5ffd\u7565\u5927\u5c0f\u5beb\u3002<\/p>\n<h2 id=\"5-%e4%bd%bf%e7%94%a8like%e9%81%8b%e7%ae%97%e7%ac%a6-wdbNGNgdxF\">5. \u4f7f\u7528LIKE\u904b\u7b97\u7b26<\/h2>\n<p>\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0c\u4f7f\u7528<code>LIKE<\/code>\u904b\u7b97\u7b26\u4e5f\u53ef\u4ee5\u5be6\u73fe\u5927\u5c0f\u5beb\u4e0d\u654f\u611f\u7684\u67e5\u8a62\u3002\u9019\u901a\u5e38\u9069\u7528\u65bc\u6a21\u7cca\u5339\u914d\u7684\u60c5\u6cc1\u3002<\/p>\n<pre><code>SELECT * FROM users WHERE username LIKE 'exampleUser';\n<\/code><\/pre>\n<p>\u4e0d\u904e\uff0c\u9019\u7a2e\u65b9\u6cd5\u7684\u6548\u679c\u53ef\u80fd\u6703\u53d7\u5230NLS_SORT\u7684\u5f71\u97ff\uff0c\u56e0\u6b64\u5728\u4f7f\u7528\u524d\u9700\u8981\u78ba\u8a8d\u76f8\u95dc\u8a2d\u7f6e\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-wdbNGNgdxF\">\u7e3d\u7d50<\/h2>\n<p>\u5728Oracle\u4e2d\u5be6\u73fe\u67e5\u8a62\u5ffd\u7565\u5927\u5c0f\u5beb\u7684\u65b9\u6cd5\u6709\u591a\u7a2e\uff0c\u5305\u62ec\u4f7f\u7528UPPER\u6216LOWER\u51fd\u6578\u3001\u8a2d\u7f6eNLS_COMP\u548cNLS_SORT\u53c3\u6578\u3001\u4f7f\u7528\u6b63\u5247\u8868\u9054\u5f0f\u3001COLLATION\u4ee5\u53caLIKE\u904b\u7b97\u7b26\u7b49\u3002\u6839\u64da\u5177\u9ad4\u9700\u6c42\u9078\u64c7\u5408\u9069\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u63d0\u9ad8\u67e5\u8a62\u7684\u9748\u6d3b\u6027\u548c\u6e96\u78ba\u6027\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u4f86\u652f\u6301\u60a8\u7684\u61c9\u7528\u7a0b\u5e8f\uff0c\u7121\u8ad6\u662f\u6578\u64da\u5b58\u5132\u9084\u662f\u67e5\u8a62\u8655\u7406\uff0c\u5747\u80fd\u63d0\u4f9b\u7a69\u5b9a\u7684\u6027\u80fd\u548c\u53ef\u9760\u7684\u670d\u52d9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3Oracle\u67e5\u8a62\u4e2d\u5982\u4f55\u5be6\u73fe\u5ffd\u7565\u5927\u5c0f\u5beb\u7684\u6280\u5de7\u8207\u65b9\u6cd5\uff0c\u63d0\u5347\u6578\u64da\u6aa2\u7d22\u7684\u9748\u6d3b\u6027\u8207\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-94808","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/94808","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=94808"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/94808\/revisions"}],"predecessor-version":[{"id":94809,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/94808\/revisions\/94809"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=94808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=94808"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=94808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}