Home > Back-end >  How to detect column that starts with special characters
How to detect column that starts with special characters

Time:11-07

I have a table with records like

  • dog
  • cat
  • mouse
  • :mouse
  • ????cat

I'm trying select all values from the table but if the value starts with a special character then ignore it. In total, the list equates to 5 recors but should only return 3 since the last 2 starts with special characters.

What would be the best way to achieve this in my select statement?

CodePudding user response:

You could use a regular expression:

  • MySQL: SELECT * FROM table WHERE col REGEXP '^[a-zA-Z]'
  • PostgreSQL: SELECT * FROM table WHERE col ~ '^[a-zA-Z]'
  • Oracle: SELECT * FROM table WHERE REGEXP_LIKE(col, '^[a-zA-Z]')
  •  Tags:  
  • sql
  • Related