oracle max_seq_calc
DECLARE
TYPE seq_st_tt IS TABLE OF INT;
seq_st seq_st_tt := seq_st_tt(20,-10,-5,-3,5,4,-2,7,40);
tmpsum INT := 0;
maxval INT :=seq_st(1);
spos INT := 1;
epos INT := 1;
nspos INT := 1;
nepos INT := 1;
BEGIN
FOR i IN 1..seq_st.count LOOP
tmpsum := tmpsum + seq_st(i);
IF(tmpsum < 0) THEN
nspos := i + 1;
nepos := i + 1;
tmpsum := 0;
ELSIF(tmpsum >= maxval) THEN
spos := nspos;
epos := nepos;
nepos := nepos + 1;
maxval := tmpsum;
ELSE
nepos := nepos + 1;
END IF;
END LOOP;
dbms_output.put_line(‘the max linear sequence from ‘||spos||‘ to ‘||epos||‘ is ‘||maxval);
END;
本文出自 “welcome” 博客,请务必保留此出处http://friendsforever.blog.51cto.com/3916357/1642428
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。