{"id":135137,"date":"2024-10-31T08:09:34","date_gmt":"2024-10-31T00:09:34","guid":{"rendered":"https:\/\/server.hk\/cnblog\/135137\/"},"modified":"2024-10-31T08:09:35","modified_gmt":"2024-10-31T00:09:35","slug":"sql-charindex%e5%87%bd%e6%95%b8%e7%9a%84%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/135137\/","title":{"rendered":"SQL CHARINDEX\u51fd\u6578\u7684\u4f7f\u7528"},"content":{"rendered":"<h1 id=\"sql-charindex%e5%87%bd%e6%95%b8%e7%9a%84%e4%bd%bf%e7%94%a8-lMhacCQFAO\">SQL CHARINDEX\u51fd\u6578\u7684\u4f7f\u7528<\/h1>\n<p>\u5728SQL Server\u4e2d\uff0cCHARINDEX\u51fd\u6578\u662f\u4e00\u500b\u975e\u5e38\u6709\u7528\u7684\u5b57\u7b26\u4e32\u51fd\u6578\uff0c\u4e3b\u8981\u7528\u65bc\u67e5\u627e\u4e00\u500b\u5b50\u5b57\u7b26\u4e32\u5728\u53e6\u4e00\u500b\u5b57\u7b26\u4e32\u4e2d\u7684\u4f4d\u7f6e\u3002\u9019\u500b\u51fd\u6578\u7684\u8fd4\u56de\u503c\u662f\u5b50\u5b57\u7b26\u4e32\u9996\u6b21\u51fa\u73fe\u7684\u4f4d\u7f6e\uff0c\u5982\u679c\u672a\u627e\u5230\u5247\u8fd4\u56de0\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0eCHARINDEX\u51fd\u6578\u7684\u8a9e\u6cd5\u3001\u4f7f\u7528\u65b9\u6cd5\u53ca\u5176\u5be6\u969b\u61c9\u7528\u793a\u4f8b\u3002<\/p>\n<h2 id=\"charindex%e5%87%bd%e6%95%b8%e7%9a%84%e8%aa%9e%e6%b3%95-lMhacCQFAO\">CHARINDEX\u51fd\u6578\u7684\u8a9e\u6cd5<\/h2>\n<p>CHARINDEX\u51fd\u6578\u7684\u57fa\u672c\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>CHARINDEX ( @substring , @string [ , @start_location ] )<\/code><\/pre>\n<ul>\n<li><strong>@substring<\/strong>\uff1a\u8981\u67e5\u627e\u7684\u5b50\u5b57\u7b26\u4e32\u3002<\/li>\n<li><strong>@string<\/strong>\uff1a\u8981\u641c\u7d22\u7684\u4e3b\u5b57\u7b26\u4e32\u3002<\/li>\n<li><strong>@start_location<\/strong>\uff1a\u53ef\u9078\u53c3\u6578\uff0c\u6307\u5b9a\u5f9e\u4e3b\u5b57\u7b26\u4e32\u7684\u54ea\u500b\u4f4d\u7f6e\u958b\u59cb\u67e5\u627e\uff0c\u9ed8\u8a8d\u70ba1\u3002<\/li>\n<\/ul>\n<h2 id=\"charindex%e5%87%bd%e6%95%b8%e7%9a%84%e4%bd%bf%e7%94%a8%e7%a4%ba%e4%be%8b-lMhacCQFAO\">CHARINDEX\u51fd\u6578\u7684\u4f7f\u7528\u793a\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u4f7f\u7528CHARINDEX\u51fd\u6578\u7684\u793a\u4f8b\uff0c\u5e6b\u52a9\u8b80\u8005\u66f4\u597d\u5730\u7406\u89e3\u5176\u7528\u6cd5\u3002<\/p>\n<h3 id=\"%e7%a4%ba%e4%be%8b1%ef%bc%9a%e5%9f%ba%e6%9c%ac%e7%94%a8%e6%b3%95-lMhacCQFAO\">\u793a\u4f8b1\uff1a\u57fa\u672c\u7528\u6cd5<\/h3>\n<p>\u5047\u8a2d\u6211\u5011\u6709\u4e00\u500b\u5b57\u7b26\u4e32\u201cHello, World!\u201d\u4e26\u5e0c\u671b\u67e5\u627e\u201cWorld\u201d\u9019\u500b\u5b50\u5b57\u7b26\u4e32\u7684\u4f4d\u7f6e\uff1a<\/p>\n<pre><code>SELECT CHARINDEX('World', 'Hello, World!') AS Position;<\/code><\/pre>\n<p>\u57f7\u884c\u4e0a\u8ff0\u67e5\u8a62\u5f8c\uff0c\u8fd4\u56de\u7684\u7d50\u679c\u5c07\u662f7\uff0c\u56e0\u70ba\u201cWorld\u201d\u5728\u5b57\u7b26\u4e32\u4e2d\u7684\u7b2c7\u500b\u4f4d\u7f6e\u958b\u59cb\u3002<\/p>\n<h3 id=\"%e7%a4%ba%e4%be%8b2%ef%bc%9a%e4%bd%bf%e7%94%a8%e8%b5%b7%e5%a7%8b%e4%bd%8d%e7%bd%ae-lMhacCQFAO\">\u793a\u4f8b2\uff1a\u4f7f\u7528\u8d77\u59cb\u4f4d\u7f6e<\/h3>\n<p>\u5982\u679c\u6211\u5011\u5e0c\u671b\u5f9e\u5b57\u7b26\u4e32\u7684\u67d0\u500b\u7279\u5b9a\u4f4d\u7f6e\u958b\u59cb\u67e5\u627e\uff0c\u53ef\u4ee5\u4f7f\u7528\u7b2c\u4e09\u500b\u53c3\u6578\u3002\u4f8b\u5982\uff0c\u5f9e\u7b2c5\u500b\u5b57\u7b26\u958b\u59cb\u67e5\u627e\u201co\u201d\uff1a<\/p>\n<pre><code>SELECT CHARINDEX('o', 'Hello, World!', 5) AS Position;<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de8\uff0c\u56e0\u70ba\u5f9e\u7b2c5\u500b\u5b57\u7b26\u958b\u59cb\uff0c\u201co\u201d\u5728\u7b2c8\u500b\u4f4d\u7f6e\u51fa\u73fe\u3002<\/p>\n<h3 id=\"%e7%a4%ba%e4%be%8b3%ef%bc%9a%e6%9f%a5%e6%89%be%e4%b8%8d%e5%ad%98%e5%9c%a8%e7%9a%84%e5%ad%90%e5%ad%97%e7%ac%a6%e4%b8%b2-lMhacCQFAO\">\u793a\u4f8b3\uff1a\u67e5\u627e\u4e0d\u5b58\u5728\u7684\u5b50\u5b57\u7b26\u4e32<\/h3>\n<p>\u5982\u679c\u67e5\u627e\u7684\u5b50\u5b57\u7b26\u4e32\u4e0d\u5b58\u5728\uff0cCHARINDEX\u5c07\u8fd4\u56de0\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>SELECT CHARINDEX('SQL', 'Hello, World!') AS Position;<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de0\uff0c\u56e0\u70ba\u201cSQL\u201d\u4e26\u4e0d\u5728\u5b57\u7b26\u4e32\u4e2d\u3002<\/p>\n<h2 id=\"charindex%e5%87%bd%e6%95%b8%e7%9a%84%e6%87%89%e7%94%a8%e5%a0%b4%e6%99%af-lMhacCQFAO\">CHARINDEX\u51fd\u6578\u7684\u61c9\u7528\u5834\u666f<\/h2>\n<p>CHARINDEX\u51fd\u6578\u5728\u5be6\u969b\u61c9\u7528\u4e2d\u6709\u591a\u7a2e\u7528\u9014\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684\u5834\u666f\uff1a<\/p>\n<ul>\n<li><strong>\u6578\u64da\u6e05\u7406\uff1a<\/strong>\u5728\u8655\u7406\u6578\u64da\u6642\uff0c\u53ef\u80fd\u9700\u8981\u67e5\u627e\u7279\u5b9a\u5b57\u7b26\u6216\u5b50\u5b57\u7b26\u4e32\uff0c\u4ee5\u4fbf\u9032\u884c\u6578\u64da\u6e05\u7406\u6216\u683c\u5f0f\u5316\u3002<\/li>\n<li><strong>\u689d\u4ef6\u67e5\u8a62\uff1a<\/strong>\u53ef\u4ee5\u6839\u64da\u67d0\u4e9b\u689d\u4ef6\u904e\u6ffe\u6578\u64da\uff0c\u4f8b\u5982\u67e5\u627e\u5305\u542b\u7279\u5b9a\u95dc\u9375\u5b57\u7684\u8a18\u9304\u3002<\/li>\n<li><strong>\u5b57\u7b26\u4e32\u64cd\u4f5c\uff1a<\/strong>\u5728\u5b57\u7b26\u4e32\u64cd\u4f5c\u4e2d\uff0cCHARINDEX\u53ef\u4ee5\u5e6b\u52a9\u78ba\u5b9a\u5b50\u5b57\u7b26\u4e32\u7684\u4f4d\u7f6e\uff0c\u4ee5\u4fbf\u9032\u884c\u9032\u4e00\u6b65\u7684\u8655\u7406\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-lMhacCQFAO\">\u7e3d\u7d50<\/h2>\n<p>CHARINDEX\u51fd\u6578\u662f\u4e00\u500b\u5f37\u5927\u7684\u5de5\u5177\uff0c\u80fd\u5920\u5e6b\u52a9\u958b\u767c\u8005\u5728SQL Server\u4e2d\u6709\u6548\u5730\u67e5\u627e\u5b57\u7b26\u4e32\u3002\u7121\u8ad6\u662f\u5728\u6578\u64da\u6e05\u7406\u3001\u689d\u4ef6\u67e5\u8a62\u9084\u662f\u5b57\u7b26\u4e32\u64cd\u4f5c\u4e2d\uff0cCHARINDEX\u90fd\u80fd\u767c\u63ee\u91cd\u8981\u4f5c\u7528\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u8655\u7406\u5b57\u7b26\u4e32\u7684\u958b\u767c\u8005\u4f86\u8aaa\uff0c\u638c\u63e1CHARINDEX\u51fd\u6578\u7684\u4f7f\u7528\u662f\u975e\u5e38\u5fc5\u8981\u7684\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u60a8\u7684\u9700\u6c42\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a> \u9084\u662f\u5176\u4ed6\u96f2\u670d\u52d9\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3SQL CHARINDEX\u51fd\u6578\u7684\u7528\u6cd5\uff0c\u5b78\u7fd2\u5982\u4f55\u5728\u5b57\u4e32\u4e2d\u67e5\u627e\u5b50\u5b57\u4e32\u7684\u4f4d\u7f6e\uff0c\u63d0\u5347\u6578\u64da\u67e5\u8a62\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-135137","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/135137","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=135137"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/135137\/revisions"}],"predecessor-version":[{"id":135138,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/135137\/revisions\/135138"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=135137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=135137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=135137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}