單位元組處理函式

xypincle發表於2017-02-19

  1. CREATE OR REPLACE Function ZL_GetSinglebyte_string
  2. (
  3.   strValue_IN varchar2,
  4.   numValue_IN number
  5. )
  6. Return Varchar2 Is
  7.    v_temp varchar2(200);
  8.    v_return varchar2(200);
  9.    v_num number:=0;
  10.    v_sum number:=0;
  11.    idx number :=1 ;
  12.    idy number :=0 ;
  13. BEGIN
  14.   IF lengthb(strValue_IN)>=numValue_IN then
  15.       WHILE idx <= LENGTH(strValue_IN) LOOP
  16.          v_temp := SUBSTR(strValue_IN,idx,1);
  17.          v_num := v_num + lengthb(v_temp);
  18.          if v_num > numValue_IN then
  19.             v_return := v_return||substr(strValue_IN,1,idx-1)||' ';
  20.             exit;
  21.          elsif v_num = numValue_IN then
  22.             v_return := v_return||substr(strValue_IN,1,idx);
  23.             exit;
  24.          else
  25.             idx := idx + 1 ;
  26.          END IF;
  27.       END LOOP;
  28.    ELSE
  29.      v_sum := numValue_IN - LENGTHB(strValue_IN);
  30.      v_return := v_return||strValue_IN;
  31.      WHILE idy < v_sum LOOP
  32.         v_return := v_return||' ';
  33.         idy := idy + 1;
  34.      END LOOP;
  35.    END IF;
  36.    IF mod(lengthb(strValue_IN),2) = 0 then
  37.       v_return := v_return || ' |';
  38.    ELSE
  39.       v_return := v_return || '|';
  40.    END IF;
  41.    Return v_return;
  42. Exception
  43.   When Others Then
  44.     Zl_Errorcenter(Sqlcode, Sqlerrm);
  45. END ZL_GetSinglebyte_string;


  46. 建同義詞:
  47. create or replace public synonym ZL_GetSinglebyte_string
  48. for HIS.ZL_GetSinglebyte_string;
  49. ----------------------------------------------------------
  50. GRANT EXECUTE ON ZL_GetSinglebyte_string to public

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28878983/viewspace-2133891/,如需轉載,請註明出處,否則將追究法律責任。

相關文章