返回首页

gbase数据、南大通用产品文档:GBase8srfmtdouble() 函数

更新日期:2024年09月11日

rfmtdouble() 函数使用格式化掩码来将 double 值转换为字符串。

语法
mint rfmtdouble(dbl_val, fmtstring, outbuf)
double dbl_val;
char *fmtstring;
char *outbuf;
dbl_val
要格式化的 double 数值。
fmtstring
指向包含 dbl_val 中的值的格式化掩码的字符缓冲区的指针。

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 870 -

outbuf
指向接收 dbl_val 中的值的格式化的字符串的字符缓冲区的指针。

用法
rfmtdouble() 函数的 fmtstring 参数指向数值格式化掩码,其包含描述
如何格式化 double 值的字符。

当您使用 rfmtdouble() 来格式化 MONEY 值时,该函数使用 DBMONEY 环境变量
指定的货币符号。如果您未指定此环境变量,则 rfmtdouble() 使用客户机语言环境定义的
货币符号。
缺省的语言环境 US English 定义货币符号如同您将 DBMONEY 设置为
“$,.”
一样。

当您使用有多字节代码集的非缺省的语言环境时,rfmtdouble() 支持格式字符串中的
多字节字符。

返回代码
0
转换成功。
-1211
程序用尽内存(内存分配错误)。
-1217
格式字符串太大。

示例
demo 目录在文件 rfmtdouble.ec 中包含此样例程序。
/*
* rfmtdouble.ec *
The following program applies a series of format specifications to series of doubles
and displays the result of each format.
*/

#include



GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 871 -

double dbls[] =
{
210203.204,
4894,
443.334899312,
-12344455,
0
};

char *formats[] =
{
"#############",
"<,<<<,<<<,<<<",
"$$$$$$$$$$.##",
"(&&,&&&,&&&.)",
"$*********.**",
0
};

char result[41];

main()
{
mint x;
mint i = 0, f;

printf("RFMTDOUBLE Sample ESQL Program running.\n\n");

while(dbls[i]) /* for each number in dbls */
{
printf("Double Number = %g\n", dbls[i]);
f = 0;
while(formats[f]) /* format with each of formats[] */

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 872 -

{
if (x = rfmtdouble(dbls[i], formats[f], result))
{
printf("Error %d in formatting %g using %s\n",
x, dbls[i], formats[f]);
break;
}
/*
* Display each result and bump to next format (f++)
*/
result[40] = '\0';
printf(" Format String = '%s'\t", formats[f++]);
printf("\tResult = '%s'\n", result);
}
++i; /* bump to next double */
printf("\n"); /* separate result groups */
}
printf("\nRFMTDOUBLE Sample Program over.\n\n");
}
输出
RFMTDOUBLE Sample ESQL Program running.

Double Number = 210203
Format String = '#############'
Result = ' 210203'
Format String = '<,<<<,<<<,<<<'
Result = '210,203'
Format String = '$$$$$$$$$$.##'
Result = ' $210203.20'
Format String = '(&&,&&&,&&&.)'
Result = ' 000210,203. '
Format String = '$*********.**'
Result = '$***210203.20'

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 873 -


Double Number = 4894
Format String = '#############'
Result = ' 4894'
Format String = '<,<<<,<<<,<<<'
Result = '4,894'
Format String = '$$$$$$$$$$.##'
Result = ' $4894.00'
Format String = '(&&,&&&,&&&.)'
Result = ' 000004,894. '
Format String = '$*********.**'
Result = '$*****4894.00'

Double Number = 443.335
Format String = '#############'
Result = ' 443'
Format String = '<,<<<,<<<,<<<'
Result = '443'
Format String = '$$$$$$$$$$.##'
Result = ' $443.33'
Format String = '(&&,&&&,&&&.)'
Result = ' 0000000443. '
Format String = '$*********.**'
Result = '$******443.33'

Double Number = -1.23445e+07
Format String = '#############'
Result = ' 12344455'
Format String = '<,<<<,<<<,<<<'
Result = '12,344,455'
Format String = '$$$$$$$$$$.##'
Result = ' $12344455.00'
Format String = '(&&,&&&,&&&.)'

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 874 -

Result = '(12,344,455.)'
Format String = '$*********.**'
Result = '$*12344455.00'

RFMTDOUBLE Sample Program over.

如果连接管理器发出事件警报,那么会使用 GBASEDBTCMNAME 环境变量来存储发出警
报的连接管理器实例的名称。该环境变量由连接管理器自动设置。
GBASEDBTCMNAME 环境变量对应于连接管理器配置文件中的 NAME 参数。
CMALARMPROGRAM 程序使用该环境变量来确定对事件警报负责的连接管理器实例。
您也可以在自己的连接管理器事件警报处理程序中使用该环境变量。
该环境变量由连接管理器自动设置,不应进行修改。

问题现象
对多列count(distinct)改写优化。
处理方法
对多列count(distinct),当前执行计划是:

先在各节点对参与count(distinct)的列进行group by 去重,结果集再汇集到一
个节点进行count(distinct)运算;

当count(distinct)列很多时,
参与group by 运算的列也很多,
去重效果不理想,
导致大量数据要拉到一个节点进行count(distinct)运算,拉表和汇总节点计算
耗时非常长;

优化的方法是改写sql,各列分别计算count(distinct),提高去重效果,然后对
结果集进行拼接。
示例

优化前
select count(distinct col1), count(distinct col2) from tb;

GBase 8a MPP Cluster 最佳实践
5 FAQ
文档版本(2022-02-11)
南大通用数据技术股份有限公司
115

优化后
select * from
(select count(distinct col1) from tb) a
join
(select count(distinct col2) from tb) b;