Posted on 2009-04-01 17:02
bluoy 阅读(817)
评论(1) 编辑 收藏
下面的例子实现把一个整数的各个位上的数字相加,通过这个例子我们再次理解
connect by.
create or replace function f_digit_add(innum integer) return number
is
outnum integer;
begin
if innum<0 then
return 0;
end if;
select sum(nm) into outnum from(
select substr(innum,rownum,1) nm from dual connect by
rownum<length(innum)
);
return outnum;
end f_digit_add;
/
select f_digit_add(123456) from dual;