sql SQL Server中的charindex和patindex有什么区别?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql SQL Server中的charindex和patindex有什么区别?相关的知识,希望对你有一定的参考价值。
-------------------SQL Server-------------------------------------------
select
tags,
charindex('technology', tags) as char_position_tech,
patindex('technology', tags) as pat_position_tech,
patindex('%technology%', tags) as pat_position_tech_2,
charindex('Technology', tags) as char_position_Tech,
patindex('%Technology%', tags) as pat_position_Tech,
charindex('TED%', tags) as char_position_TED,
patindex('%TED%', tags) as pat_position_TED
from datageeking.dbo.ted_talks
/*tags |char_position_tech |pat_position_tech |pat_position_tech_2 |
-------------------------------------------------------------------------------------|-------------------|------------------|--------------------|
['alternative energy', 'energy', 'exploration', 'green', 'science', 'technology'] |70 |0 |70 |
['DNA', 'biology', 'business', 'genetics', 'life', 'science', 'technology'] |64 |0 |64 |
['TED Brain Trust', 'children', 'creativity', 'education', 'invention'] |0 |0 |0 |
['TEDx', 'business', 'creativity', 'culture', 'design', 'fashion', 'law', 'media'] |0 |0 |0 |
['TED Fellows', 'children', 'culture', 'film', 'politics', 'suicide', 'war'] |0 |0 |0 |
['AIDS', 'HIV', 'Vaccines', 'disease', 'global issues', 'health', 'medicine'] |0 |0 |0 |
['cities', 'music', 'performance', 'poetry', 'storytelling'] |0 |0 |0 |
['Internet', 'TEDx', 'law', 'music', 'online video', 'technology', 'web'] |55 |0 |55 |
tags |char_position_Tech |pat_position_Tech |
-------------------------------------------------------------------------------------|-------------------|------------------|
['alternative energy', 'energy', 'exploration', 'green', 'science', 'technology'] |70 |70 |
['DNA', 'biology', 'business', 'genetics', 'life', 'science', 'technology'] |64 |64 |
['TED Brain Trust', 'children', 'creativity', 'education', 'invention'] |0 |0 |
['TEDx', 'business', 'creativity', 'culture', 'design', 'fashion', 'law', 'media'] |0 |0 |
['TED Fellows', 'children', 'culture', 'film', 'politics', 'suicide', 'war'] |0 |0 |
['AIDS', 'HIV', 'Vaccines', 'disease', 'global issues', 'health', 'medicine'] |0 |0 |
['cities', 'music', 'performance', 'poetry', 'storytelling'] |0 |0 |
['Internet', 'TEDx', 'law', 'music', 'online video', 'technology', 'web'] |55 |55 |x
tags |char_position_TED |pat_position_TED
-------------------------------------------------------------------------------------|------------------|----------
['alternative energy', 'energy', 'exploration', 'green', 'science', 'technology'] |0 |0
['DNA', 'biology', 'business', 'genetics', 'life', 'science', 'technology'] |0 |0
['TED Brain Trust', 'children', 'creativity', 'education', 'invention'] |0 |3
['TEDx', 'business', 'creativity', 'culture', 'design', 'fashion', 'law', 'media'] |0 |3
['TED Fellows', 'children', 'culture', 'film', 'politics', 'suicide', 'war'] |0 |3
['AIDS', 'HIV', 'Vaccines', 'disease', 'global issues', 'health', 'medicine'] |0 |0
['cities', 'music', 'performance', 'poetry', 'storytelling'] |0 |0
['Internet', 'TEDx', 'law', 'music', 'online video', 'technology', 'web'] |0 |15
*/
以上是关于sql SQL Server中的charindex和patindex有什么区别?的主要内容,如果未能解决你的问题,请参考以下文章
sql server charindex函数和patindex函数详解(转)
sql server中的charindex函数用法解析(在一段字符中搜索字符或者字符串-----返回expression1在expression2出现的位置;反之,返回0)
sql server的一些函数------CHARINDEX(),PATINDEX(),STUFF(),SUBSTRING(),RIGHT(),LEFT()