Difference between revisions of "SUBSTRING(ansi)"

From SQLZOO
Jump to: navigation, search
 
(One intermediate revision by one user not shown)
Line 14: Line 14:
 
<p></p>  
 
<p></p>  
 
<pre style='width:75ex'>
 
<pre style='width:75ex'>
   SUBSTRING('Hello world' FROM 2 FOR 3) -> 'llo'     
+
   SUBSTRING('Hello world' FROM 2 FOR 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-oracle e-sqlserver'>
 
SELECT name,
 
SELECT name,

Latest revision as of 09:28, 24 March 2013

Compatibility
SUBSTRING(s FROM i FOR j)
EngineOKAlternative
ingresYesSUBSTRING(s,i,j)
mysqlYes
oracleNoSUBSTR(s,i,j)
postgresYesSUBSTRING(s,i,j)
sqlserverNoSUBSTRING(s,i,j)

SUBSTRING (ansi)

SUBSTRING allows you to extract part of a string.

   SUBSTRING('Hello world' FROM 2 FOR 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
SELECT name,
       SUBSTRING(name FROM 2 FOR 5)
  FROM bbc

See also

Language: English  • Deutsch
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense