substring function

Collecting rest of the string from 4th posting ( from left )
SELECT substring('',4); // Output is
Last 4 chars ( from right end)
SELECT substring('',-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('',3,5); // Oputput us2ne
Starting from end, from 6th position 2 ( length) chars to be collected
select substring('',-6,2); // Output is et

Using FROM to get part of string

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

Removing Last one char

select substring('',1,char_length('')-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 All rights reserved worldwide Privacy Policy Disclaimer