云数据库 GaussDB-DBE_UTILITY:示例

时间:2025-01-26 10:48:54

示例

  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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99100101102103104105106107108109110111112113114115116117
CREATE OR REPLACE PROCEDURE test_get_time1() ASdeclare    start_time  bigint;    end_time  bigint;BEGIN    start_time:= dbe_utility.get_time ();    pg_sleep(1);    end_time:=dbe_utility.get_time ();    dbe_output.print_line(end_time - start_time); END;/CREATE PROCEDURE-- 给表名字符串做规范declare    cname varchar2(50);begin    dbe_utility.canonicalize('seg1', cname, 50);    dbe_output.put_line(cname);end;/-- 预期结果为:SEG1ANONYMOUS BLOCK EXECUTE-- 将输入的字符串转换成一个表名的数组  DECLARE tab_list VARCHAR2(100) := 't1,t2'; len BINARY_INTEGER; tab varchar2[];BEGIN dbe_output.put_line('table list is :' || tab_list); dbe_utility.comma_to_table(tab_list, len, tab);END;/-- 预期结果为:table list is: t1,t2ANONYMOUS BLOCK EXECUTE-- 查看数据库的版本号和兼容性版本号declare    v_version varchar2;begin    dbe_utility.db_version(v_version);    v_version:=left(v_version, 8);    dbe_output.print_line('version:' || v_version); end;/-- 预期结果为:version:gaussdb ANONYMOUS BLOCK EXECUTE-- 查看当前CPU处理时间的测量值DECLARE    cputime NUMBER;BEGIN    cputime := dbe_utility.get_cpu_time;    dbe_output.put_line('cpu time:' || cputime);END;/-- 预期结果为(数值并非固定):cpu time9851ANONYMOUS BLOCK EXECUTE-- 获取数据库所在平台字节序的大小端信息BEGIN    dbe_output.PUT_LINE(dbe_utility.GET_ENDIANNESS);END;/-- 预期结果为:2ANONYMOUS BLOCK EXECUTE-- 获取一个给定字符串的hash值DECLARE    result NUMBER(28);BEGIN    result := dbe_utility.get_hash_value('hello',10,10);    dbe_output.put_line(result);END;/-- 预期结果为:11ANONYMOUS BLOCK EXECUTE-- 判断当前数据库是否为集群模式DECLARE    is_cluster BOOLEAN;BEGIN    is_cluster := dbe_utility.IS_CLUSTER_DATABASE;    dbe_output.put_line('CLUSTER DATABASE: ' || CASE WHEN is_cluster THEN 'TRUE' ELSE 'FALSE' END);END;/-- 预期结果为:CLUSTER DATABASE: FALSEANONYMOUS BLOCK EXECUTE-- 获取当前用户环境下的数据库模式名称DECLARE    schm varchar2(100);BEGIN    schm := dbe_utility.old_current_schema;    dbe_output.put_line('current schema: ' || schm);END;/-- 预期结果为(结果为当前数据库的模式名,并非固定):current schema: publicANONYMOUS BLOCK EXECUTE-- 获取当前用户名称select dbe_utility.old_current_user from sys_dummy;-- 预期结果为(结果为当前数据库的用户名,并非固定): old_current_user ------------------ admin(1 row)
support.huaweicloud.com/centralized-devg-v3-gaussdb/gaussdb-42-0781.html