create or replace
FUNCTION "BINTOTEN" (strbin in varchar2) return NUMBER
IS
decvalue NUMBER(10);
binlen NUMBER(10);
indexa NUMBER(10);
currbit CHAR;
BEGIN
binlen := LENGTH(strbin);
decvalue := 0;
indexa := 0;
WHILE indexa < binlen LOOP
indexa := indexa + 1;
currbit := SUBSTR(strbin, indexa, 1);
IF (currbit != '0' AND currbit != '1') THEN
decvalue := -1;
ELSE
decvalue := decvalue * 2;
IF(currbit = '1') THEN
decvalue := decvalue + POWER(2, 0);
END IF;
END IF;
END LOOP;
RETURN decvalue;
END BINTOTEN;
oracle数据库二进制转十进制函数
最新推荐文章于 2021-06-03 23:55:14 发布