返回首页

gbase数据、南大通用产品文档:GBase8s支持 DATE 最终用户格式

更新日期:2024年09月11日

最终用户格式是 DATE 值出现在字符串变量中的格式。本节描述了指定 DATE 最终用户
格式的 GL_DATE 、DBDATE 和 DBCENTURY 变量。这些变量是可选的。
重要: GBase 8s JDBC Driver 不支持 DBDATE 或 GL_DATE 环境变量的 ALS 6.0 、5.0 或 4.0
格式。

2 |
+---------------------+------------+--------+
10 rows in set
gbase> UPDATE t2 SET b=89.3 where c <1000;
Query OK, 5 rows affected
Rows matched: 5
Changed: 5
Warnings: 0
-- 查看没有被更新的数据行对应的TIMESTAMP 列,TIMESTAMP 列的值保

GBase 8a MPP Cluster 产品手册
5 数据库管理指南
文档版本953(2022-04-10)
南大通用数据技术股份有限公司
1060
持不变。
gbase> SELECT * FROM t2 WHERE c <1000;
+---------------------+---------+------+
| a
| b
| c
|
+---------------------+---------+------+
| 2013-12-17 14:17:57 | 89.3000 |
11 |
| 2013-12-17 14:17:57 | 89.3000 |
111 |
| 2013-12-17 14:17:57 | 89.3000 |
123 |
| 2013-12-17 14:17:57 | 89.3000 |
1 |
| 2013-12-17 14:17:57 | 89.3000 |
2 |
+---------------------+---------+------+
5 rows in set
-- 查看没有被更新的数据行对应的TIMESTAMP 列,TIMESTAMP 列的值保
持不变。
gbase> SELECT * FROM t2 WHERE c >=1000;
+---------------------+-----------+--------+
| a
| b
| c
|
+---------------------+-----------+--------+
| 2013-12-17 14:11:16 | 1334.5600 |
1111 |
| 2013-12-17 14:11:16 |

deccvasc() 函数将以 C char 类型中作为可打印字符保存的值转换为 decimal 类型数
值。

语法
mint deccvasc(strng_val, len, dec_val)
char *strng_val;
mint len;
dec_t *dec_val;
strng_val
指向要将其值 deccvasc() 转换为 decimal 值的字符串的指针。
len
strng_val 字符串的长度。
dec_val
指向 deccvasc() 将转换的结果放置其中的 decimal 结构的指针。

用法

字符串 strng_val 可包含下列符号:
前置符号,或正号(+)或负号(-)
小数点,以及小数点游标的数字
以 e 或 E 开头的指数。您可在指数前添加符号,或正号(+)或负号(-)。
deccvasc() 函数忽略字符串中开头的空格。

返回代码
0
转换成功。
-1200
该数值太大,以至于不能放入 decimal 类型结构内(溢出)。
-1201

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

该数值太小,以至于不能放入 decimal 类型结构内(下溢)。
-1213
该字符串有非数值字符。
-1216
该字符串有不良指数。

示例

demo 目录中的 deccvasc.ec 文件包含下列样例程序。
/*
* deccvasc.ec *

The following program converts two strings to DECIMAL numbers and displays the values
stored in each field of the decimal structures.
*/

#include

EXEC SQL include decimal;

char string1[] = "-12345.6789";
char string2[] = "480";

main()
{
mint x;
dec_t num1, num2;

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

if (x = deccvasc(string1, strlen(string1), &num1))
{
printf("Error %d in converting string1 to DECIMAL\n", x);

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

exit(1);
}
if (x = deccvasc(string2, strlen(string2), &num2))
{
printf("Error %d in converting string2 to DECIMAL\n", x);
exit(1);
}
/*
* Display the exponent, sign value and number of digits in num1.
*/
printf("\tstring1 = %s\n", string1);
disp_dec("num1", &num1);

/*
* Display the exponent, sign value and number of digits in num2.
*/
printf("\tstring2 = %s\n", string2);
disp_dec("num2", &num2);

printf("\nDECCVASC Sample Program over.\n\n");
exit(0);
}


disp_dec(s, num)
char *s;
dec_t *num;
{
mint n;

printf("%s dec_t structure:\n", s);
printf("\tdec_exp = %d, dec_pos = %d, dec_ndgts = %d, dec_dgts: ",
num->dec_exp, num->dec_pos, num->dec_ndgts);

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

n = 0;
while(n < num->dec_ndgts)
printf("%02d ", num->dec_dgts[n++]);
printf("\n\n");
}
输出
DECCVASC Sample ESQL Program running.

string1 = -12345.6789
num1 dec_t structure:
dec_exp = 3, dec_pos = 0, dec_ndgts = 5,
dec_dgts: 01 23 45 67 89

string2 = 480
num2 dec_t structure:
dec_exp = 2, dec_pos = 1, dec_ndgts = 2,
dec_dgts: 04 80

DECCVASC Sample Program over.