CREATE OR REPLACE TYPE type_str_agg AS OBJECT
(
total VARCHAR
STATIC FUNCTION odciaggregateinitialize(sctx IN OUT type_str_agg)
RETURN NUMBER
MEMBER FUNCTION odciaggregateiterate
(
SELF IN OUT type_str_agg
VALUE IN VARCHAR
) RETURN NUMBER
MEMBER FUNCTION odciaggregateterminate
(
SELF IN type_str_agg
returnvalue OUT VARCHAR
flags IN NUMBER
) RETURN NUMBER
MEMBER FUNCTION odciaggregatemerge
(
SELF IN OUT type_str_agg
ctx
) 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
END;
MEMBER FUNCTION odciaggregateiterate
(
SELF IN OUT type_str_agg
VALUE IN VARCHAR
) RETURN NUMBER IS
BEGIN
SELF
RETURN odciconst
END;
MEMBER FUNCTION odciaggregateterminate
(
SELF IN type_str_agg
returnvalue OUT VARCHAR
flags IN NUMBER
) RETURN NUMBER IS
BEGIN
returnvalue := SELF
RETURN odciconst
END;
MEMBER FUNCTION odciaggregatemerge
(
SELF IN OUT type_str_agg
ctx
) RETURN NUMBER IS
BEGIN
SELF
RETURN odciconst
END;
END;
/
CREATE OR REPLACE FUNCTION f_stragg(p_input VARCHAR
PARALLEL_ENABLE
AGGREGATE USING type_str_agg;
/
CREATE OR REPLACE PACKAGE pkg_number_trans IS
FUNCTION f_bin_to_oct(p_str IN VARCHAR
FUNCTION f_bin_to_dec(p_str IN VARCHAR
FUNCTION f_bin_to_hex(p_str IN VARCHAR
FUNCTION f_oct_to_bin(p_str IN VARCHAR
FUNCTION f_oct_to_dec(p_str IN VARCHAR
FUNCTION f_oct_to_hex(p_str IN VARCHAR
FUNCTION f_hex_to_bin(p_str IN VARCHAR
FUNCTION f_hex_to_oct(p_str IN VARCHAR
FUNCTION f_hex_to_dec(p_str IN VARCHAR
FUNCTION f_dec_to_bin(p_int IN VARCHAR
FUNCTION f_dec_to_oct(p_int IN VARCHAR
FUNCTION f_dec_to_hex(p_int IN VARCHAR
END pkg_number_trans;
/
CREATE OR REPLACE PACKAGE BODY pkg_number_trans IS
FUNCTION f_bin_to_oct(p_str IN VARCHAR
v_return VARCHAR
v_bin VARCHAR
BEGIN
v_bin := substr(
SELECT f_stragg(data
FROM (SELECT (CASE upper(substr(v_bin
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
END) data
FROM dual
CONNECT BY rownum <= length(v_bin) /
RETURN v_return;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END f_bin_to_oct;
FUNCTION f_bin_to_dec(p_str IN VARCHAR
v_return VARCHAR
BEGIN
SELECT SUM(data
FROM (SELECT substr(p_str
FROM dual
CONNECT BY rownum <= length(p_str));
RETURN v_return;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END f_bin_to_dec;
FUNCTION f_bin_to_hex(p_str IN VARCHAR
v_return VARCHAR
v_bin VARCHAR
BEGIN
v_bin := substr(
SELECT f_stragg(data
FROM (SELECT (CASE upper(substr(v_bin
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
END) data
FROM dual
CONNECT BY rownum <= length(v_bin) /
RETURN v_return;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END f_bin_to_hex;
FUNCTION f_oct_to_bin(p_str IN VARCHAR
v_return VARCHAR
BEGIN
SELECT to_char(to_number(f_stragg(data
FROM (SELECT (CASE upper(substr(p_str
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
END) data
FROM dual
CONNECT BY rownum <= length(p_str));
RETURN v_return;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END f_oct_to_bin;
FUNCTION f_oct_to_dec(p_str IN VARCHAR
v_return VARCHAR
BEGIN
SELECT SUM(data
FROM (SELECT substr(p_str
FROM dual
CONNECT BY rownum <= length(p_str));
RETURN v_return;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END f_oct_to_dec;
FUNCTION f_oct_to_hex(p_str IN VARCHAR
v_return VARCHAR
v_bin VARCHAR
BEGIN
SELECT pkg_number_trans
SELECT pkg_number_trans
RETURN v_return;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END f_oct_to_hex;
FUNCTION f_dec_to_bin(p_int IN VARCHAR
v_return VARCHAR
v_hex VARCHAR
BEGIN
SELECT pkg_number_trans
SELECT pkg_number_trans
RETURN v_return;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END f_dec_to_bin;
FUNCTION f_dec_to_oct(p_int IN VARCHAR
v_return VARCHAR
v_bin VARCHAR
BEGIN
SELECT pkg_number_trans
v_bin := substr(
SELECT f_stragg(data
FROM (SELECT (CASE upper(substr(v_bin
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
END) data
FROM dual
CONNECT BY rownum <= length(v_bin) /
RETURN v_return;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END f_dec_to_oct;
FUNCTION f_dec_to_hex(p_int IN VARCHAR
v_return VARCHAR
BEGIN
SELECT upper(TRIM(to_char(p_int
RETURN v_return;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END f_dec_to_hex;
FUNCTION f_hex_to_bin(p_str IN VARCHAR
v_return VARCHAR
BEGIN
SELECT to_char(to_number(f_stragg(data
FROM (SELECT (CASE upper(substr(p_str
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
END) data
FROM dual
CONNECT BY rownum <= length(p_str));
RETURN v_return;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END f_hex_to_bin;
FUNCTION f_hex_to_oct(p_str IN VARCHAR
v_return VARCHAR
v_bin VARCHAR
BEGIN
SELECT pkg_number_trans
SELECT pkg_number_trans
RETURN v_return;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END f_hex_to_oct;
FUNCTION f_hex_to_dec(p_str IN VARCHAR
v_return VARCHAR
BEGIN
SELECT SUM(data
FROM (SELECT (CASE upper(substr(p_str
WHEN
WHEN
WHEN
WHEN
WHEN
WHEN
ELSE substr(p_str
END) * power(
FROM dual
CONNECT BY rownum <= length(p_str));
RETURN v_return;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END f_hex_to_dec;
END pkg_number_trans;
/
From:http://tw.wingwit.com/Article/program/Oracle/201311/18912.html