我需要生成6个数字而不重复从1到49。 我有类似的东西:
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;
但这似乎不起作用。有人可以帮帮我吗?
答案 0 :(得分:5)
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
答案 1 :(得分:1)
只需将49个数字放在表格中并使用
SELECT SOME_NUMBER FROM
(
SELECT SOME_NUMBER
FROM TABLE_OF_NUMBERS
ORDER BY DBMS_RANDOM.VALUE()
)
WHERE ROWNUM < 7
答案 2 :(得分:0)
create table zadanie1(
user varchar2(30),
PUNKTY number,
ID number,
constraint stud1_nazw primary key(NAZWISKO)
);