SUBSTRING() : Part of the string from input position

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
using concat()
SELECT CONCAT(SUBSTRING('Hello, world!', 1, 5), SUBSTRING('Hello, world!', -6)); -- Output: 'Helloworld!'

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
SQL String References substring_index to get part of string using delimiter
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    SQL Video Tutorials

    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer