drop table x; create table x (xx varchar2(10)); insert into x values('X1'); insert into x values('X2'); insert into x values('X3'); insert into x values('X4');create table x_cnt (cnt number); insert into x_cnt values(1); commit; /create or replace procedure get_x(o out varchar2) is v_cnt number; v_max number; begin select cnt into v_cnt from x_cnt; select count(1) into v_max from x; select xx into o from (select xx, rownum rn from x) where rn = v_cnt; if (v_cnt = v_max) then v_cnt := 0; end if; v_cnt := v_cnt + 1; update x_cnt set cnt = v_cnt; commit; end;/
不想循环取,调用存储每次就取一次,然后下次再调存储的时候取X2,第三次取X3,第四次取X4,就是每次只取一个,并且这四个数平均取
create table x (xx varchar2(10));
insert into x values('X1');
insert into x values('X2');
insert into x values('X3');
insert into x values('X4');create table x_cnt (cnt number);
insert into x_cnt values(1);
commit;
/create or replace procedure get_x(o out varchar2) is
v_cnt number;
v_max number;
begin select cnt into v_cnt from x_cnt;
select count(1) into v_max from x;
select xx into o from (select xx, rownum rn from x) where rn = v_cnt; if (v_cnt = v_max) then
v_cnt := 0;
end if;
v_cnt := v_cnt + 1;
update x_cnt set cnt = v_cnt;
commit;
end;/