知识大全 oracle进制之间转换
Posted 知
篇首语:书到用时方恨少,事非经过不知难。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 oracle进制之间转换相关的知识,希望对你有一定的参考价值。
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 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 VARCHAR
) RETURN NUMBER IS
BEGIN
SELF total := SELF total || VALUE;
RETURN odciconst success;
END;
MEMBER FUNCTION odciaggregateterminate
(
SELF IN type_str_agg
returnvalue OUT VARCHAR
flags IN NUMBER
) RETURN NUMBER IS
BEGIN
returnvalue := SELF total;
RETURN odciconst success;
END;
MEMBER FUNCTION odciaggregatemerge
(
SELF IN OUT type_str_agg
ctx IN type_str_agg
) RETURN NUMBER IS
BEGIN
SELF total := SELF total || ctx total;
RETURN odciconst success;
END;
END;
/
CREATE OR REPLACE FUNCTION f_stragg(p_input VARCHAR ) RETURN 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 ) RETURN VARCHAR ;
FUNCTION f_bin_to_dec(p_str IN VARCHAR ) RETURN VARCHAR ;
FUNCTION f_bin_to_hex(p_str IN VARCHAR ) RETURN VARCHAR ;
FUNCTION f_oct_to_bin(p_str IN VARCHAR ) RETURN VARCHAR ;
FUNCTION f_oct_to_dec(p_str IN VARCHAR ) RETURN VARCHAR ;
FUNCTION f_oct_to_hex(p_str IN VARCHAR ) RETURN VARCHAR ;
FUNCTION f_hex_to_bin(p_str IN VARCHAR ) RETURN VARCHAR ;
FUNCTION f_hex_to_oct(p_str IN VARCHAR ) RETURN VARCHAR ;
FUNCTION f_hex_to_dec(p_str IN VARCHAR ) RETURN VARCHAR ;
FUNCTION f_dec_to_bin(p_int IN VARCHAR ) RETURN VARCHAR ;
FUNCTION f_dec_to_oct(p_int IN VARCHAR ) RETURN VARCHAR ;
FUNCTION f_dec_to_hex(p_int IN VARCHAR ) RETURN VARCHAR ;
END pkg_number_trans;
/
CREATE OR REPLACE PACKAGE BODY pkg_number_trans IS
FUNCTION f_bin_to_oct(p_str IN VARCHAR ) RETURN VARCHAR IS
对象名称: f_bin_to_oct
对象描述: 二进制转换八进制
输入参数: p_str 二进制字符串
返回结果: 八进制字符串
测试用例: SELECT pkg_number_trans f_bin_to_oct( ) FROM dual;
备 注: 需要定义f_stragg函数和type_str_agg类型
v_return VARCHAR ( );
v_bin VARCHAR ( );
BEGIN
v_bin := substr( || p_str * ceil(length(p_str) / ));
SELECT f_stragg(data ) INTO v_return
FROM (SELECT (CASE upper(substr(v_bin (rownum ) * + ))
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
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 ) RETURN VARCHAR IS
对象名称: f_bin_to_dec
对象描述: 二进制转换十进制
输入参数: p_str 二进制字符串
返回结果: 十进制字符串
测试用例: SELECT pkg_number_trans f_bin_to_dec( ) FROM dual;
v_return VARCHAR ( );
BEGIN
SELECT SUM(data ) INTO v_return
FROM (SELECT substr(p_str rownum ) * power( length(p_str) rownum) data
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 ) RETURN VARCHAR IS
对象名称: f_bin_to_hex
对象描述: 二进制转换十六进制
输入参数: p_str 二进制字符串
返回结果: 十六进制字符串
测试用例: SELECT pkg_number_trans f_bin_to_oct( ) FROM dual;
备 注: 需要定义f_stragg函数和type_str_agg类型
v_return VARCHAR ( );
v_bin VARCHAR ( );
BEGIN
v_bin := substr( || p_str * ceil(length(p_str) / ));
SELECT f_stragg(data ) INTO v_return
FROM (SELECT (CASE upper(substr(v_bin (rownum ) * + ))
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN A
WHEN THEN B
WHEN THEN C
WHEN THEN D
WHEN THEN E
WHEN THEN F
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 ) RETURN VARCHAR IS
对象名称: f_oct_to_bin
对象描述: 八进制转换二进制
输入参数: p_str 八进制字符串
返回结果: 二进制字符串
测试用例: SELECT pkg_number_trans f_oct_to_bin( ) FROM dual;
备 注: 需要定义f_stragg函数和type_str_agg类型
v_return VARCHAR ( );
BEGIN
SELECT to_char(to_number(f_stragg(data ))) INTO v_return
FROM (SELECT (CASE upper(substr(p_str rownum ))
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
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 ) RETURN VARCHAR IS
对象名称: f_oct_to_dec
对象描述: 八进制转换十进制
输入参数: p_str 八进制字符串
返回结果: 十进制字符串
测试用例: SELECT pkg_number_trans f_oct_to_dec( ) FROM dual;
v_return VARCHAR ( );
BEGIN
SELECT SUM(data ) INTO v_return
FROM (SELECT substr(p_str rownum ) * power( length(p_str) rownum) data
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 ) RETURN VARCHAR IS
对象名称: f_oct_to_bin
对象描述: 八进制转换十六进制
输入参数: p_str 八进制字符串
返回结果: 十六进制字符串
测试用例: SELECT pkg_number_trans f_oct_to_hex( ) FROM dual;
v_return VARCHAR ( );
v_bin VARCHAR ( );
BEGIN
SELECT pkg_number_trans f_oct_to_bin(p_str) INTO v_bin FROM dual;
SELECT pkg_number_trans f_bin_to_hex(v_bin) INTO v_return FROM dual;
RETURN v_return;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END f_oct_to_hex;
FUNCTION f_dec_to_bin(p_int IN VARCHAR ) RETURN VARCHAR IS
对象名称: f_dec_to_bin
对象描述: 十进制转换二进制
输入参数: p_str 十进制字符串
返回结果: 二进制字符串
测试用例: SELECT pkg_number_trans f_dec_to_bin( ) FROM dual;
v_return VARCHAR ( );
v_hex VARCHAR ( );
BEGIN
SELECT pkg_number_trans f_dec_to_hex(p_int) INTO v_hex FROM dual;
SELECT pkg_number_trans f_hex_to_bin(v_hex) INTO v_return FROM dual;
RETURN v_return;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END f_dec_to_bin;
FUNCTION f_dec_to_oct(p_int IN VARCHAR ) RETURN VARCHAR IS
对象名称: f_dec_to_oct
对象描述: 十进制转换八进制
输入参数: p_str 十进制字符串
返回结果: 八进制字符串
测试用例: SELECT pkg_number_trans f_dec_to_oct( ) FROM dual;
v_return VARCHAR ( );
v_bin VARCHAR ( );
BEGIN
SELECT pkg_number_trans f_dec_to_bin(p_int) INTO v_bin FROM dual;
v_bin := substr( || v_bin * ceil(length(v_bin) / ));
SELECT f_stragg(data ) INTO v_return
FROM (SELECT (CASE upper(substr(v_bin (rownum ) * + ))
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
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 ) RETURN VARCHAR IS
对象名称: f_dec_to_oct
对象描述: 十进制转换十六进制
输入参数: p_str 十进制字符串
返回结果: 十六进制字符串
测试用例: SELECT pkg_number_trans f_dec_to_hex( ) FROM dual;
v_return VARCHAR ( );
BEGIN
SELECT upper(TRIM(to_char(p_int xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ))) INTO v_return FROM dual;
RETURN v_return;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END f_dec_to_hex;
FUNCTION f_hex_to_bin(p_str IN VARCHAR ) RETURN VARCHAR IS
对象名称: f_dec_to_oct
对象描述: 十六进制转换二进制
输入参数: p_str 十六进制字符串
返回结果: 二进制字符串
测试用例: SELECT pkg_number_trans f_hex_to_oct( A ) FROM dual;
v_return VARCHAR ( );
BEGIN
SELECT to_char(to_number(f_stragg(data ))) INTO v_return
FROM (SELECT (CASE upper(substr(p_str rownum ))
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
WHEN THEN
WHEN A THEN
WHEN B THEN
WHEN C THEN
WHEN D THEN
WHEN E THEN
WHEN F THEN
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 ) RETURN VARCHAR IS
对象名称: f_dec_to_oct
对象描述: 十六进制转换八进制
输入参数: p_str 十六进制字符串
返回结果: 八进制字符串
测试用例: SELECT pkg_number_trans f_hex_to_oct( A ) FROM dual;
v_return VARCHAR ( );
v_bin VARCHAR ( );
BEGIN
SELECT pkg_number_trans f_hex_to_bin(p_str) INTO v_bin FROM dual;
SELECT pkg_number_trans f_bin_to_oct(v_bin) INTO v_return FROM dual;
RETURN v_return;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END f_hex_to_oct;
FUNCTION f_hex_to_dec(p_str IN VARCHAR ) RETURN VARCHAR IS
对象名称: f_hex_to_dec
对象描述: 十六进制转换十进制
输入参数: p_str 十六进制字符串
返回结果: 十进制字符串
测试用例: SELECT pkg_number_trans f_hex_to_dec( A ) FROM dual;
v_return VARCHAR ( );
BEGIN
SELECT SUM(data ) INTO v_return
FROM (SELECT (CASE upper(substr(p_str rownum ))
WHEN A THEN
WHEN B THEN
WHEN C THEN
WHEN D THEN
WHEN E THEN
WHEN F THEN
ELSE substr(p_str rownum )
END) * power( length(p_str) rownum) data
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;
cha138/Article/program/Oracle/201311/18912相关参考
在Oracle中实现数字进制转换完全版 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 以下内容包
C#16进制转换10进制 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! //十进制转二进制 C
转换进制中的8421码怎么用四位二进制相当于一位十六进制(8421)三位二进制相当于一位八进制(421)如101011转十六进制从右开始匹配(十六进制用8421)零不计1010112821每四位相加得
用SQL实现其他进制到十进制的转换 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 本文主要讲解了
C#:把其他进制的数转换为十进制 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 问题 你有一个
将Image图像文件存入到数据库中我们知道数据库里的Image类型的数据是二进制数据因此必须将图像文件转换成字节数组才能存入数据库中 &nbs
java中IP地址转换十进制数实现代码 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 先看实例
希赛教育计算机专业考研专业课辅导招生 希赛教育计算机专业考研专业课辅导视频 希赛教育计算机考研专业课在线测试系统 十进制数N和其他d进制数的转换是计算机实现计算的基本问题其解决方法很多其中一
八进制中,为什么16-7=7?八进制中的16=14(十进制),换算:16=1*8+6=14(十进制)。自然14-7=7八进制中345=2进制中多少你好,很高兴为你解答,345是八进制转换10进制229
在oracle中有个大对象(lobs)类型可用分别是blobclobbfilenclob 下面是对lob数据类型的简单介绍 lblob:二进制lob为二进制数据最长可达GB存贮在数据库中 l