创建一个 ORACLE PROCEDURE 存储过程,用户输入第一个数字 1 和最后一个数字100 ,系统输出 1,2,3...100 20
3个回答
展开全部
是不是要FUNCTION?
CREATE OR REPLACE FUNCTION GENNUM(V_FROM NUMBER,V_TO NUMBER) RETURN VARCHAR2 IS
V_RETURN VARCHAR2(32000);
V_CURRENT NUMBER;
BEGIN
IF V_FROM < V_TO THEN
V_CURRENT := V_FROM;
WHILE V_CURRENT <= V_TO LOOP
V_RETURN := V_RETURN ||','|| TO_CHAR(V_CURRENT);
V_CURRENT := V_CURRENT + 1;
END LOOP;
V_RETURN := SUBSTR(V_RETURN,2); -- 去掉第一个字符 ","
DBMS_OUTPUT.PUT_LINE(V_RETURN);
RETURN V_RETURN;
ELSE
RETURN '';
END IF;
EXCEPTION
WHEN OTHERS THEN
RETURN 'ERROR!';
END;
CREATE OR REPLACE FUNCTION GENNUM(V_FROM NUMBER,V_TO NUMBER) RETURN VARCHAR2 IS
V_RETURN VARCHAR2(32000);
V_CURRENT NUMBER;
BEGIN
IF V_FROM < V_TO THEN
V_CURRENT := V_FROM;
WHILE V_CURRENT <= V_TO LOOP
V_RETURN := V_RETURN ||','|| TO_CHAR(V_CURRENT);
V_CURRENT := V_CURRENT + 1;
END LOOP;
V_RETURN := SUBSTR(V_RETURN,2); -- 去掉第一个字符 ","
DBMS_OUTPUT.PUT_LINE(V_RETURN);
RETURN V_RETURN;
ELSE
RETURN '';
END IF;
EXCEPTION
WHEN OTHERS THEN
RETURN 'ERROR!';
END;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
create or replace procedure test
(
v_start IN NUMBER,
v_end IN NUMBER
)
IS
f NUMBER;
BEGIN
f:=v_start;
LOOP
exit when f > v_end;
dbms_output.put_line(f);
f:=f+1;
end loop;
end;
(
v_start IN NUMBER,
v_end IN NUMBER
)
IS
f NUMBER;
BEGIN
f:=v_start;
LOOP
exit when f > v_end;
dbms_output.put_line(f);
f:=f+1;
end loop;
end;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
create or replace procedure concatnumber
(
n_begin in number,
n_end in number,
o_out out varchar2
) is
i number;
begin
o_out := '';
for i in n_begin .. n_end
loop
if i > n_begin then
o_out := o_out || ',';
end if;
o_out := o_out || i;
end loop;
end;
(
n_begin in number,
n_end in number,
o_out out varchar2
) is
i number;
begin
o_out := '';
for i in n_begin .. n_end
loop
if i > n_begin then
o_out := o_out || ',';
end if;
o_out := o_out || i;
end loop;
end;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询