• sql 工具类function


    --判断是否为整数
    create or replace function is_number(param VARCHAR2) return NUMBER is
      v_num NUMBER;
    begin
      v_num := to_number(NVL(param,'a'));
      RETURN 0;
    EXCEPTION
      WHEN OTHERS THEN
        RETURN 1;
    end is_number; 
    
    --判断是否为日期类型
    create or replace function is_date(param VARCHAR2) return NUMBER  is
      v_date Date;
    begin
      v_date := TO_DATE(NVL(param, 'a'), 'yyyy-mm-dd hh24:mi:ss');
      RETURN 0;
    EXCEPTION
      WHEN OTHERS THEN
        RETURN 1;
    end is_date;
    
    --去除空格
    create or replace function getStringValue(text IN varchar2) RETURN varchar2 IS
    begin
       RETURN to_single_byte(replace(text, ' ', '')) ;
    EXCEPTION
       WHEN NO_DATA_FOUND THEN
         RETURN '';
        WHEN OTHERS THEN
         RETURN '';
    end getStringValue;
    
    ----
    create or replace function getWzkf(wzkf IN varchar2) RETURN varchar2 IS
    v_wzkf varchar2(10) ;
    begin
       --去掉去掉两头空格
       v_wzkf := ltrim(rtrim(wzkf)) ;
       IF v_wzkf = ''
       THEN
          SELECT REPLACE(v_wzkf,'','0') into v_wzkf  FROM dual;
       ELSIF  v_wzkf = '/'
       THEN
              SELECT REPLACE(v_wzkf,'/','0') into v_wzkf  FROM dual;
       ELSIF  v_wzkf IS NULL
       THEN
             v_wzkf := '0' ;
       ELSE
              SELECT REPLACE(v_wzkf,'','') into v_wzkf  FROM dual;
        END IF;
       RETURN v_wzkf ;
    EXCEPTION
       WHEN NO_DATA_FOUND THEN
         RETURN '';
        WHEN OTHERS THEN
         RETURN '';
    end getWzkf;
    
    ---
    create or replace function specDate(wzkf IN varchar2) RETURN varchar2 IS
    v_wzkf varchar2(10) ;
    cLength number;
    v_date date ;
    begin
    
        v_wzkf := replace(replace(replace(wzkf,'', '-'),'','-'),'',' ') ;
        v_wzkf := ltrim(rtrim(v_wzkf)) ;
        v_wzkf := replace(v_wzkf,'/','-') ;
        v_wzkf := replace(v_wzkf,'.','-') ;
    
        select length(v_wzkf) into cLength from dual;
        if(cLength=8 and instr(v_wzkf,'-')<1 )
            THEN
            SELECT substr(v_wzkf, 1,4 )||'-'||substr(v_wzkf, 5,2 )||'-'||substr(v_wzkf, 7,2 ) into v_wzkf FROM dual;
        END IF ;
    
    --    v_date := to_char(to_date(v_wzkf,'yyyy-mm-dd'),'yyyy-mm-dd') ;
        RETURN to_char(to_date(v_wzkf,'yyyy-mm-dd'),'yyyy-mm-dd') ;
    
    EXCEPTION
       WHEN NO_DATA_FOUND THEN
         RETURN  '@@@111';
        WHEN OTHERS THEN
         RETURN  '@@@222';
    
    end specDate;
    ---
    select instr('ewew点e',''from dual
  • 相关阅读:
    pr 打印函数
    list to tree(记录集转换为树结构)
    iOS 中计时器的使用心得
    iOS动画开发----打分 数字滚动刷新动画
    iOS动画开发----粒子系统---彩带效果
    Touch Up Inside not working with UISlider
    Xcode警告:Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0
    iOS评论App----常用时间的处理
    获取文件/文件系统属性的方法----attributesOfItemAtPath:和attributesOfFileSystemForPath:
    NSInvocation错误
  • 原文地址:https://www.cnblogs.com/yy123/p/5274829.html
Copyright © 2020-2023  润新知