日期:2014-05-16  浏览次数:20462 次

oracle 进制之间转换
CREATE OR REPLACE TYPE type_str_agg AS OBJECT
(
  total VARCHAR2(4000),

  STATIC FUNCTION odciaggregateinitialize(sctx IN OUT type_str_agg)
    RETURN NUMBER,

  MEMBER FUNCTION odciaggregateiterate
  (
    SELF  IN OUT type_str_agg,
    VALUE IN VARCHAR2
  ) RETURN NUMBER,

  MEMBER FUNCTION odciaggregateterminate
  (
    SELF        IN type_str_agg,
    returnvalue OUT VARCHAR2,
    flags       IN NUMBER
  ) RETURN NUMBER,

  MEMBER FUNCTION odciaggregatemerge
  (
    SELF IN OUT type_str_agg,
    ctx2 IN type_str_agg
  ) RETURN NUMBER
)
/
CREATE OR REPLACE TYPE BODY type_str_agg IS

  STATIC FUNCTION odciaggregateinitialize(sctx IN OUT type_str_agg)
    RETURN NUMBER IS
  BEGIN
    sctx := type_str_agg(NULL);
    RETURN odciconst.success;
  END;

  MEMBER FUNCTION odciaggregateiterate
  (
    SELF  IN OUT type_str_agg,
    VALUE IN VARCHAR2
  ) RETURN NUMBER IS
  BEGIN
    SELF.total := SELF.total || VALUE;
    RETURN odciconst.success;
  END;

  MEMBER FUNCTION odciaggregateterminate
  (
    SELF        IN type_str_agg,
    returnvalue OUT VARCHAR2,
    flags       IN NUMBER
  ) RETURN NUMBER IS
  BEGIN
    returnvalue := SELF.total;
    RETURN odciconst.success;
  END;

  MEMBER FUNCTION odciaggregatemerge
  (
    SELF IN OUT type_str_agg,
    ctx2 IN type_str_agg
  ) RETURN NUMBER IS
  BEGIN
    SELF.total := SELF.total || ctx2.total;
    RETURN odciconst.success;
  END;

END;
/




CREATE OR REPLACE FUNCTION f_stragg(p_input VARCHAR2) RETURN VARCHAR2
  PARALLEL_ENABLE
  AGGREGATE USING type_str_agg;
/


CREATE OR REPLACE PACKAGE pkg_number_trans IS

  FUNCTION f_bin_to_oct(p_str IN VARCHAR2) RETURN VARCHAR2;
 
  FUNCTION f_bin_to_dec(p_str IN VARCHAR2) RETURN VARCHAR2;
 
  FUNCTION f_bin_to_hex(p_str IN VARCHAR2) RETURN VARCHAR2;

  FUNCTION f_oct_to_bin(p_str IN VARCHAR2) RETURN VARCHAR2;
 
  FUNCTION f_oct_to_dec(p_str IN VARCHAR2) RETURN VARCHAR2;

  FUNCTION f_oct_to_hex(p_str IN VARCHAR2) RETURN VARCHAR2;
 
  FUNCTION f_hex_to_bin(p_str IN VARCHAR2) RETURN VARCHAR2;

  FUNCTION f_hex_to_oct(p_str IN VARCHAR2) RETURN VARCHAR2;

  FUNCTION f_hex_to_dec(p_str IN VARCHAR2) RETURN VARCHAR2;
 
  FUNCTION f_dec_to_bin(p_int IN VARCHAR2) RETURN VARCHAR2;

  FUNCTION f_dec_to_oct(p_int IN VARCHAR2) RETURN VARCHAR2;

  FUNCTION f_dec_to_hex(p_int IN VARCHAR2) RETURN VARCHAR2;
 
END pkg_number_trans;
/
CREATE OR REPLACE PACKAGE BODY pkg_number_trans IS


  FUNCTION f_bin_to_oct(p_str IN VARCHAR2) RETURN VARCHAR2 IS
    ----------------------------------------------
    -- 对象名称: f_bin_to_oct
    -- 对象描述: 二进制转换八进制
    -- 输入参数: p_str 二进制字符串