刚学习使用db2,在创建自定义函数时遇到一个问题,函数代码如下
createorreplacefunctionF_GETDATE_BY_Q(p_quarterinteger)languagesqlspecificF_GETDATE_B...
create or replace function F_GETDATE_BY_Q(p_quarter integer)
language sql
specific F_GETDATE_BY_Q
returns varchar(8)
begin atomic
declare v_result varchar(8);
declare v_current_date varchar(8);
declare v_date_of_quarter_end varchar(8);
declare v_date_of_quarter_begin varchar(8);
set v_current_date = (select to_char(current date,'YYYYMMDD') from sysibm.sysdummy1);
set v_date_of_quarter_end = (select max(biz_date) from f_com_com_date where year = year(current date) and q = p_quarter);
set v_date_of_quarter_begin = (select min(biz_date) from f_com_com_date where year = year(current date) and q = p_quarter);
if (v_current_date < v_date_of_quarter_begin) then
set v_result = '19000230';
else if (v_current_date >= v_date_of_quarter_begin and v_current_date <= v_date_of_quarter_end) then
set v_result = v_current_date;
else if (v_current_date > v_date_of_quarter_end) then
set v_result = v_date_of_quarter_end;
end if;
return v_result;
end
>[错误] 脚本行:24-24 -------------------------------------
An unexpected token "END-OF-STATEMENT" was found following "end". Expected tokens may include: "JOIN <joined_table>".. SQLCODE=-104, SQLSTATE=42601, DRIVER=3.53.71
麻烦大家给看下是哪儿出错了,先谢了 展开
language sql
specific F_GETDATE_BY_Q
returns varchar(8)
begin atomic
declare v_result varchar(8);
declare v_current_date varchar(8);
declare v_date_of_quarter_end varchar(8);
declare v_date_of_quarter_begin varchar(8);
set v_current_date = (select to_char(current date,'YYYYMMDD') from sysibm.sysdummy1);
set v_date_of_quarter_end = (select max(biz_date) from f_com_com_date where year = year(current date) and q = p_quarter);
set v_date_of_quarter_begin = (select min(biz_date) from f_com_com_date where year = year(current date) and q = p_quarter);
if (v_current_date < v_date_of_quarter_begin) then
set v_result = '19000230';
else if (v_current_date >= v_date_of_quarter_begin and v_current_date <= v_date_of_quarter_end) then
set v_result = v_current_date;
else if (v_current_date > v_date_of_quarter_end) then
set v_result = v_date_of_quarter_end;
end if;
return v_result;
end
>[错误] 脚本行:24-24 -------------------------------------
An unexpected token "END-OF-STATEMENT" was found following "end". Expected tokens may include: "JOIN <joined_table>".. SQLCODE=-104, SQLSTATE=42601, DRIVER=3.53.71
麻烦大家给看下是哪儿出错了,先谢了 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询