知识大全 在Oracle中实现数字进制转换完全版
Posted 字符
篇首语:有志者自有千计万计,无志者只感千难万难。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 在Oracle中实现数字进制转换完全版相关的知识,希望对你有一定的参考价值。
在Oracle中实现数字进制转换完全版 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!
以下内容包括 ) 提供两个进制转换包 ) 提供进制转换的一些简便方法 ) 提供进制转换的不同方法的性能评估 两个进制转换包 )包PKG_DM_BASE_CONV(推荐) CREATE OR REPLACE PACKAGE PKG_DM_BASE_CONV AS FUNCTION hex_to_dec (hexnum IN char) RETURN NUMBER; PRAGMA restrict_references (HEX_TO_DEC WNDS); FUNCTION dec_to_hex (N IN NUMBER) RETURN VARCHAR ; PRAGMA restrict_references (DEC_TO_HEX WNDS); FUNCTION oct_to_dec (octin IN NUMBER) RETURN NUMBER; PRAGMA restrict_references (OCT_TO_DEC WNDS); FUNCTION dec_to_oct (decin IN NUMBER) RETURN VARCHAR ; PRAGMA restrict_references (DEC_TO_OCT WNDS); FUNCTION bin_to_dec (binin IN NUMBER) RETURN NUMBER; PRAGMA restrict_references (BIN_TO_DEC WNDS); FUNCTION dec_to_bin (decin IN NUMBER) RETURN VARCHAR ; PRAGMA restrict_references (DEC_TO_BIN WNDS); FUNCTION hex_to_bin (hexin IN VARCHAR ) RETURN NUMBER; PRAGMA restrict_references (HEX_TO_BIN WNDS); FUNCTION bin_to_hex (binin IN NUMBER) RETURN VARCHAR ; PRAGMA restrict_references (BIN_TO_HEX WNDS); FUNCTION oct_to_bin (octin IN NUMBER) RETURN NUMBER; PRAGMA restrict_references (OCT_TO_BIN WNDS); FUNCTION bin_to_oct (binin IN NUMBER) RETURN NUMBER; PRAGMA restrict_references (BIN_TO_OCT WNDS); FUNCTION oct_to_hex (octin IN NUMBER) RETURN VARCHAR ; PRAGMA restrict_references (OCT_TO_HEX WNDS); FUNCTION hex_to_oct (hexin IN VARCHAR ) RETURN NUMBER; PRAGMA restrict_references (HEX_TO_OCT WNDS); 十六进制字符转换成ASCII码字符 FUNCTION raw_to_char(v_raw LONG RAW) RETURN VARCHAR ; PRAGMA restrict_references (raw_to_char WNDS); ASCII码字符转换成十六进制字符 FUNCTION char_to_raw(v_char varchar ) RETURN LONG RAW; PRAGMA restrict_references (char_to_raw WNDS); END PKG_DM_BASE_CONV; / CREATE OR REPLACE PACKAGE BODY PKG_DM_BASE_CONV AS FUNCTION hex_to_dec (hexnum in char) RETURN NUMBER IS i NUMBER; digits NUMBER; result NUMBER := ; current_digit char( ); current_digit_dec number; BEGIN digits := length(hexnum); FOR i IN digits LOOP current_digit := SUBSTR(hexnum i ); IF current_digit IN ( A B C D E F ) THEN current_digit_dec := ascii(current_digit) ascii( A ) + ; ELSE current_digit_dec := to_number(current_digit); END IF; result := (result * ) + current_digit_dec; END LOOP; RETURN result; END hex_to_dec; FUNCTION dec_to_hex (N IN NUMBER) RETURN VARCHAR IS H VARCHAR ( ) := ; N INTEGER := N; BEGIN LOOP SELECT rawtohex(chr(N ))||H INTO H FROM dual; N := trunc(N / ); EXIT WHEN N = ; END LOOP; RETURN H; END dec_to_hex; FUNCTION oct_to_dec (octin IN NUMBER) RETURN NUMBER IS v_charpos NUMBER; v_charval CHAR( ); v_return NUMBER DEFAULT ; v_power NUMBER DEFAULT ; v_string VARCHAR ( ); BEGIN v_string := TO_CHAR(octin); v_charpos := LENGTH(v_string); WHILE v_charpos > LOOP v_charval := SUBSTR(v_string v_charpos ); IF v_charval BEEEN AND THEN v_return := v_return + TO_NUMBER(v_charval) * POWER( v_power); ELSE raise_application_error( Invalid input ); END IF; v_charpos := v_charpos ; v_power := v_power + ; END LOOP; RETURN v_return; END oct_to_dec; FUNCTION dec_to_oct (decin IN NUMBER) RETURN VARCHAR IS v_decin NUMBER; v_next_digit NUMBER; v_result varchar( ); BEGIN v_decin := decin; WHILE v_decin > LOOP v_next_digit := mod(v_decin ); v_result := to_char(v_next_digit) || v_result; v_decin := floor(v_decin / ); END LOOP; RETURN v_result; END dec_to_oct; FUNCTION bin_to_dec (binin IN NUMBER) RETURN NUMBER IS v_charpos NUMBER; v_charval CHAR( ); v_return NUMBER DEFAULT ; v_power NUMBER DEFAULT ; v_string VARCHAR ( ); BEGIN v_string := TO_CHAR(binin); v_charpos := LENGTH(v_string); WHILE v_charpos > LOOP v_charval := SUBSTR(v_string v_charpos ); IF v_charval BEEEN AND THEN v_return := v_return + TO_NUMBER(v_charval) * POWER( v_power); ELSE raise_application_error( Invalid input ); END IF; v_charpos := v_charpos ; v_power := v_power + ; END LOOP; RETURN v_return; END bin_to_dec; FUNCTION dec_to_bin (decin IN NUMBER) RETURN VARCHAR IS v_decin NUMBER; v_next_digit NUMBER; v_result varchar( ); BEGIN v_decin := decin; WHILE v_decin > LOOP v_next_digit := mod(v_decin ); v_result := to_char(v_next_digit) || v_result; v_decin := floor(v_decin / ); END LOOP; RETURN v_result; END dec_to_bin; FUNCTION hex_to_bin (hexin IN VARCHAR ) RETURN NUMBER IS BEGIN RETURN dec_to_bin(hex_to_dec(hexin)); END hex_to_bin; FUNCTION bin_to_hex (binin IN NUMBER) RETURN VARCHAR IS BEGIN RETURN dec_to_hex(bin_to_dec(binin)); END bin_to_hex; FUNCTION oct_to_bin (octin IN NUMBER) RETURN NUMBER IS BEGIN RETURN dec_to_bin(oct_to_dec(octin)); END oct_to_bin; FUNCTION bin_to_oct (binin IN NUMBER) RETURN NUMBER IS BEGIN RETURN dec_to_oct(bin_to_dec(binin)); END bin_to_oct; FUNCTION oct_to_hex (octin IN NUMBER) RETURN VARCHAR IS BEGIN RETURN dec_to_hex(oct_to_dec(octin)); END oct_to_hex; FUNCTION hex_to_oct (hexin IN VARCHAR ) RETURN NUMBER IS BEGIN RETURN dec_to_oct(hex_to_dec(hexin)); END hex_to_oct; FUNCTION raw_to_char(v_raw LONG RAW) RETURN VARCHAR IS rawlen NUMBER; hex VARCHAR ( ); rawparam VARCHAR ( ); i NUMBER; BEGIN hex := rawtohex(v_raw); rawlen := length(hex); i := ; WHILE i <= rawlen LOOP rawparam := rawparam||CHR(hex_to_dec(substrb(hex i ))); i := i + ; END LOOP; RETURN rawparam; END raw_to_char; FUNCTION char_to_raw(v_char varchar ) RETURN LONG RAW IS rawdata LONG RAW; rawlen NUMBER; hex VARCHAR ( ); i NUMBER; BEGIN rawlen := length(v_char); i := ; WHILE i <= rawlen LOOP hex := dec_to_hex(ascii(substrb(v_char i ))); rawdata := rawdata || HEXTORAW(hex); i := i + ; END LOOP; RETURN rawdata; END; END PKG_DM_BASE_CONV; / cha138/Article/program/Oracle/201311/18388相关参考
CREATEORREPLACETYPEtype_str_aggASOBJECT ( totalVARCHAR() STATICFUNCTIONodciaggregateinitialize(
下列四个不同数字表示的数中,数值最大的是_____。A、二进制数11011101B、八进制数334C、十进制数219D、十六进制数DA答案:A解析:将选项中的数转换成二进制后比较,A项为1101110
在Oracle中实现各种日期处理完全版 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! TO_DA
转换进制中的8421码怎么用四位二进制相当于一位十六进制(8421)三位二进制相当于一位八进制(421)如101011转十六进制从右开始匹配(十六进制用8421)零不计1010112821每四位相加得
进制中的位权是什么意思?最好举几个例子1、在各种数制(无论是二进制,十进制、十六进制等)中,各位数字所表示值的大小不仅与该数字本身的大小有关,还与该数字所在的位置有关,我们称这关系为数的位权。2、拿十
将Image图像文件存入到数据库中我们知道数据库里的Image类型的数据是二进制数据因此必须将图像文件转换成字节数组才能存入数据库中 &nbs
java中IP地址转换十进制数实现代码 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 先看实例
RHEL3上安装Oracle9.2.0完全版 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 安装
C#16进制转换10进制 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! //十进制转二进制 C
用SQL实现其他进制到十进制的转换 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 本文主要讲解了