conn sys/SysPassword1@//localhost:1521/pdb1 as sysdba
alter system flush shared_pool;
conn testuser1/testuser1@//localhost:1521/pdb1
drop table tab1 purge;
create table tab1 (
id number,
name varchar2(20),
gender varchar2(1),
y_chromosome varchar2(1),
beard varchar2(1),
constraint tab1_pk primary key (id),
constraint tab1_gender_chk check (gender in ('M', 'F')),
constraint tab1_has_y_chromosome_chk check (y_chromosome in ('Y', 'N')),
constraint tab1_has_beard_chk check (beard in ('Y', 'N'))
);
insert into tab1
select level,
dbms_random.string('l',trunc(dbms_random.value(10,16))) as name,
case
when mod(rownum, 2) = 0 then 'M'
else 'F'
end as gender,
case
when mod(rownum, 2) = 0 then 'Y'
else 'N'
end as y_chromosome,
case
when mod(rownum, 2) = 0 then decode(trunc(dbms_random.value(1,3)), 1, 'Y', 'N')
else 'N'
end as beard
from dual
connect by level <= 10000;
commit;
create index tab1_gender_idx on tab1(gender);
create index tab1_has_y_chromosome_idx on tab1(y_chromosome);
create index tab1_has_beard_idx on tab1(beard);
-- Don't explicitly gather that statistics at this point!
--exec dbms_stats.gather_table_stats(null, 'tab1');
select gender, y_chromosome, beard, count(*) as total
from tab1
group by gender, y_chromosome, beard
order by 1,2,3;
G Y B TOTAL
- - - ----------
F N N 5000
M Y N 2523
M Y Y 2477
SQL>