开发者

Get all unique character of String in sql

I have a Table with column firstName and lastName as String. Now want to take all unique first char of those column.my table have thousand of row in that table ,but i just want to have Is the any string function in SQL to do this?

One more thing I need to 开发者_如何学运维find only alphabets no special characters.As my table is big it contains firstname and lastname with special character i need to ignore them

EG:assume my table contains firstname entry as ::jack,tom,riddle,monk,*opeth

In that case my sql should return j,m,r,t


Try this:

SELECT DISTINCT LOWER(SUBSTR(firstName,1,1)) firstChars
FROM your_table
WHERE LOWER(SUBSTR(firstName,1,1)) IN
 ('a','b','c','d','e','f','g','h','i','j',
  'k','l','m','n','o','p','q','r','s','t',
  'u','v','w','x','y','z')
ORDER BY firstChars


If you are working on 10g or higher the RegEx version of the query requires a lot less typing :)

SELECT DISTINCT SUBSTR(firstName,1,1) 
FROM your_table
WHERE REGEXP_LIKE(firstName,'^[[:alpha:]]')
/

You may want to apply UPPER() or LOWER() to smooth out mixed case results.


SELECT DISTINCT left(firstName,1) FROM table_name
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜