我能够解决这个问题,但是有没有人有更高效的方法来计算10并且只打印出PL / SQL中的赔率?
DECLARE
v_count integer := 0;
v_num integer := 1;
BEGIN
WHILE V_NUM <=8
LOOP
EXIT WHEN v_count = 10;
v_num := v_num + 1;
IF (v_num MOD 2) = 1
THEN v_count := v_count + 1;
dbms_output.put_line(v_num);
END IF;
END LOOP;
END;
答案 0 :(得分:1)
DECLARE
v_num integer;
BEGIN
FOR v_num IN 1..10 LOOP
IF (v_num MOD 2) = 1 THEN
dbms_output.put_line(v_num);
END IF;
END LOOP;
END;
/
或者,如果你想最小化循环迭代次数(你不再真正计算到10):
DECLARE
v_num integer;
BEGIN
FOR v_num IN 0..4 LOOP
dbms_output.put_line(v_num*2+1);
END LOOP;
END;
/