How can I count the number of words in a string in Oracle?

前端 未结 4 1462
独厮守ぢ
独厮守ぢ 2020-12-11 16:49

I\'m trying to count how many words there are in a string in SQL.

Select  (\"Hello To Oracle\") from dual;

I want to show the number of wor

4条回答
  •  既然无缘
    2020-12-11 17:22

    If your requirement is to remove multiple spaces too, try this:

    Select length('500  text Oracle Parkway Redwood Shores CA') - length(REGEXP_REPLACE('500  text Oracle Parkway Redwood Shores CA',
    '( ){1,}', ''))  NumbofWords
    from dual;
    

    Since I have used the dual table you can test this directly in your own development environment.

提交回复
热议问题