Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server SQL Server 2012字符串拆分_Sql Server_Text Mining - Fatal编程技术网

Sql server SQL Server 2012字符串拆分

Sql server SQL Server 2012字符串拆分,sql-server,text-mining,Sql Server,Text Mining,我的数据库中有一个充满大字符串的表,我试图分析这些字符串中的文本 我有这样的东西 On August the third the pope talked on vatican square.... bla bla 我想知道的是这样的事情 Word | Count ON | 2 August | 1 the | 2 third | 1 等等,我知道我必须断开这些字符串,找到空白空间“,”,“等等”,这样函数就知道这是一个单词,然后是字符串 结果应该放在一个新表中,如上所

我的数据库中有一个充满大字符串的表,我试图分析这些字符串中的文本

我有这样的东西

On August the third the pope talked on vatican square.... bla bla
我想知道的是这样的事情

Word   | Count 
ON     | 2
August | 1
the    | 2
third  | 1

等等,我知道我必须断开这些字符串,找到空白空间“,”,“等等”,这样函数就知道这是一个单词,然后是字符串<长度>

结果应该放在一个新表中,如上所示


使用SQL函数如何实现这一点?

您可以拆分和计数:

DECLARE @t NVARCHAR(400)='On August the third the pope talked on vatican square.'

;WITH tally AS
(
  SELECT TOP 1000  rn = ROW_NUMBER() OVER(ORDER BY 1/0)
  FROM master..spt_values
), cte AS(     
SELECT REPLACE(REPLACE(SUBSTRING(' ' + @t + ' ', rn + 1,
CHARINDEX(' ', ',' + @t + ' ', rn + 1) - rn -1),'.', ''), ',','') AS word
FROM tally
WHERE rn <= LEN(' ' + @t + ' ') - 1
    AND SUBSTRING(' ' + @t + ' ', rn, 1) = ' '
)
SELECT word, COUNT(*) AS total
FROM cte
GROUP BY word;

您可以拆分和计数:

DECLARE @t NVARCHAR(400)='On August the third the pope talked on vatican square.'

;WITH tally AS
(
  SELECT TOP 1000  rn = ROW_NUMBER() OVER(ORDER BY 1/0)
  FROM master..spt_values
), cte AS(     
SELECT REPLACE(REPLACE(SUBSTRING(' ' + @t + ' ', rn + 1,
CHARINDEX(' ', ',' + @t + ' ', rn + 1) - rn -1),'.', ''), ',','') AS word
FROM tally
WHERE rn <= LEN(' ' + @t + ' ') - 1
    AND SUBSTRING(' ' + @t + ' ', rn, 1) = ' '
)
SELECT word, COUNT(*) AS total
FROM cte
GROUP BY word;
输出-

--------------- -----------
august          1
bla             2
on              2
pope            1
square          1
talked          1
the             2
third           1
vatican         1
输出-

--------------- -----------
august          1
bla             2
on              2
pope            1
square          1
talked          1
the             2
third           1
vatican         1

+一个不同于那些张贴在无数重复问题上的技巧。性能如何?好问题;)实际上,我在
2Gb
表上测试了
dm\u fts\u解析器(每行
~1Mb
)。比
CTE
XML
快,但比
CLR
慢。此外,用户必须拥有
sysadmin
权限…+1,以使用与无数重复问题中发布的不同的技术。性能如何?好问题;)实际上,我在
2Gb
表上测试了
dm\u fts\u解析器(每行
~1Mb
)。比
CTE
XML
快,但比
CLR
慢。另外,用户必须拥有
sysadmin
权限…有几十个重复的问题。这很简单,而且不是最快的。数量级上最快的方法是使用SQLCLR辅助函数。有几十个重复的问题。这很简单,而且不是最快的。数量级上最快的是使用SQLCLR辅助函数。首先,SQLServer有自己的全文搜索和数据挖掘服务。你不应该试图自己解析文本。其次,有几十个重复的问题和几个拆分字符串的选项。首先,SQLServer有自己的全文搜索和数据挖掘服务。你不应该试图自己解析文本。其次,有几十个重复的问题和几个拆分字符串的选项