Difference between revisions of "INSTR"
From SQLZOO
| Line 9: | Line 9: | ||
<tr><td align='left'>sqlserver</td><td>No</td><td>[[PATINDEX |PATINDEX('%'+s2+'%',s1)]]</td></tr> | <tr><td align='left'>sqlserver</td><td>No</td><td>[[PATINDEX |PATINDEX('%'+s2+'%',s1)]]</td></tr> | ||
</table> | </table> | ||
| + | |||
<h1>INSTR</h1> | <h1>INSTR</h1> | ||
<p>INSTR(s1, s2) returns the character position of the substring s2 within the larger string s1. The first character is in position 1. If s2 does not occur in s1 it returns 0. </p> | <p>INSTR(s1, s2) returns the character position of the substring s2 within the larger string s1. The first character is in position 1. If s2 does not occur in s1 it returns 0. </p> | ||
| Line 42: | Line 43: | ||
<li>[[RIGHT |RIGHT function]]</li> | <li>[[RIGHT |RIGHT function]]</li> | ||
</ul> | </ul> | ||
| + | |||
| + | {{Languages}} | ||
Revision as of 20:30, 22 October 2012
| INSTR(s1, s2) | ||
|---|---|---|
| Engine | OK | Alternative |
| ingres | No | POSITION(s2 IN s1) |
| mysql | Yes | |
| oracle | Yes | |
| postgres | No | POSITION(s2 IN s1) |
| sqlserver | No | PATINDEX('%'+s2+'%',s1) |
INSTR
INSTR(s1, s2) returns the character position of the substring s2 within the larger string s1. The first character is in position 1. If s2 does not occur in s1 it returns 0.
INSTR('Hello world', 'll') -> 3
In this example you get the hour from the datetime field whn.
SELECT name, POSITION('an' IN name) FROM bbc
SELECT name, PATINDEX('%an%', name) FROM bbc ORDER BY name
SELECT name, INSTR(name, 'an') FROM bbc
See also
| Language: | English • Deutsch |
|---|