Asked 2 years ago
31 May 2022
Views 602
jignesh

jignesh posted

how to use function POSITION in MySQL?

how to use POSITION in MySQL ? can you please explain function POSITION in MySQL with some example?
iPhone-coder

iPhone-coder
answered Jun 2 '22 00:00

POSITION() function can search case insensitive so it means it finds the given string or character without caring of lowercase or upper case

  SELECT POSITION("RA" IN "array") AS matcheindex; 

so RA is upper case and tries to find in all lower case string "array" but still it finds and returns index.
so in other words:
POSITION("RA" IN "array") is equal to POSITION("ra" IN "array")
sachin

sachin
answered Jun 2 '22 00:00

POSITION() function can be used find string /character in the given string or word .
POSITION() return :
if found in given string , POSITION() returns the index in string where given character or string is found
if not found in given string , POSITION() returns 0


 SELECT POSITION("r" IN "array") AS matcheindex; 

at above query POSITION try to find "r" character in "array" and it return 2


 SELECT POSITION("0" IN "array") AS matcheindex; 

at above query POSITION try to find "0" character in "array" and it does not found that so it return 0

andy

andy
answered Jun 2 '22 00:00

POSITION() function and LOCATE() function are both identical in functionality in MySQL, but they have diffrent syntax.


 SELECT POSITION("r" IN "array") AS matcheindex; 
 SELECT LOCATE("r" ,"array") AS matcheindex; 

above both query return same but they have diffrent syntax LOCATE dont use IN ,it use , instead of IN.
Post Answer