<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>patindex</title>
	<atom:link href="https://www.aitaocui.cn/tag/260875/feed" rel="self" type="application/rss+xml" />
	<link>https://www.aitaocui.cn</link>
	<description>翡翠玉石爱好者聚集地</description>
	<lastBuildDate>Mon, 28 Nov 2022 11:37:26 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.1</generator>

<image>
	<url>https://www.aitaocui.cn/wp-content/uploads/2022/11/taocui.png</url>
	<title>patindex</title>
	<link>https://www.aitaocui.cn</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>patindex(SQL中的函数)</title>
		<link>https://www.aitaocui.cn/article/373081.html</link>
					<comments>https://www.aitaocui.cn/article/373081.html#respond</comments>
		
		<dc:creator><![CDATA[韩晓光]]></dc:creator>
		<pubDate>Mon, 28 Nov 2022 11:37:26 +0000</pubDate>
				<category><![CDATA[知识]]></category>
		<category><![CDATA[patindex]]></category>
		<guid isPermaLink="false">https://www.aitaocui.cn/?p=373081</guid>

					<description><![CDATA[PATINDEX是SQL中用于返回指定模式的开始位置的函数。 基本内容 CHARINDEX 和 PATINDEX 函数都返回指定模式的开始位置。PATINDEX 可使用通配符，而 ...]]></description>
										<content:encoded><![CDATA[</p>
<article>
<p>PATINDEX是SQL中用于返回指定模式的开始位置的函数。</p>
</article>
<article>
<h1>基本内容</h1>
<p>CHARINDEX 和 PATINDEX 函数都返回指定模式的开始位置。PATINDEX 可使用通配符，而 CHARINDEX 不可以。</p>
<p>这两个函数都带有2个参数:</p>
<p>1 希望获取其位置的模式。使用 PATINDEX，模式是可以包含通配符的字面字符串。使用 CHARINDEX，模式是字面字符串(不能包含通配符)。</p>
<p>2 字符串值表达式(通常为列名)。</p>
<p>例如，查找模式&quot;wonderful&quot;在 titles 表中 notes 列的某一特定行中的开始位置。</p>
<p>USE pubs</p>
<p>SELECT CHARINDEX(&#x27;wonderful&#x27;, notes)</p>
<p>FROM titles</p>
<p>WHERE title_id = &#x27;TC3218&#x27;</p>
<p>例如，使用通配符查找模式&quot;candies&quot;在 Categories 表中的 Description 列的任一行中的开始位置:</p>
<p>USE Northwind</p>
<p>GO</p>
<p>SELECT CategoryID, PATINDEX(&#x27;%candies%&#x27;, Description)AS POSITION</p>
<p>FROM Categories</p>
<p>WHERE PATINDEX(&#x27;%candies%&#x27;, Description) &lt;&gt; 0</p>
<h1>特点</h1>
<p>用PatIndex和CharIndex替代LIKE进行模糊查询</p>
<p>使用Like 进行模糊查询的速度很慢，尤其是多个 like的时候，更是如此。</p>
<p>而使用PatIndex和CharIndex相对来说速度快很多。</p>
<p>select * from table where a  Like&#x27;%字符%&#x27;</p>
<p>select * from table where PatIndex(&#x27;%字符%&#x27; , a)  &gt;  0 </p>
<p>select * from table where CharIndex(&#x27;字符&#x27; ,a)  &gt;  0 </p>
<p>需要注意的是，PatIndex用来处理模糊的条件，比如%字符%</p>
<p>而CahrIndex则处理相对精确的条件。</p>
</article>
<div class="mt-3 mb-3" style="max-width: 770px;height: auto;">
                                    </div>
<div class="mt-3 mb-3" style="max-width: 770px;height: auto;">
                                    </div>
<div class="mt-3 mb-3" style="max-width: 770px;height: auto;">
                                    </div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.aitaocui.cn/article/373081.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
