Oracle大型数据库 作业5

第六章

img

//2

-- 2
create table exer_class
(
    cno   number(2) primary key,
    cname varchar(20),
    num   number(3)
) tablespace users;

create table exer_student
(
    son   number(4) primary key,
    sname varchar2(10) unique,
    sage  number,
    sex   char(2),
    con   number(2)
) tablespace USERS;

image-20211116204015291

//3

-- 3
alter table exer_student
    add constraint ck check (sage between 0 and 100);

image-20211116204130194

//4

alter table exer_student
    modify(sex char(2) default ('m'));
alter table exer_student
    add constraint cs check (sex in ('m', 'f'));

image-20211116204232466

//5

create unique index ind_cname on exer_class (cname);

image-20211116204310732

//6

这里我遇上一个错误,权限不足的问题

image-20211116204835200

需要先用sys权限输入以下

grant create  view to SCOTT;
grant select any table to SCOTT;
grant select any dictionary to SCOTT;

image-20211116204724765

这样就可以了

create view s_view(ccno, ccname, ssname, ssno, age, ssex, nnum)
as
select c.cno, c.cname, c.num, s.son, s.sage, s.sex, s.sname
from exer_class c,
     exer_student s
where c.cno = s.con;

image-20211116204843893

//7

create sequence seq start with 100000001 increment by 1 nocache nocycle;

image-20211116205212493

//8

这里还是权限不够,我干脆用sys弄了

create tablespace orcltbs1 datafile 'orcltbs1.dbf' size 10m;
create tablespace orcltbs2 datafile 'orcltbs2.dbf' size 10m;

image-20211116210039240

image-20211116210059687

然后发现users居然在脱机状态

在sys用户下直接ALTER TABLESPACE USERS online ;即可

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-IOpOhP39-1637074745557)(http://pic.sehnsucht.top/img/image-20211116211143552.png)]

然后创建即可,毫无问题了

create table exer_student_range
(
    sno   number(4) primary key,
    sname varchar2(10),
    sage  number,
    sex   char(2),
    cno   number(2)
)
    partition by range (sage)
(
    partition part1 values less than (20) tablespace example,-- 低于20岁的学生信息放入part1区,存储在example
    partition part2 values less than (30) tablespace orcltbs1,-- 20-30岁的学生信息放在part2区,存放在orcltbs1
    partition part3 values less than (maxvalue) tablespace orcltbs2-- 其他放在part3区,存放在prcltbs2
);

image-20211116211132682

//9

create table student_list
(
    sno   number(4) primary key,
    sname varchar2(10),
    sage  number,
    sex   char(2),
    cno   number(2)
)
    partition by list
(
    sex
)
(
    partition male values ('m') tablespace orcltbs1,
    partition female values ('f') tablespace orcltbs2
);

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-VJc1ry0R-1637074745558)(http://pic.sehnsucht.top/img/image-20211116213127429.png)]

//10

create index student_range_l on exer_student_range(sname) local;

image-20211116225453633

Guess you like

Origin blog.csdn.net/Dueser/article/details/120832369