substring function

Collecting rest of the string from 4th posting ( from left )
SELECT substring('plus2net.com',4); // Output is s2net.com
Last 4 chars ( from right end)
SELECT substring('plus2net.com',-4); // Output is is .com

With optional parameter length

Let us add number of chars we will get by adding length

Starting from 3rd position 5 chars to be collected
SELECT substring('plus2net.com',3,5); // Oputput us2ne
Starting from end, from 6th position 2 ( length) chars to be collected
select substring('plus2net.com',-6,2); // Output is et

Using FROM to get part of string

Rest of the string from a position
SELECT SUBSTRING('plus2net.com' FROM 3)  // Ouptut is us2net.com
From right ( end ) starting from 7 position return 3 chars (length)
SELECT SUBSTRING('plus2net.com' FROM -7 FOR 3) // Output is net

Removing Last one char

select substring('plus2net.com',1,char_length('plus2net.com')-1)
Use this code in our student table.
SELECT id,substring(class,1,char_length(class)-1) as class FROM student

Substring and substring_index

Substring returns part of string by taking position ( number ) as input. If the position is not known and to use a specific delimiter for searching, then substring_index function can be used.

How substring is used to collect domain part of Email address

Your Rating




Post Comment This is for short comments only. Use the forum for more discussions.








HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer