1. sql里如何查询一个字段里不是数字类型的值出来
select * from 表 where isnumeric(字段) = 1
isnumeric(字段),如果为数字,则返回1,如果不为数字,则返回0~~~
2. 在sql查询中如何只查该字段只包含汉字,不含其它符号、数字、英文之类的。请大神解答。
select * from 表名 where REGEXP_LIKE(列名,'[^\w]')
3. sql语句 查询 非数字字符
把数字全部转化成ascii码 然后来判断。下面是个例子。
这题给5分太少了点,呵呵。
DECLARE @position int, @string char(15),@t_num varchar(50)
DECLARE cursor_r cursor for select t_num from tab2
open cursor_r
fetch next from cursor_r into @string
begin
while @@fetch_status =0
begin
--print @string
SET @position = 1
WHILE @position <= len(@string)
BEGIN
set @t_num =ASCII(SUBSTRING(@string, @position, 1))
if @t_num<48 or @t_num>57
begin
insert into tab3 (t_num) values(@string)
break
end
SET @position = @position + 1
END
fetch next from cursor_r into @string
end
close cursor_r
deallocate cursor_r
end
这题给5分太少了点,呵呵。正好我以前写过,就无私奉上了。
4. sql:查询一个字段里面时不是全为数字
用ltrim 函数,如果提示未选定行,那么字段不全为数字,如果有返回值,那么全为数字
select 1 from al where ltrim('12385x2','0123456789') is null
5. sql查询剔除字段中的数字,只保留不含数字的文本
/*用正则表达式或者自定义函数下面是用正则表达式的代码如果报错的话,需要开启Ole Automation Proceres exec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure 'Ole Automation Proceres',1;RECONFIGURE;exec sp_configure 'show advanced options', 0;RECONFIGURE;*/--能按正则表达式替换的函数Create Function [dbo].[MyReplace](@Reg Varchar(1000),@Source Varchar(4000),@Str Varchar(1000))returns sql_variant AsBegin Declare @Err Int Declare @obj Int Declare @Rst sql_variant EXEC @Err=Sp_OACreate 'VBScript.RegExp',@obj OUTPUT If @Err<>0 GoTo LB EXEC @Err=Sp_OASetProperty @obj,'Pattern',@Reg If @Err<>0 GoTo LB EXEC @Err=Sp_OASetProperty @obj,'Global','True' If @Err<>0 GoTo LB EXEC @Err=Sp_OASetProperty @obj,'IgnoreCase','False' If @Err<>0 GoTo LB EXEC @Err=Sp_OAMethod @obj,'Replace',@Rst OUTPUT,@source,@Str If @Err<>0 GoTo LB EXEC @Err=Sp_OADestroy @obj If @Err<>0 GoTo LB Return @RstLB: EXEC Sp_OADestroy @obj RETURN NullEnd --查询(把所有数字替换为空)select dbo.myreplace('\d',字段,'') from 表
6. 用sql怎么查出某一字段中不是数字的值
写法如下:select*frommytablewherefieldlike'%查询的值%'具体替换表名和字段名
7. sql查询过滤掉数字,现表A中有一个字符串student_id字段,里面存的应该是126356546这样的字符串
/*
方案一:
把student_id不是数字的取出来,然后用是数字最大的一个student_id+记录号进行编号(这里考虑student_id是主键不能重复的情况)
然后把这个编号更新给student_id
*/
With CT
As
(
Select student_id,(Select MAX(student_id) From T
Where isnumeric(student_id)=1)+ROW_NUMBER()Over(Order By student_id)
As cnt From T
Where isnumeric(student_id)=0
)
Update CT Set student_id=cnt
/*
方案二
不是数字的id,分别把里面的字母A替换为1,B替换为2,依次
思路
把不是字母id的,按字母拆分,然后把他的Ascii-64再合并成一个字符串
最后用这个字符串更新给id
(不能保证关键是否重复)
*/
With CT
As
(
Select student_id,SUBSTRING(student_id,1,1) As Tmp,1 As LV From T Where ISNUMERIC(student_id)=0
Union All
select student_id,SUBSTRING(student_id,LV+1,1) ,LV+1 From CT Where LV<LEN(student_id)
)
Update T Set student_id=Rst
From(
Select student_id,
(Select Convert(Varchar(2),Unicode(Upper(Tmp))-64) From CT
Where student_id=A.student_id
For XML Path('')) AS Rst
FROM CT A
Group By student_id) s
Where T.student_id=s.student_id
8. sql 去除字段中非数字字符
思路:找到第二个$,更新数据为$后面的
实例:
UPDATE A
SET A.a1 = (
SUBSTR(a1, INSTR(a1, $, '2') + 1, LENGTH(a1))
)
9. sql 语句 急!!!! 数据将英文和数字去掉,只保留汉字的sql语句
1、创建测试表,
create table test_replace_str(value varchar2(200));
4、编写语句,将英文和数字去掉,只保留汉字;
select t.*, regexp_replace(value, '[a-zA-Z0-9]', '') sec
from test_replace_str t;
10. sql中查询条件语句中怎么写才能不包含数字,字母(比如姓名)
SELECT * FROM table WHERE field NOT LIKE '%[0-9a-zA-Z]%'
在SQL中,有四种模糊查询方式,即可以使用匹配方式。
%表示匹配任意
[xxx] 匹配 [ ] 之间的字符。
_ 匹配一个字符
[^ ] 表示不含 [ ] 内的字符。