Matheus Nascimento
Matheus Nascimento

Reputation: 21

How to count the number of commas (',') in a SQL table column?

I have a table in Teradata. This table has a column named text_column that contains some text in format varchar(25).

I need to count the number of ',' in this column.

Upvotes: 0

Views: 351

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270783

One method uses the difference of lengths of strings:

select ( character_length(text_column) - character_length(oreplace(text_column, ',', '')) as num_columns

Upvotes: 1

Related Questions