Click(Link,My Playing Station)

substring 函数

Posted on 2007-12-19 12:58  倒骑驴的人生  阅读(426)  评论(0)    收藏  举报
SQL 中的 substring 函数是用来抓出一个栏位资料中的其中一部分。这个函数的名称在不同的资料库中不完全一样:

MySQL: SUBSTR(), SUBSTRING()
Oracle: SUBSTR()
SQL Server: SUBSTRING()


最常用到的方式如下 (在这里我们用SUBSTR()为例):

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

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

假设我们有以下的表格:

Geography 表格

region_name
store_name
East Boston
East New York
West Los Angeles
West San Diego

例1:

SELECT SUBSTR(store_name, 3) FROM Geography WHERE store_name = 'Los Angeles';

结果:

's Angeles'

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3

Click(Link,My Playing Station)