返回首页

gbase数据、南大通用产品文档:GBase8s对象资源

更新日期:2024年09月11日

对象资源包括服务器属性、数据库节点、服务器对象、管理节点。

dtcvfmtasc() 函数使用格式化掩码来将字符串转换为 datetime 值。
语法
mint dtcvfmtasc(inbuf, fmtstring, dtvalue)
char *inbuf;
char *fmtstring;
dtime_t *dtvalue;
inbuf
指向包含要转换的字符串的缓冲区的指针。
fmtstring
指向要针对 inbuf 字符串使用其格式化掩码的缓冲区的指针。此时间格式化掩码包含
DBTIME 环境变量支持的相同的格式化伪指令。
dtvalue
指向初始化了的 datetime 变量的指针。

用法
您必须以您想要此变量拥有的限定符来初始化 dtvalue 中的 datetime 变量。
datetime
变量不需要指定该格式化掩码说明的同一限定符。
当 datetime 限定符与说明了的格式化掩
码限定符不同时,dtcvfmtasc() 扩展 datetime 值(如同它以调用了 dtextend() 函数)。


GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 679 -
inbuf 中的字符串中的所有限定符字段都必须是相邻的,换句话说,如果限定符为
hour to second,
则您必须为该字符串中某处的 hour、
minute 和 second 都指定值,
否则,
dtcvfmtasc() 函数返回错误。
inbuf 字符串可有开头的和结尾的空格。然而,从第一个有效位至最后一个,inbuf 仅
可包含适于格式化掩码说明的限定符字段的数字和定界符。

如果格式化掩码 fmtstring 为空字符串,
则 dtcvfmtasc() 函数返回错误。
如果 fmtstring
是空指针,则当 dtcvfmtasc() 函数读取 inbuf 中的字符串时,它必须确定格式。当您使用
缺省的语言环境时,该函数使用下列优先顺序:
DBTIME 环境变量指定的格式(如果设置 DBTIME 的话)。
GL_DATETIME 环境变量指定的格式(如果设置 GL_DATETIME 的话)。
符合标准 ANSI SQL 格式的缺省的日期格式:
%iY-%m-%d %H:%M:%S

ANSI SQL 格式为输出指定 year to second 的限定符。您可以四位(2007)或以两位
(07)表示年份。当您在格式化掩码中使用两位年份(%y)时,dtcvfmtasc() 函数使用
DBCENTURY 环境变量的值来确定要使用哪个世纪。如果您未设置 DBCENTURY,则
dtcvfmtasc() 为两位年份假定当前的世纪。

当您使用非缺省的语言环境(US English 之外的一种),且未设置 DBTIME 或
GL_DATETIME 环境变量时,dtcvfmtasc() 使用该语言环境定义的缺省的 DATETIME 格
式。

当字符串和格式化掩码是可接受的时,dtcvfmtasc() 函数设置 dtvalue 中的 datetime
变量,并返回零。否则,它返回错误代码,且 datetime 变量包含不可预计的值。

返回代码
0
转换成功。
<0
转换失败。

示例


GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 680 -
demo 目录在文件 dtcvfmtasc.ec 中包含此样例程序。该代码将变量 birthday 初始化
为虚构的生日。
/* *dtcvfmtasc.ec*
The following program illustrates the conversion of several ascii strings into datetime
values.
*/

#include

EXEC SQL include datetime;

main()
{
char out_str[17], out_str2[17], out_str3[17];
mint x;

EXEC SQL BEGIN DECLARE SECTION;
datetime month to minute birthday;
datetime year to minute birthday2;
datetime year to minute birthday3;
EXEC SQL END DECLARE SECTION;

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

/* Initialize birthday to "09-06 13:30" */
printf("Birthday #1 = September 6 at 01:30 pm\n");
x = dtcvfmtasc("September 6 at 01:30 pm", "%B %d at %I:%M %p",
&birthday);

/*Convert the internal format to ascii in ANSI format, for displaying. */
x = dttoasc(&birthday, out_str);
printf("Datetime (month to minute) value = %s\n\n", out_str);
/* Initialize birthday2 to "07-14-88 09:15" */

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 681 -
printf("Birthday #2 = July 14, 1988. Time: 9:15 am\n");
x = dtcvfmtasc("July 14, 1988. Time: 9:15am",
"%B %d, %Y. Time: %I:38p", &birthday2);

/*Convert the internal format to ascii in ANSI format, for displaying. */
x = dttoasc(&birthday2, out_str2);
printf("Datetime (year to minute) value = %s\n\n", out_str2);
/* Initialize birthday3 to "07-14-XX 09:15" where XX is current year.
* Note that birthday3 is year to minute but this initialization only
* provides month to minute. dtcvfmtasc provides current information for the
missing year.
*/
printf("Birthday #3 = July 14. Time: 9:15 am\n");
x = dtcvfmtasc("July 14. Time: 9:15am", "%B %d.
Time: %I:%M %p",&birthday3);

/* Convert the internal format to ascii in ANSI format, for displaying. */
x = dttoasc(&birthday3, out_str3);
printf("Datetime (year to minute) value with current year = %s\n", out_str3);

printf("\nDTCVFMTASC Sample Program over.\n\n");

}
输出
DTCVFMTASC Sample ESQL Program running.

Birthday #1 = September 6 at 01:30 pm
Datetime (month to minute) value = 09-06 13:30

Birthday #2 = July 14, 1988 Time: 9:15 am
Datetime (year to minute) value = 2007-07-14 09:15

Birthday #3 = July 14. Time: 9:15 am

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 682 -
Datetime (year to minute) value with current year = 2007-07-14 09:15

DTCVFMTASC Sample Program over.

操作场景
回收用户组的数据库权限。
语法格式
REVOKE SELECT ON DBNAME.TBNAME FROM role_name
示例
gbase> revoke select on test.t from r1;
Query OK, 0 rows affected (Elapsed: 00:00:00.07)

GBase 8a MPP Cluster 产品手册
4 管理员指南
文档版本953(2022-04-10)
南大通用数据技术股份有限公司
428
gbase> revoke all privileges on *.* from u2;
Query OK, 0 rows affected (Elapsed: 00:00:00.04)
gbase> revoke all privileges, grant option from u2;
Query OK, 0 rows affected (Elapsed: 00:00:00.03)
gbase> revoke all , grant option from u2;
Query OK, 0 rows affected (Elapsed: 00:00:00.02)