當前位置:首頁 » 編程語言 » sql不含數字
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

sql不含數字

發布時間: 2022-05-20 14:34:59

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] 匹配 [ ] 之間的字元。
_ 匹配一個字元
[^ ] 表示不含 [ ] 內的字元。