是否可以仅使用SQL计算每个单词的长度?例如,对于以下句子:
I have a length of x.
1 4 1 6 2 1
答案 0 :(得分:1)
可以尝试自定义方法来创建:
以下是可以提供帮助的示例代码:
Declare @products varchar(200) = 'I have a length of x.'
Declare @individual varchar(20) = null
Declare @lengthOfProducts varchar(20) = null
WHILE LEN(@products) > 0
BEGIN
IF PATINDEX('% %', @products) > 0
BEGIN
SET @individual = SUBSTRING(@products,
0,
PATINDEX('% %', @products))
SELECT @individual
SET @lengthOfProducts = @lengthOfProducts + ' ' + LEN(@individual)
SET @products = SUBSTRING(@products,
LEN(@individual + ' ') + 1,
LEN(@products))
END
ELSE
BEGIN
SET @individual = @products
SET @products = NULL
SELECT @lengthOfProducts
END
END
答案 1 :(得分:0)
有LEN()
功能。你只需要在SQL中使用它
SELECT LEN(column_name) FROM table_name;
这在Oracle中
SELECT LENGTH(column_name) FROM table_name;
答案 2 :(得分:0)
在sql server中,使用LEN(column_name)
。
对于oracle使用LENGTH(column_name)
例如SELECT CustomerName,LEN(Address) as LengthOfAddress
FROM Customers;