Difference between revisions of "SUBSTR"

From SQLZOO
Jump to: navigation, search
(Created page with "<table align='right' border='1'> <caption>Compatibility</caption> <tr><th colspan='3'>SUBSTRING(s FROM i FOR j)</th></tr> <tr><td align='center'>'''Engine'''</td><td align='ce...")
 
 
(4 intermediate revisions by 2 users 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'>SUBSTR(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>
 +
<tr><td align='left'>mysql</td><td>Yes</td><td>[[SUBSTRING(ansi) |SUBSTRING(s FROM i FOR j)]]</td></tr>
 
<tr><td align='left'>oracle</td><td>Yes</td><td></td></tr>
 
<tr><td align='left'>oracle</td><td>Yes</td><td></td></tr>
 
<tr><td align='left'>postgres</td><td>Yes</td><td>[[SUBSTRING(ansi) |SUBSTRING(s FROM i FOR j)]]</td></tr>
 
<tr><td align='left'>postgres</td><td>Yes</td><td>[[SUBSTRING(ansi) |SUBSTRING(s FROM i FOR j)]]</td></tr>
 
<tr><td align='left'>sqlserver</td><td>No</td><td>[[SUBSTRING |SUBSTRING(s,i,j)]]</td></tr>
 
<tr><td align='left'>sqlserver</td><td>No</td><td>[[SUBSTRING |SUBSTRING(s,i,j)]]</td></tr>
 
</table>
 
</table>
 +
 
<h1> SUBSTR</h1>
 
<h1> SUBSTR</h1>
 
<p>SUBSTR allows you to extract part of a string. </p>
 
<p>SUBSTR allows you to extract part of a string. </p>
 
<p></p>  
 
<p></p>  
 
<pre style='width:75ex'>
 
<pre style='width:75ex'>
   SUBSTR('Hello world', 2, 3) -> 'llo'     
+
   SUBSTR('Hello world', 2, 3) -> 'ell'     
 
</pre>
 
</pre>
  
 
<div class='ht'>
 
<div class='ht'>
In this example you put the region and the name together for each country.   
+
In this example you get the 2nd to 5th character from each country's name.   
<source lang='sql' class='def e-oracle e-sqlserver'>
+
<source lang='sql' class='def e-sqlserver'>
 
SELECT name,
 
SELECT name,
 
       SUBSTRING(name, 2, 5)
 
       SUBSTRING(name, 2, 5)
Line 29: Line 31:
 
</source>
 
</source>
 
</div>
 
</div>
 +
 +
{{Languages}}

Latest revision as of 01:16, 25 March 2013

Compatibility
SUBSTR(s, i, j)
EngineOKAlternative
ingresYesSUBSTRING(s FROM i FOR j)
mysqlYesSUBSTRING(s FROM i FOR j)
oracleYes
postgresYesSUBSTRING(s FROM i FOR j)
sqlserverNoSUBSTRING(s,i,j)

SUBSTR

SUBSTR allows you to extract part of a string.

   SUBSTR('Hello world', 2, 3) -> 'ell'    

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

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

Variants
Actions
Reference
Toolbox
Google AdSense