Home > Database > Mysql Tutorial > sql substring()字符串截取函数的使用方法

sql substring()字符串截取函数的使用方法

WBOY
Release: 2016-06-07 17:48:12
Original
2174 people have browsed it

SQL 中的 substring 函数是用来抓出一个栏位资料中的其中一部分。这个函数的名称在不同的资料库中不完全一样:

MySQL: SUBSTR(), SUBSTRING()
Oracle: SUBSTR()
SQL Server: SUBSTRING()
最常用到的方式如下 (在这里我们用SUBSTR()为例):

SUBSTR(str,pos): 由中,选出所有从第位置开始的字元。请注意,这个语法不适用于SQL Server上。

SUBSTR(str,pos,len): 由中的第位置开始,选出接下去的个字元。


SELECT 
        SUBSTR(COURSE_DESIGNATER,6,3) as "Course number"                  
FROM    COURSES
WHERE   COURSE_DESIGNATER LIKE 'Excel%'

实例二

SELECT
  UPPER(SUBSTR(lastname,1,1)) || LOWER(SUBSTR(lastname,2,29))
  AS "Lastname"
FROM Students

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template