oracle判斷是否為數(shù)字的方法 oracle sql判斷是否數(shù)字?
oracle sql判斷是否數(shù)字?可以用oracle自帶的正則表達(dá)式函數(shù)REGEXP_REPLACE把數(shù)字全部取出來(lái),然后計(jì)算數(shù)字的長(zhǎng)度是否等于這個(gè)字段的長(zhǎng)度,如果等于的話說(shuō)明這個(gè)值全部是數(shù)字,如果不
oracle sql判斷是否數(shù)字?
可以用oracle自帶的正則表達(dá)式函數(shù)REGEXP_REPLACE把數(shù)字全部取出來(lái),然后計(jì)算數(shù)字的長(zhǎng)度是否等于這個(gè)字段的長(zhǎng)度,如果等于的話說(shuō)明這個(gè)值全部是數(shù)字,如果不等于的話說(shuō)明值里面包含非數(shù)字,測(cè)試語(yǔ)句如下:SELECT(REGEXP_REPLACE("LSS12345","[^0-9]"))FROMDUAL---取出值里面的全部數(shù)字SELECTLENGTH("LSS12345"),LENGTH(REGEXP_REPLACE("LSS12345","[^0-9]"))FROMDUAL---查詢(xún)出字段的長(zhǎng)度和字段內(nèi)數(shù)字的長(zhǎng)度SELECT*FROMDUAL WHERELENGTH("LSS12345")=LENGTH(REGEXP_REPLACE("LSS12345","[^0-9]")) ----查詢(xún)這個(gè)字段所有的純數(shù)字列
oracle如何判定是數(shù)字還是字符?
用正則表達(dá)式:ORACLE查出列為純數(shù)字的值:SELECT* FROM DUAL WHERE LENGTH("LSS12345") = LENGTH(REGEXP_REPLACE("LSS12345", "[^0-9]"))
Oracle中如何判斷字符串是否全為數(shù)字?
額,正好以前寫(xiě)過(guò)一個(gè)oracle本身沒(méi)有,得自定義一個(gè)函數(shù)create or replace function isNumber(p in varchar2)return numberisresult numberbeginresult := to_number(p)return 1exceptionwhen VALUE_ERROR then return 0end調(diào)用select isNumber("abc123") from dual或者select isNumber("123") from dual返回值為1,說(shuō)明是數(shù)字,返回值是0,說(shuō)明里邊包含非數(shù)字的字符
oracle如何判斷某個(gè)字段的值是不是數(shù)字?
1、創(chuàng)建測(cè)試表,
create table test_isnum(id number, value varchar2(20))
2、插入測(cè)試數(shù)據(jù),
insert into test_isnum values(1,"a")
insert into test_isnum values(2,329)
insert into test_isnum values(4,"15")
insert into test_isnum values(6,"2c")
commit
3、查詢(xún)表中所有記錄,select t.*, rowid from test_isnum t,
4、編寫(xiě)sql,判斷value字段,記錄為數(shù)字的內(nèi)容,
select t.*,
case
when not regexp_like(value, "D") then
"是"
else
"否"
end as "是否數(shù)字"
from test_isnum t
在oracle中,如何用一條select語(yǔ)句查詢(xún)字段中非純數(shù)字值?
--1.正則判斷,適用于10g以上版本--非正整數(shù) select 字段 from 表 where regexp_replace(字段,"d","") is not null--非數(shù)值類(lèi)型select 字段 from 表 where regexp_replace(字段,"^[- ]?d (.d )?$","") is not null--2.自定義函數(shù),判斷非值類(lèi)型create or replace function isnumber(col varchar2) return integer is i numberbegin i := to_number(col) return 1exception when others then return 0endselect 字段 from 表 where isnumber(字段)=0