我知道可以在db2中完成以下操作:
select * from table where created_date < current_timestamp - 5 days;
但是执行类似以下操作的正确语法是什么?
begin
declare numdays int default 5;
-- some logic
select * from table where created_date < current_timestamp - numdays days;
end;
答案 0 :(得分:1)
可以直接使用变量代替常量,如下所示:
create table test (dt timestamp);
begin
declare numdays int;
set numdays = 10;
insert into test
SELECT CURRENT_timestamp + numdays DAYS FROM sysibm.sysdummy1;
end ;
select current_timestamp, dt from test;
返回
2017-12-14 08:20:39.19063 2017-12-24 08:20:35.503779