一些有用的函式
工作當中用到的一些有用的函式,記錄如下:
1、判斷輸入是否是數字:
CREATE OR REPLACE FUNCTION fun_isnumber (parmin VARCHAR2)
RETURN NUMBER
IS
val NUMBER;
BEGIN
val := TO_NUMBER (NVL (parmin, 'a'));
RETURN 1;
EXCEPTION
WHEN OTHERS THEN
RETURN 0;
END;
2、判斷輸入是否是手機號碼:
create or replace function fun_IsMobile(
vcSource in varchar2
) return number is
Result number;
begin
if vcSource is null then
Result := 0;
else
if length(vcSource)<>11 then
Result := 0;
else
if fun_IsNumber(vcSource)=0 then
Result := 0;
else
if substr(vcSource,1,1)<>'1' then
Result := 0;
else
Result := 1;
end if;
end if;
end if;
end if;
return(Result);
end fun_IsMobile;
3、ip地址轉換:
create or replace function ip_convert(strip in String) return integer
as
ip1 varchar2(10);
ip2 varchar2(10);
ip3 varchar2(10);
ip4 varchar2(10);
temp varchar2(20);
result integer;
begin
temp:=strip;
ip1:=SUBSTR(temp, 1,INSTR (temp, '.', 1,1)-1);
ip2:= substr(temp,INSTR (temp, '.', 1,1)+1,INSTR (temp, '.', 1,2)-length(ip1)-2 ) ;
ip3:= substr(temp,INSTR (temp, '.', 1,2)+1,INSTR (temp, '.', 1,3)-length(ip1)-length(ip2)-3 ) ;
ip4:= substr(temp,INSTR (temp, '.', 1,3)+1,length(temp)-length(ip1)-length(ip2)-4 ) ;
result:=to_number(ip1)*256*256*256+to_number(ip2)*256*256+to_number(ip3)*256+to_number(ip4);
return(result);
end ip_convert;
4、隨機生成指定長度的字串(字母+數字):
create or replace function fun_gen_pass return varchar2 is
v varchar2(6);
vChar varchar2(50);
n number(2);
r number(10);
t number(2);
begin
vChar := 'ABCDEFGHIJKLMNPQRSTUVWXYZ123456789';
n := 1;
loop
r := trunc(dbms_random.value*34);
if r>=1 and r<=34 then
v := v||substr(vChar,r,1);
n := n+1;
end if;
if n=7 then
select count(*)
into t
from m_club_pass
where pass=v;
if t>0 then
n := 1;
v := '';
end if;
end if;
exit when n=7;
end loop;
return v;
end;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25618347/viewspace-714081/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- php的一些函式PHP函式
- 一些有用的Python庫Python
- 一些有用的網站網站
- 一些有用的連結
- 專案裡的一些小函式函式
- 2 分鐘,瞭解 4 個極為有用的 MetricsQL 函式SQL函式
- 總結一些常用的陣列函式陣列函式
- 關於虛擬函式的一些理解函式
- 關於 Math.random 的一些函式random函式
- 有關字串的一些好用的小函式字串函式
- ES6的一些有用的小特性
- pycuda-一些計算函式函式
- mysql練習 —— 關於一些函式的使用MySql函式
- hive常用的一些高階函式彙總Hive函式
- 一些功能性函式使用整理函式
- 一些很實用util工具函式函式
- c++一些常見的內建函式(字串)C++函式字串
- win11安裝後一些有用的操作
- 初學 PHP 對於回撥函式的一些理解PHP函式
- 對jquery原始碼中 clean函式的一些體會jQuery原始碼函式
- Python常見的一些面試題,太有用啦!Python面試題
- main函式的入口函式AI函式
- js中filter()函式,以及一些去重方法JSFilter函式
- 【Python從入門到精通】(十一)Python的函式的方方面面【收藏下來保證有用!!!】Python函式
- [持續更新]——關於C++的一些可能會常用的函式C++函式
- 箭頭函式、簡寫函式、普通函式的區別函式
- Angular 14 inject 函式使用過程中的一些注意事項Angular函式
- MySQL函式大全(字串函式,數學函式,日期函式,系統級函式,聚合函式)MySql函式字串
- Sql 中的 left 函式、right 函式SQL函式
- 閉包函式(匿名函式)的理解函式
- Rust中的into函式和from函式Rust函式
- 函式: 函式是怎麼使用的?函式
- 最近在 Vue 專案中用到的一些小技巧,或許有用Vue
- Kotlin一些十分有用的方法(run、let、with、apply、also、repeat)KotlinAPP
- python內建函式-eval()函式與exec()函式的區別Python函式
- python中id()函式、zip()函式、map()函式、lamda函式Python函式
- Python 擴充之特殊函式(lambda 函式,map 函式,filter 函式,reduce 函式)Python函式Filter
- 《基於MVC的javascript web富應用開發》中的一些函式MVCJavaScriptWeb函式
- 英文簡歷中關於專案經驗的一些有用的例子