脚本优化

[复制链接]
查看11 | 回复9 | 2008-1-2 17:35:53 | 显示全部楼层 |阅读模式
以下脚本是对不同的 v_bmonth进行相应的计算,请问,对以下脚本在逻辑上(或类型转换)上如何优化呀
if (to_number(substr(v_bmonth, 1, 4)) = 2008) then
if (to_number(substr(v_bmonth, 5, 6)) > 2) then
if (v_flag = '1') then

v_KR := v_temp + 2000;
else

v_templ := round((v_temp - v_datedef - 2000), 2);

if (v_templ > 0) then

v_KR := 0;

else

v_KR := abs(v_templ);

end if;

end if;
else
if (v_flag = '1') then

v_KR := v_datedef * 1600;
else

v_templ := round((v_temp - v_datedef - 1600), 2);

if (v_templ > 0) then

v_KR := 0;

else

v_KR := abs(v_templ);

end if;
end if;
end if;
elsif (to_number(substr(v_bmonth, 1, 4)) > 2008) then
if (v_flag = '1') then
v_KR := v_datedef * 2000;
else
v_templ := round((v_temp - v_datedef - 2000), 2);
if (v_templ > 0) then

v_KR := 0;
else

v_KR := abs(v_templ);
end if;

end if;
else
if (v_flag = '1') then
v_KR := v_datedef * 1600;
else

v_templ := round((v_temp - v_datedef - 1600), 2);
if (v_templ > 0) then

v_KR := 0;
else

v_KR := abs(v_templ);
end if;
end if;
end if;
回复

使用道具 举报

千问 | 2008-1-2 17:35:53 | 显示全部楼层
光从语法的运用上是不是很合理?有优化的空间吗
回复

使用道具 举报

千问 | 2008-1-2 17:35:53 | 显示全部楼层
逻辑没细看,但是我觉着这里写个function处理看起来不就更简单了~~~
回复

使用道具 举报

千问 | 2008-1-2 17:35:53 | 显示全部楼层
类似to_number(substr(v_bmonth, 1, 4)) = 2008
to_number(substr(v_bmonth, 1, 4)) > 2008
等语句能不能优化
回复

使用道具 举报

千问 | 2008-1-2 17:35:53 | 显示全部楼层
本人是写成了function,上面的语句是function体中的实现,感觉写的不好所以想请教
回复

使用道具 举报

千问 | 2008-1-2 17:35:53 | 显示全部楼层
请大家帮忙
回复

使用道具 举报

千问 | 2008-1-2 17:35:53 | 显示全部楼层
要实现什么功能?
回复

使用道具 举报

千问 | 2008-1-2 17:35:53 | 显示全部楼层
原帖由 sxlcom 于 2008-8-12 16:12 发表
类似to_number(substr(v_bmonth, 1, 4)) = 2008
to_number(substr(v_bmonth, 1, 4)) > 2008
等语句能不能优化


单独的好像不能优化了。
不过像
if (to_number(substr(v_bmonth, 1, 4)) = 2008) then
if (to_number(substr(v_bmonth, 5, 6)) > 2) then
为什么不写成一个if语句呢?
回复

使用道具 举报

千问 | 2008-1-2 17:35:53 | 显示全部楼层
if (v_flag = '1') then
if (to_number(substr(v_bmonth, 1, 4)) > 2008) then
v_KR := v_datedef * 2000;
elseif (to_number(substr(v_bmonth, 1, 4)) = 2008)

and(to_number(substr(v_bmonth, 5, 6)) > 2) then

v_KR := v_temp + 2000;

else

v_KR := v_datedef * 1600;
end if;
else
if ((to_number(substr(v_bmonth, 1, 4)) = 2008) and
(to_number(substr(v_bmonth, 5, 6)) > 2)) or
(to_number(substr(v_bmonth, 1, 4)) > 2008) then
v_templ := round((v_temp - v_datedef - 2000), 2);
if (v_templ > 0) then

v_KR := 0;
else

v_KR := abs(v_templ);
end if;
else
v_templ := round((v_temp - v_datedef - 1600), 2);
if (v_templ > 0) then

v_KR := 0;
else

v_KR := abs(v_templ);
end if;
end if;

end if;
回复

使用道具 举报

千问 | 2008-1-2 17:35:53 | 显示全部楼层
通过v_KR(标识)和v_bmonth(年月)来进行相应的计算
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行