How to separate a letter from a character in SQL?

1

I have a variable of type character varying (17) and need to separate one of the characters, for example the third letter, and use it to filter.

SELECT *
FROM fnord
WHERE terceira(illuminati) = "a"
    
asked by anonymous 02.08.2018 / 14:43

2 answers

2

I think the simplest one will be (using the hint of the 3rd letter):

SELECT  *
FROM    fnord
WHERE   substr('illuminati', 3, 1) = 'a'

The first parameter is the string you want to validate, the 2nd is the index and the 3rd is the amount of characters you want to "remove" (it is optional).

    
02.08.2018 / 14:50
2

For this there is the function substr

  

substr (string, from [ count])
  substr ('alphabet', 3, 1) returns p (third position, one character)

See working in SQLFiddle

    
02.08.2018 / 14:52