SQL Substring
SQL 中的 substring 函数是用来抓出一个栏位资料中的其中一部分。这个函数的名称在不同的资料库中不完全一样:
MySQL: SUBSTR(), SUBSTRING()
Oracle: SUBSTR()
SQL Server: SUBSTRING()
最常用到的方式如下 (在这里我们用SUBSTR()为例):
SUBSTR(str,pos): 由<str>中,选出所有从第<pos>位置开始的字元。请注意,这个语法不适用于SQL Server上。
SUBSTR(str,pos,len): 由<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'
例2:
SELECT SUBSTR(store_name,2,4)
from Geography
WHERE store_name = 'San Diego';
结果:
'an D'
相关文档:
1. 说明:复制表(只复制结构,源表名:a,新表名:b)
SQL: select * into b from a where 1<>1;
2. 说明:拷贝表(拷贝数据,源表名:a,目标表名:b)
SQL: insert into b(a, b, c) select d, e, f from b;
&nb ......
SQL注入攻击是黑客对数据库进行攻击的常用手段之一。随着B/S模式应用开发的发展,使用这种模式编写应用程序的程序员也越来越多。但是由于程序员的水平及经验也参差不齐,相当大一部分程序员在编写代码的时候,没有对用户输入数据的合法性进行判断,使应用程序存在安全隐患。用户可以提交一段数据库查询代码,根据程序 ......
create table #a
(
a int identity(1,1) primary key,
b int default(0) not null,
c nvarchar(20)
)
insert into #a(c)
select 'a' union all
select 'b' union all
select 'c' union all
select 'd' union all
select 'e'
select * from #a
alter table #a drop constraint DF__#a_____________b__12 ......
update CHELIANG_MINGDAN set clmd_yunxuzaizhong = cast(clmd_yunxuzaizhong/1000 as decimal(14,4)) where clmd_yunxuzaizhong is not null
update CHELIANG_MINGDAN set clmd_carweight = cast(clmd_carweight/1000 as decimal(14,4)) where clmd_carweight is not null ......