Difference between revisions of "SUBSTRING"

From SQLZOO
Jump to: navigation, search
(2 intermediate revisions by one user not shown)
Line 1: Line 1:
 
<table align='right' border='1'>
 
<table align='right' border='1'>
 
<caption>Compatibility</caption>
 
<caption>Compatibility</caption>
<tr><th colspan='3'>SUBSTRING(s FROM i FOR j)</th></tr>
+
<tr><th colspan='3'>SUBSTRING(s, i, j)</th></tr>
 
<tr><td align='center'>'''Engine'''</td><td align='center'>'''OK'''</td><td align='center'>'''Alternative'''</td></tr>
 
<tr><td align='center'>'''Engine'''</td><td align='center'>'''OK'''</td><td align='center'>'''Alternative'''</td></tr>
 
<tr><td align='left'>ingres</td><td>Yes</td><td>[[SUBSTRING(ansi) |SUBSTRING(s FROM i FOR j)]]</td></tr>
 
<tr><td align='left'>ingres</td><td>Yes</td><td>[[SUBSTRING(ansi) |SUBSTRING(s FROM i FOR j)]]</td></tr>
Line 9: Line 9:
 
<tr><td align='left'>sqlserver</td><td>Yes</td><td></td></tr>
 
<tr><td align='left'>sqlserver</td><td>Yes</td><td></td></tr>
 
</table>
 
</table>
 +
 
<h1> SUBSTRING</h1>
 
<h1> SUBSTRING</h1>
 
<p>SUBSTRING allows you to extract part of a string. </p>
 
<p>SUBSTRING allows you to extract part of a string. </p>
Line 17: Line 18:
  
 
<div class='ht'>
 
<div class='ht'>
 +
In this example you get the 2nd to 5th character from each country's name. 
 
<source lang='sql' class='def e-oracle'>
 
<source lang='sql' class='def e-oracle'>
 
SELECT name,
 
SELECT name,
Line 28: Line 30:
 
</source>
 
</source>
 
</div>
 
</div>
 +
 +
{{Languages}}

Revision as of 12:02, 28 October 2012

Compatibility
SUBSTRING(s, i, j)
EngineOKAlternative
ingresYesSUBSTRING(s FROM i FOR j)
mysqlYesSUBSTRING(s FROM i FOR j)
oracleNoSUBSTR(s,i,j)
postgresYesSUBSTRING(s FROM i FOR j)
sqlserverYes

SUBSTRING

SUBSTRING allows you to extract part of a string.

   SUBSTRING('Hello world', 2, 3) -> 'llo'    

In this example you get the 2nd to 5th character from each country's name.

SELECT name,
       SUBSTR(name, 2, 5)
  FROM bbc
SELECT name,
       SUBSTRING(name, 2, 5)
  FROM bbc
Language: English  • Deutsch
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense