CREATE OR REPLACE PROCEDURE CONVERT_16_10 /*16进制转10进制,双字节算法实现*/ ( I_DATA VARCHAR2, O_DATA OUT VARCHAR2 ) AS V_TMP_BEGIN INT; V_TMP_LEN INT; V_TMP_VAL INT := 0; V_TMP_TEXT VARCHAR2(1); V_TMP_DATA VARCHAR2(100); BEGIN IF I_DATA IS NULL THEN RETURN; ELSE V_TMP_BEGIN := 1; V_TMP_LEN := LENGTH(I_DATA); IF V_TMP_LEN > 8 THEN RETURN; END IF; IF V_TMP_LEN = 1 AND I_DATA = '0' THEN O_DATA := '0'; RETURN; END IF; END IF; WHILE V_TMP_BEGIN <= V_TMP_LEN LOOP V_TMP_TEXT := SUBSTR(I_DATA, V_TMP_BEGIN, 1); IF V_TMP_TEXT NOT IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F') THEN RETURN; END IF; IF V_TMP_TEXT = '1' THEN V_TMP_DATA := V_TMP_DATA || '0001 '; ELSIF V_TMP_TEXT = '2' THEN V_TMP_DATA := V_TMP_DATA || '0010 '; ELSIF V_TMP_TEXT = '3' THEN V_TMP_DATA := V_TMP_DATA || '0011 '; ELSIF V_TMP_TEXT = '4' THEN V_TMP_DATA := V_TMP_DATA || '0100 '; ELSIF V_TMP_TEXT = '5' THEN V_TMP_DATA := V_TMP_DATA || '0101 '; ELSIF V_TMP_TEXT = '6' THEN V_TMP_DATA := V_TMP_DATA || '0110 '; ELSIF V_TMP_TEXT = '7' THEN V_TMP_DATA := V_TMP_DATA || '0111 '; ELSIF V_TMP_TEXT = '8' THEN V_TMP_DATA := V_TMP_DATA || '1000 '; ELSIF V_TMP_TEXT = '9' THEN V_TMP_DATA := V_TMP_DATA || '1001 '; ELSIF V_TMP_TEXT = 'A' THEN V_TMP_DATA := V_TMP_DATA || '1010 '; ELSIF V_TMP_TEXT = 'B' THEN V_TMP_DATA := V_TMP_DATA || '1011 '; ELSIF V_TMP_TEXT = 'C' THEN V_TMP_DATA := V_TMP_DATA || '1100 '; ELSIF V_TMP_TEXT = 'D' THEN V_TMP_DATA := V_TMP_DATA || '1101 '; ELSIF V_TMP_TEXT = 'E' THEN V_TMP_DATA := V_TMP_DATA || '1110 '; ELSIF V_TMP_TEXT = 'F' THEN V_TMP_DATA := V_TMP_DATA || '1111 '; ELSE V_TMP_DATA := V_TMP_DATA || '0000 '; END IF; V_TMP_BEGIN := V_TMP_BEGIN + 1; END LOOP; O_DATA := REPLACE(V_TMP_DATA, ' ', ''); IF LENGTH(O_DATA) = 32 THEN -- 初始值要么为0,要么为最小值 V_TMP_VAL := TO_NUMBER(SUBSTR(O_DATA, 1, 1)) * POWER(2, 31) * -1; -- 重新初始化字符串对象 O_DATA := SUBSTR(O_DATA, 2); END IF; V_TMP_BEGIN := 1; V_TMP_LEN := LENGTH(O_DATA); WHILE V_TMP_BEGIN <= V_TMP_LEN LOOP IF SUBSTR(O_DATA, V_TMP_BEGIN, 1) = '1' THEN V_TMP_VAL := V_TMP_VAL + POWER(2, V_TMP_LEN - V_TMP_BEGIN); END IF; V_TMP_BEGIN := V_TMP_BEGIN + 1; END LOOP; O_DATA := TO_CHAR(V_TMP_VAL); END;
oracle16进制转10进制,双字节算法实现,优化后
猜你喜欢
转载自laz383310051.iteye.com/blog/1921788
今日推荐
周排行