云数据库 GAUSSDB-DBE_RAW:示例

时间:2024-11-13 14:45:37

示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
DECLARE
v_raw RAW;
v_int INTEGER;
v_length INTEGER;
v_str VARCHAR2;
v_double BINARY_DOUBLE;
v_float FLOAT4;
v_numeric NUMERIC;
v_nvarchar2 NVARCHAR2;
BEGIN
-- INTEGER类型值转RAW类型
SELECT DBE_RAW.CAST_FROM_BINARY_INTEGER_TO_RAW(170,1) INTO v_raw; -- 000000AA
SELECT DBE_RAW.CAST_FROM_BINARY_INTEGER_TO_RAW(170,2) INTO v_raw; -- AA000000
SELECT DBE_RAW.CAST_FROM_BINARY_INTEGER_TO_RAW(170,3) INTO v_raw; -- AA000000
-- RAW类型值转INTEGER类型
SELECT DBE_RAW.CAST_FROM_RAW_TO_BINARY_INTEGER(DBE_RAW.CAST_FROM_BINARY_INTEGER_TO_RAW(170,1),1) INTO v_int; -- 170
SELECT DBE_RAW.CAST_FROM_RAW_TO_BINARY_INTEGER(DBE_RAW.CAST_FROM_BINARY_INTEGER_TO_RAW(170,2),2) INTO v_int; -- 170
SELECT DBE_RAW.CAST_FROM_RAW_TO_BINARY_INTEGER(DBE_RAW.CAST_FROM_BINARY_INTEGER_TO_RAW(170,3),3) INTO v_int; -- 170
-- 求RAW类型值长度
SELECT DBE_RAW.GET_LENGTH(DBE_RAW.CAST_FROM_BINARY_INTEGER_TO_RAW(170,1)) INTO v_length; -- 4
-- VARCHAR2类型值转RAW类型
SELECT DBE_RAW.CAST_FROM_VARCHAR2_TO_RAW('AA') INTO v_raw; -- 4141
-- RAW类型值转VARCHAR2类型
SELECT DBE_RAW.CAST_TO_VARCHAR2('4141') INTO v_str; -- AA
-- RAW类型按位或
SELECT DBE_RAW.BIT_OR('0000', '1111') INTO v_raw; -- 1111
-- RAW类型取字串
SELECT DBE_RAW.SUBSTR('ABCD', 1, 2) INTO v_raw; -- ABCD
-- RAW类型按位与
SELECT DBE_RAW.BIT_AND('AFF', 'FF0B') INTO v_raw; -- 0A0B
-- RAW类型按位取反
SELECT DBE_RAW.BIT_COMPLEMENT('0AFF') INTO v_raw; -- F500
-- RAW类型按位异或
SELECT DBE_RAW.BIT_XOR('AFF', 'FF0B') INTO v_raw; -- F5F4
-- BINARY_DOUBLE类型值转RAW类型
SELECT DBE_RAW.CAST_FROM_BINARY_DOUBLE_TO_RAW(1.0001,1) INTO v_raw; -- 3FF00068DB8BAC71
-- RAW类型值转BINARY_DOUBLE类型
SELECT DBE_RAW.CAST_FROM_RAW_TO_BINARY_DOUBLE('3FF00068DB8BAC7',1) INTO v_double; -- 1.0001
-- RAW类型转FLOAT4类型
SELECT DBE_RAW.CAST_FROM_RAW_TO_BINARY_FLOAT('40200000',1) INTO v_float; -- 2.5
-- FLOAT4类型转RAW类型
SELECT DBE_RAW.CAST_FROM_BINARY_FLOAT_TO_RAW('2.5',1) INTO v_raw; -- 40200000
-- RAW类型转NUMERIC类型
SELECT DBE_RAW.CAST_FROM_RAW_TO_NUMBER('808002008813') INTO v_numeric; -- 2.5
-- NUMERIC类型转RAW类型
SELECT DBE_RAW.CAST_FROM_NUMBER_TO_RAW('2.5') INTO v_raw; -- 808002008813
-- RAW类型转NVARCHAR2类型
SELECT DBE_RAW.CAST_FROM_RAW_TO_NVARCHAR2('12345678') INTO v_nvarchar2; -- \x124Vx
-- RAW类型COMPARE
SELECT DBE_RAW.COMPARE('ABCD','AB') INTO v_numeric; -- 2
-- RAW类型CONCAT
SELECT DBE_RAW.CONCAT('ABCD','AB') INTO v_raw; -- ABCDAB
-- RAW类型CONVERT
SELECT DBE_RAW.CONVERT('E695B0', 'GBK','UTF8') INTO v_raw; -- CAFD
-- RAW类型COPIES
SELECT DBE_RAW.COPIES('ABCD',2) INTO v_raw; -- ABCDABCD
-- RAW类型指定位置和长度进行覆盖
SELECT DBE_RAW.OVERLAY('abcef', '12345678123456', 2, 5, '9966') INTO v_raw; -- 120ABCEF999956
-- RAW类型按字节翻转
SELECT DBE_RAW.REVERSE('12345678') INTO v_raw; -- 78563412
-- RAW类型字节转换(无填充码)
SELECT DBE_RAW.TRANSLATE('1122112233', '1133','55') INTO v_raw; -- 55225522
-- RAW类型字节转换(有填充码)
SELECT DBE_RAW.TRANSLITERATE('1122112233', '55','1133','FFEE') INTO v_raw; -- 55225522FF
-- RAW类型两个字节间的所有字节
SELECT DBE_RAW.XRANGE('00','03') INTO v_raw; -- 00010203
END;
/
ANONYMOUS BLOCK EXECUTE
support.huaweicloud.com/centralized-devg-v8-gaussdb/gaussdb-42-0819.html