返回首页

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

更新日期:2024年09月11日

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

语法
mint rfmtdec(dec_val, fmtstring, outbuf)
dec_t *dec_val;
char *fmtstring;

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 865 -
char *outbuf;
dec_val
指向要格式化的 decimal 值的指针。
fmtstring
指向包含要用于 dec_val 值的格式化掩码的字符缓冲区的指针。
outbuf
指向接收 dec_val 值的格式化的字符串的字符缓冲区的指针。

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

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

当您使用有多字节代码集的非缺省的语言环境时,
rfmtdec() 支持格式字符串中的多字
节字符。
返回代码
0
转换成功。
-1211
程序用尽内存(内存分配错误)。
-1217
格式字符串太大。

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

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

#include

EXEC SQL include decimal;

char *strings[] =
{
"210203.204",
"4894",
"443.334899312",
"-12344455",
0
};

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

char result[41];

main()
{
mint x;
mint s = 0, f;
dec_t num;

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

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

while(strings[s])
{
/*
* Convert each string to DECIMAL
*/
printf("String = %s\n", strings[s]);
if (x = deccvasc(strings[s], strlen(strings[s]), #))
{
printf("Error %d in converting string [%s] to decimal\n",
x, strings[s]);
break;
}
f = 0;
while(formats[f])
{
/*
* Format DECIMAL num for each of formats[f]
*/
rfmtdec(#, formats[f], result);
/*
* Display result and bump to next format (f++)
*/
result[40] = '\0';
printf(" Format String = '%s'\t", formats[f++]);
printf("\tResult = '%s'\n", result);
}
++s; /* bump to next string */
printf("\n"); /* separate result groups */
}

printf("\nRFMTDEC Sample Program over.\n\n");
}

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

输出
RFMTDEC Sample ESQL Program running.

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

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

String = 443.334899312
Format String = '**###########'
Result = ' ** 443'
Format String = '$$$$$$$$$$.##'
Result = ' $443.33'

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 869 -
Format String = '(&&,&&&,&&&.)'
Result = ' 0000000443. '
Format String = '<,<<<,<<<,<<<'
Result = ' 443'
Format String = ' $*********.**'
Result = '$******443.33'

String = -12344455
Format String = '**###########'
Result = ' ** 12344455'
Format String = '$$$$$$$$$$.##'
Result = ' $12344455.00'
Format String = '(&&,&&&,&&&.)'
Result = '(12,344,455.)'
Format String = '<,<<<,<<<,<<<'
Result = '12,344,455'
Format String = ' $*********.**'
Result = ' $*12344455.00'

RFMTDEC Sample Program over.

ifx_int8cmp() 函数比较两个 int8 类型数值。
语法
mint ifx_int8cmp(n1, n2)
ifx_int8_t *n1;
ifx_int8_t *n2;
n1
指向包含要比较的第一个数值的 int8 结构的指针。
n2
指向包含要比较的第二个数值的 int8 结构的指针。

返回代码
-1
第一个值小于第二个值。
0
两个值相同。

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

1
第一个值大于第二个值。
INT8UNKNOWN
有的值为空。

示例
demo 目录中的文件 int8cmp.ec 包含下列示例程序。
/*
* ifx_int8cmp.ec *
The following program compares INT8t types and displays
the results.
*/

#include

EXEC SQL include "int8.h";

char string1[] = "-999,888,777,666";
char string2[] = "-12,345,678,956,546";
char string3[] = "123,456,780,555,224,456";
char string4[] = "123,456,780,555,224,456";
char string5[] = "";

main()
{
mint x;
ifx_int8_t num1, num2, num3, num4, num5;

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

if (x = ifx_int8cvasc(string1, strlen(string1), &num1))
{

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

printf("Error %d in converting string1 to int8\n", x);
exit(1);
}
if (x = ifx_int8cvasc(string2, strlen(string2), &num2))
{
printf("Error %d in converting string2 to int8\n", x);
exit(1);
}
if (x = ifx_int8cvasc(string3, strlen(string3), &num3))
{
printf("Error %d in converting string3 to int8\n", x);
exit(1);
}
if (x = ifx_int8cvasc(string4, strlen(string4), &num4))
{
printf("Error %d in converting string4 to int8\n", x);
exit(1);
}
if (x = ifx_int8cvasc(string5, strlen(string5), &num5))
{
printf("Error %d in converting string5 to int8\n", x);
exit(1);
}
printf("num1 = %s\nnum2 = %s\n", string1, string2);
printf("num3 = %s\nnum4 = %s\n", string3, string4);
printf("num5 = %s\n", "NULL");
printf("\nExecuting: ifx_int8cmp(&num1, &num2)\n");
printf(" Result = %d\n", ifx_int8cmp(&num1, &num2));
printf("Executing: ifx_int8cmp(&num2, &num3)\n");
printf(" Result = %d\n", ifx_int8cmp(&num2, &num3));
printf("Executing: ifx_int8cmp(&num1, &num3)\n");
printf(" Result = %d\n", ifx_int8cmp(&num1, &num3));
printf("Executing: ifx_int8cmp(&num3, &num4)\n");

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

printf(" Result = %d\n", ifx_int8cmp(&num3, &num4));
printf("Executing: ifx_int8cmp(&num1, &num5)\n");
x = ifx_int8cmp(&num1, &num5);
if(x == INT8UNKNOWN)
printf("RESULT is INT8UNKNOWN. One of the INT8 values in null.\n");
else
printf(" Result = %d\n", x);
printf("\nIFX_INT8CMP Sample Program over.\n\n");
exit(0);
}
输出
IFX_INT8CMP Sample ESQL Program running.

Number 1 = -999,888,777,666
Number 2 = -12,345,678,956,546
Number 3 = 123,456,780,555,224,456
Number 4 = 123,456,780,555,224,456
Number 5 =

Executing: ifx_int8cmp(&num1, &num2)
Result = 1
Executing: ifx_int8cmp(&num2, &num3)
Result = -1
Executing: ifx_int8cmp(&num1, &num3)
Result = -1
Executing: ifx_int8cmp(&num3, &num4)
Result = 0
Executing: ifx_int8cmp(&num1, &num5)
RESULT is INT8UNKNOWN. One of the INT8 values in null.
IFX_INT8CMP Sample Program over.

参数说明:透明数据加密功能开关。创建加密表前需要将此参数置为on。当前参数值
为off 时,禁止创建新的加密表,对于已经创建的加密表只在读取数据时解密,写入数据时
不再加密。
该参数属于POSTMASTER 类型参数,请参考表15-1 中对应设置方法进行设置。
取值范围:布尔型。

on:开启透明数据加密功能。

off:关闭透明数据加密功能。
默认值:off