作者在 2010-02-26 17:56:06 发布以下内容
INSTR(x, find_string [, start] [, occurrence])
Searches for find_string in x and returns the position at which find_string occurs. You can supply an optional start position to begin the search. Also, you can supply an optional occurrence that indicates which occurrence of find_string should be returned.
查询指定字符串(find_string)在目标字符串(x)中的位置,相当于java中的String类函数:indexOf()
eg1:
SELECT name, INSTR(name, 'Science')
FROM products
WHERE product_id = 1;
NAME INSTR(NAME,'SCIENCE')
------------------------------ ---------------------
Modern Science 8
eg2:
SELECT name, INSTR(name, 'e', 1, 2) FROM products WHERE product_id = 1; NAME INSTR(NAME,'E',1,2) ------------------------------ ------------------- Modern Science 11