我需要从 1 到 49 不重复地生成 6 个数字。 我有这样的东西:
create table zadanie1(
NAZWISKO varchar2(30),
PUNKTY number,
ID number,
constraint stud1_nazw primary key(NAZWISKO)
);
create or replace procedure "LOTTO" IS
pkt number;
begin
loop
BEGIN
pkt := round(dbms_random.value(1,14),0);
INSERT INTO ZADANIE1(PUNKTY) VALUES (pkt);
exit;
Exception When DUP_VAL_ON_INDEX Then 0;
END;
end loop;
END;
但这似乎行不通。有人可以帮助我吗?
最佳答案
SQL> select num
2 from (select rownum num
3 from dual
4 connect by level <= 49
5 order by dbms_random.value)
6 where rownum <= 6;
NUM
----------
10
6
9
12
22
14
关于sql - 从集合 1 ... 49 中生成 6 个无重复的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13274991/