GBase 8t使用unix_timestamp()函数
从mysql迁移到GBase 8t数据库时,原有unix_timestamp()函数在GBase 8t中不可用,因此需要自己创建相应的函数,可以使用C或者JAVA创建自定义例程,也可以使用存储过程。以下以存储过程方式创建。
create procedure UNIX_TIMESTAMP(datestr datetime year to fraction(5))
returning int;
define srcdate datetime year to fraction(5);
define rc_char varchar(30);
define rc int;
let srcdate = datetime(1970-01-01 00:00:00.00000) year to fraction(5) ;
let rc_char = datestr - srcdate;
-- rc_char 17281 13:07:11.00000
let rc = (substr(rc_char,1,9)*86400 + substr(rc_char,17,2)*1 + substr(rc_char,14,2)*60 + substr(rc_char,11,2)*3600)::integer;
let rc = rc - 8*3600;
return rc;
end procedure ;
create procedure UNIX_TIMESTAMP(datestr varchar(30))
returning int;
define srcdate datetime year to second;
define tmpdate datetime year to second;
define rc_char varchar(30);
define rc int;
let srcdate = datetime(1970-01-01 00:00:00) year to second ;
let tmpdate = to_date(datestr,'%Y-%m-%d %H:%M:%S');
let rc_char = tmpdate - srcdate;
-- rc_char 17281 13:07:11.00000
let rc = (substr(rc_char,1,9)*86400 + substr(rc_char,17,2)*1 + substr(rc_char,14,2)*60 + substr(rc_char,11,2)*3600)::integer;
let rc = rc - 8*3600;
return rc;
end procedure ;
- 上一篇: GBase 8t和NoSQL结合
- 下一篇: GBase 8t数据库SQL优化一例