--建立临时表:
create global temporary table temp on commit preserve rows [as select * from drv where 1=2] --session 级别 对话关闭后消失
create global temporary table temp on commit preserve rows [as select * from drv where 1=2] --session 级别 对话关闭后消失
create global temporary table temp on commit delete rows [as select * from drv where 1=2] --transaction 级别 提交后消失
create or replace procedure pro_show(rn in number)
as
var_num number(10);
var_rownum number(5);
var_i number(2);
var_flag number(2);
begin
select count(*) into var_num from drv;
var_i:=1;
delete from temp;--session 级别 程序调用可去掉该行【truncate table temp 报错?】
commit;
for i in 1..rn loop
var_rownum:=ceil(dbms_random.value * var_num);--随机行数 向上转成整数
select count(*) into var_flag from temp where id = var_rownum;
while (var_flag > 0 ) loop
var_rownum:=ceil(dbms_random.value * var_num);-- 随机过的不在随机
select count(*) into var_flag from temp where id = var_rownum;
end loop;
insert into temp select id,name,car,carno from (select drv.* ,rownum rn from drv)t where t.rn = var_rownum;
end loop;
if (sql%rowcount > 0) then
commit;
end if;
end pro_show;