--这个很 基础吧,写个基础点的时时,没测试 create or replace function f_test(n varchar2) return number is num number; result NUMBER:=0; begin begin select to_number(n) into num from dual; exception when others then raise_application_error(-20012,'not a number!'); end; if num=0 then result:=0; elsif num>0 then for i in 1..num loop result:=result+i; end loop; else for i in 1..abs(num) loop result:=result+i; end loop; result:=result*(-1); end if; return result; end;
函数可以在脚本里调用啊,你想要过程? 把1楼的函数编程过程就是了 类似create or replace procedure test1(i_num in varchar2, o_result out number) as num number; begin select to_number(i_num) into num from dual; exception when others then raise_application_error(-20012, 'not a number!'); end; if num = 0 then o_result := 0; elsif num > 0 then for i in 1 .. num loop o_result := o_result + i; end loop; else for i in 1 .. abs(num) loop o_result := o_result + i; end loop; o_result := o_result * (-1); end if; end;调用SET SERVEROUTPUT ON; declare v_result number; i_num varchar; begin i_num = '&inputnum'; test1(i_num,v_result); DBMS_OUTPUT.put_line('RESULT IS '||v_result); end; have a try
--这个很 基础吧,写个基础点的时时,没测试
create or replace function f_test(n varchar2)
return number
is
num number;
result NUMBER:=0;
begin
begin
select to_number(n) into num from dual;
exception when others then
raise_application_error(-20012,'not a number!');
end;
if num=0 then
result:=0;
elsif num>0 then
for i in 1..num loop
result:=result+i;
end loop;
else
for i in 1..abs(num) loop
result:=result+i;
end loop;
result:=result*(-1);
end if;
return result;
end;
把1楼的函数编程过程就是了
类似create or replace procedure test1(i_num in varchar2, o_result out number) as
num number;
begin
select to_number(i_num) into num from dual;
exception when others then
raise_application_error(-20012, 'not a number!');
end;
if num = 0 then o_result := 0;
elsif num > 0 then
for i in 1 .. num
loop
o_result := o_result + i;
end loop;
else for i in 1 .. abs(num)
loop
o_result := o_result + i;
end loop;
o_result := o_result * (-1);
end if;
end;调用SET SERVEROUTPUT ON;
declare
v_result number;
i_num varchar;
begin
i_num = '&inputnum';
test1(i_num,v_result);
DBMS_OUTPUT.put_line('RESULT IS '||v_result);
end;
have a try
可以寫個定時的JOB讓它主動去執行procedure
楼主首先要明确什么是PLSQL,什么是SQL
什么是shell