How to use SQL substring () string intercept function

Source: Internet
Author: User
Tags how to use sql

The substring function in SQL is used to grab a portion of a field data. The name of this function is not exactly the same in different repositories:

Mysql:substr (), SUBSTRING ()
Oracle:substr ()
SQL server:substring ()
The most commonly used approach is as follows (here we use substr () as an example):

SUBSTR (Str,pos): From <str>, select all characters starting from <pos> position. Note that this syntax is not available on SQL Server.

SUBSTR (Str,pos,len): Starting from <pos> position in <str>, the next <len> characters are selected.


SELECT
SUBSTR (course_designater,6,3) as "COURSE number"
From courses
WHERE course_designater like ' excel% '

Example Two

SELECT
UPPER (SUBSTR (lastname,1,1)) | | LOWER (SUBSTR (lastname,2,29))
As "Lastname"
From Students

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.