當前位置:首頁 » 凈水方式 » oracle過濾字元串

oracle過濾字元串

發布時間: 2021-01-25 17:11:00

① oracle如何去除字元串中的重復字元

代碼如下:

createorreplacefunctionremove_rame_string(oldStrvarchar2,signvarchar2)
returnvarchar2is

/****************************************************
**Oracle去掉重復字元串
**函數名稱:RemoveSameStr
**參數:【名稱】【類型】【說明】
**oldStrvarchar2要處理的字元串
**signvarchar2字元串分隔符
**返回值:Resultvarchar2不包含重復子串的記錄
****************************************************/
strvarchar2(2000);
currentIndexnumber;
startIndexnumber;
endIndexnumber;

typestr_typeistableofvarchar2(30)indexbybinary_integer;
arrstr_type;
Resultvarchar2(1000);
begin
--空字元串
ifoldStrisnullthen
return('');
endif;

--字元串太長
iflength(oldStr)>2000then
return(oldStr);
endif;
str:=oldStr;

currentIndex:=0;
startIndex:=0;

loop
currentIndex:=currentIndex+1;
endIndex:=instr(str,sign,1,currentIndex);
if(endIndex<=0)then
exit;
endif;

arr(currentIndex):=trim(substr(str,
startIndex+1,
endIndex-startIndex-1));
startIndex:=endIndex;
endloop;

--取最後一個字元串:
arr(currentIndex):=substr(str,startIndex+1,length(str));

--去掉重復出現的字元串:
foriin1..currentIndex-1loop
forjini+1..currentIndexloop
ifarr(i)=arr(j)then
arr(j):='';
endif;
endloop;
endloop;

str:='';
foriin1..currentIndexloop
ifarr(i)isnotnullthen
str:=str||sign||arr(i);
--數組置空:
arr(i):='';
endif;
endloop;

--去掉前面的標識符:
Result:=substr(str,2,length(str));

return(Result);
endremove_rame_string;

② oracle怎麼截取指定字元後面的字元串,或者刪除指定字元前面的字元串也行

取最後一個\後面的字元
select substr('D:\AssetsManagement\resource\ehcache\test.txt',1+(select instr ('D:\AssetsManagement\resource\ehcache\test.txt','\',1,(select length('D:\AssetsManagement\resource\ehcache\test.txt') - length(replace('D:\AssetsManagement\resource\ehcache\test.txt','\','')) from al)) from al)
,length('D:\AssetsManagement\resource\ehcache\test.txt')-(select instr ('D:\AssetsManagement\resource\ehcache\test.txt','\',1,(select length('D:\AssetsManagement\resource\ehcache\test.txt') - length(replace('D:\AssetsManagement\resource\ehcache\test.txt','\','')) from al)) from al)
) from al

如果前面D:\AssetsManagement\resource\ehcache\是固定的就直接replace了
select replace('D:\AssetsManagement\resource\ehcache\test.txt','D:\AssetsManagement\resource\ehcache\','') from al

③ oracle如何去除字元串中數字

selectreplace(translate('abc1234def678add590a','0123456789',''),'','')fromal;

④ Oracle SQL從含數字的字元串中,截取出非數字字元

這個只能祭出強大的正則表達式了,字元的正a-z A-Z ,篩選的正則表達式為regexp_substr(欄位,'.*[a-zA-z]')

⑤ oracle 自定義函數處理『過濾掉空格和其他特殊字元函數』怎麼寫

用regexp_replace這個函數根據正則表達式將特殊字元替換成空串

⑥ Oracle sql語句把欄位中的某個字元去掉

1、創建抄測試表,

create table test_date2(id int , v_date varchar(20));

⑦ Oracle怎麼用正則表達式過濾欄位中"非漢字"的所有字元

varreg=/([^復s])/g;varstr="abcdef";vararr=str.match(reg);console.error(arr);

  • 正則表達式,又稱規制則表達式。(英語:Regular Expression,在代碼中常簡寫為regex、regexp或RE),計算機科學的一個概念。正則表達式通常被用來檢索、替換那些符合某個模式(規則)的文本。

  • 許多程序設計語言都支持利用正則表達式進行字元串操作。例如,在Perl中就內建了一個功能強大的正則表達式引擎。正則表達式這個概念最初是由Unix中的工具軟體(例如sed和grep)普及開的。正則表達式通常縮寫成「regex」,單數有regexp、regex,復數有regexps、regexes、regexen。

⑧ oracle 去掉左邊的字元串

可以這樣試試
select replace(substr('00005xxxxxx',2,3),'') from 表名;

⑨ oracle,字元串查詢處理

create table test (id int, name varchar(10) )
insert into test values (1,'a')
insert into test values (1,'b')
insert into test values (1,'c')
insert into test values (2,'a')
insert into test values (2,'b')
insert into test values (3,'a')
insert into test values (3,'c')

select id,sys_connect_by_path(name,',') from (
select id,name, row_number() over(partition by id order by name)rn,
count(*) over(partition by id ) cnt from test
) a where level=cnt
start with rn=1 connect by prior id=id and prior rn=rn-1

測試後 可用。

一樓的回答其實最容易理解了。你把它修改成動態sql 就可以了。可以不受限制了。

⑩ ORACLE中怎樣用正則表達式過濾中文字元

從表裡提取漢字, 需要考慮字元集, 不同的字元集漢字的編碼有所不同
這里以GB2312為例, 寫一函數准確地從表裡提取簡體漢字.

假設資料庫字元集編碼是GB2312, 環境變數(注冊表或其它)的字元集也是GB2312編碼
並且保存到表裡的漢字也都是GB2312編碼的

那麼也就是漢字是雙位元組的,且簡體漢字的編碼范圍是
B0A1 - F7FE
換算成10進制就是
B0 A1 F7 FE
176,161 - 247,254

我們先看一下asciistr函數的定義
Non-ASCII characters are converted to the form \xxxx, where xxxx represents a UTF-16 code unit.
但是這並不表示以 "\" 開始的字元就是漢字了

舉例如下
SQL> select * from test;

NAME
--------------------
,啊OO10哈
你好aa
大家好aa/
☆大海123
★ABC

這里第5條記錄有一個實心的五角星
然後用asciistr函數轉換一下試試
SQL> select name,asciistr(name) from test;

NAME ASCIISTR(NAME)
-------------------- ----------------------
,啊OO10哈 ,\554AOO10\54C8
你好aa \4F60\597Daa
大家好aa/ \5927\5BB6\597Daa/
☆大海123 \2606\5927\6D77123
★ABC \2605ABC

我們看到最後一條記錄的實心五角星也是 "\"開頭的
此時我們就不能用asciistr(欄位)是否存在 "\" 來判斷是否含有漢字了.

我的函數如下,基本思路是判斷字元的編碼是否在GB2312規定的漢字編碼范圍之內
[PHP]
create or replace function get_chinese(p_name in varchar2) return varchar2
as
v_code varchar2(30000) := '';
v_chinese varchar2(4000) := '';
v_comma pls_integer;
v_code_q pls_integer;
v_code_w pls_integer;
begin
if p_name is not null then
select replace(substrb(mp(p_name,1010),instrb(mp(p_name,1010),'ZHS16GBK:')),'ZHS16GBK: ','') into v_code from al where rownum=1;
for i in 1..length(p_name) loop
if lengthb(substr(p_name,i,1))=2 then
v_comma := instrb(v_code,',');
v_code_q := to_number(substrb(v_code,1,v_comma-1));
v_code_w := to_number(substrb(v_code,v_comma+1,abs(instrb(v_code,',',1,2)-v_comma-1)));
if v_code_q>=176 and v_code_q<=247 and v_code_w>=161 and v_code_w<=254 then
v_chinese := v_chinese||substr(p_name,i,1);
end if;
v_code := ltrim(v_code,'1234567890');
v_code := ltrim(v_code,',');
end if;
v_code := ltrim(v_code,'1234567890');
v_code := ltrim(v_code,',');
end loop;
return v_chinese;
else
return '';
end if;
end;
/
.
[/PHP]

好,現在來執行一些語句
SQL> select * from test;

NAME
--------------------
,啊OO10哈
你好aa
大家好aa/
☆大海123
★ABC

5 rows selected.

1. 列出有漢字的記錄
SQL> select name from test where length(get_chinese(name))>0;

NAME
--------------------
,啊OO10哈
你好aa
大家好aa/
☆大海123

4 rows selected.

2. 列出有漢字的記錄,並且只列出漢字

SQL> select get_chinese(name) from test where length(get_chinese(name))>0;

GET_CHINESE(NAME)
---------------------------------------------------------------------------
啊哈
你好
大家好
大海

4 rows selected.

需要說明的是GB2312共有6763個漢字,即72*94-5=6763
我這里是計算72*94,沒有減去那5個,那五個是空的。等查到了再減去
============

改寫這個函數,可以提取非漢字或者漢字
該函數有兩個參數,第一個表示要提取的字元串,第二個是1,表示提取漢字,是非1,表示提取非漢字

[PHP]
create or replace function get_chinese
(
p_name in varchar2,
p_chinese in varchar2
) return varchar2
as
v_code varchar2(30000) := '';
v_chinese varchar2(4000) := '';
v_non_chinese varchar2(4000) := '';
v_comma pls_integer;
v_code_q pls_integer;
v_code_w pls_integer;
begin
if p_name is not null then
select replace(substrb(mp(p_name,1010),instrb(mp(p_name,1010),'ZHS16GBK:')),'ZHS16GBK: ','') into v_code from al where rownum=1;
for i in 1..length(p_name) loop
if lengthb(substr(p_name,i,1))=2 then
v_comma := instrb(v_code,',');
v_code_q := to_number(substrb(v_code,1,v_comma-1));
v_code_w := to_number(substrb(v_code,v_comma+1,abs(instrb(v_code,',',1,2)-v_comma-1)));
if v_code_q>=176 and v_code_q<=247 and v_code_w>=161 and v_code_w<=254 then
v_chinese := v_chinese||substr(p_name,i,1);
else
v_non_chinese := v_non_chinese||substr(p_name,i,1);
end if;
v_code := ltrim(v_code,'1234567890');
v_code := ltrim(v_code,',');
else
v_non_chinese := v_non_chinese||substr(p_name,i,1);
end if;
v_code := ltrim(v_code,'1234567890');
v_code := ltrim(v_code,',');
end loop;
if p_chinese = '1' then
return v_chinese;
else
return v_non_chinese;
end if;
else
return '';
end if;
end;
/

.
[/PHP]
SQL> select * from a;

NAME
--------------------
我們啊、
他(艾呀)是★們
他的\啊@

SQL> select get_chinese(name,1) from a;

GET_CHINESE(NAME,1)
-----------------------------------------
我們啊
他艾呀是們
他的啊

SQL> select get_chinese(name,0) from a;

GET_CHINESE(NAME,0)
-----------------------------------------

()★
\@

SQL>

熱點內容
丁度巴拉斯情人電影推薦 發布:2024-08-19 09:13:07 瀏覽:886
類似深水的露點電影 發布:2024-08-19 09:10:12 瀏覽:80
《消失的眼角膜》2電影 發布:2024-08-19 08:34:43 瀏覽:878
私人影院什麼電影好看 發布:2024-08-19 08:33:32 瀏覽:593
干 B 發布:2024-08-19 08:30:21 瀏覽:910
夜晚看片網站 發布:2024-08-19 08:20:59 瀏覽:440
台灣男同電影《越界》 發布:2024-08-19 08:04:35 瀏覽:290
看電影選座位追女孩 發布:2024-08-19 07:54:42 瀏覽:975
日本a級愛情 發布:2024-08-19 07:30:38 瀏覽:832
生活中的瑪麗類似電影 發布:2024-08-19 07:26:46 瀏覽:239