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

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

WBOY
WBOYOriginal
2016-06-07 17:48:122129browse

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

Statement:
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