oracle 檢查字元中資料類型 函數&預存程序

來源:互聯網
上載者:User

標籤:turn   ora   ret   oop   rom   create   substr   roc   acl   

dump函數用來判斷字串中的字元類型是屬於number或者string

預存程序

create or replace procedure pro_isNum(I_STRING in varchar2,o_note out varchar2) as        string1 varchar2(1000);--欄位通過dump()轉換後        num1 number(20);--欄位中字元的個數        num2 number(20);--ASCII比較變數        i number(20);--迴圈累積變數 begin   IF I_String is not null then      select            ‘,‘||substr(dump(I_STRING),instr(dump(I_STRING),‘:‘)+1,length(dump(I_STRING))-instr(dump(I_STRING),‘:‘))||‘,‘           into string1 from dual;   select nvl(length(string1)-length(replace(string1,‘,‘,‘‘)),-1) into num1 from dual;     i:=1;     o_note:=‘number‘;     <<first_loop>>       loop         if i =num1 then            dbms_output.put_line(‘迴圈已結束資料類型為‘||o_note);          exit first_loop;         end if;         select to_number(substr(string1,instr(string1,‘,‘,1,i)+1,instr(string1,‘,‘,1,i+1)-instr(string1,‘,‘,1,i)-1)) into num2 from dual;         IF num2<48 or num2>57 then           o_note:=‘string‘;           return;         end IF;         i:=i+1;      end loop fst_loop;      dbms_output.put_line(‘LOOP迴圈已經結束!‘);   else     o_note:=‘null‘;   end if; end;

 

函數

create or replace function func_isNum(I_STRING in varchar2) return varchar2--傳回型別 is        string1 varchar2(1000);--欄位通過dump()轉換後        num1 number(20);--欄位中字元的個數        num2 number(20);--ASCII比較變數        i number(20);--迴圈累積變數        o_note varchar2(20);--傳回型別 begin   IF I_String is not null then      select            ‘,‘||substr(dump(I_STRING),instr(dump(I_STRING),‘:‘)+1,length(dump(I_STRING))-instr(dump(I_STRING),‘:‘))||‘,‘           into string1 from dual;   select nvl(length(string1)-length(replace(string1,‘,‘,‘‘)),-1) into num1 from dual;     i:=1;     o_note:=‘number‘;     <<first_loop>>       loop         if i =num1 then            dbms_output.put_line(‘迴圈已結束資料類型為‘||o_note);          exit first_loop;         end if;         select to_number(substr(string1,instr(string1,‘,‘,1,i)+1,instr(string1,‘,‘,1,i+1)-instr(string1,‘,‘,1,i)-1)) into num2 from dual;         IF num2<48 or num2>57 then           o_note:=‘string‘;         end IF;         i:=i+1;      end loop fst_loop;      dbms_output.put_line(‘LOOP迴圈已經結束!‘);   else     o_note:=‘null‘;   end if;   return o_note; end;

 

oracle 檢查字元中資料類型 函數&預存程序

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.