oracle数据库的上机题求助:

oracle数据库的上机题求助:,第1张

补齐函数lpad()或者rpad(),一个是左边补齐lpad(),一个是后边补齐rpad(),举例:

lpad('aa',5,‘0’)这个意思是在左边用0补齐5位,结果是000aa。

截取函数:substr(‘1234567’,1,5)意思是把1234567这个字符串从1个位置开始截取,截取到第五个

第一题:select substr(lpad('1234567',5,'0'),1,5) from dual结果12345

select substr(lpad('123',5,'0'),1,5) from dual结果00123

第二题:select case when length('1234567')>5 then '1234567' else lpad('1234567',5,'0') end from dual结果1234567

select case when length('1234')>5 then '1234' else lpad('1234,5,'0') end from dual结果01234

实验通过了,望采纳

borrower:

create table borrower(

借书证号 char[5] primary key,

姓名 char[20] not null,

系名 char[10],

班级 char[10])

create table loans(

借书证号 char[5],

图书登记号 char[6],

结束日期 DATE,

primary key(借书证号,图书登记号),

foreign key(借书证号) reference borrower(借书证号),

foreign key(图书登记号 reference books(图书登记号))

create table books(

索书号 char[10],

书名 char[20],

图书登记号 char[6] primary key,

出版社 char[20],

价格 smallint))

(1)

select borrower.借书证号,姓名,系名,temp.total as 借书数量

from borrower,(select 借书证号,count(图书登记号) as total

from loans group by 借书证号

where tatal>5 as temp(借书证号,total))

(2)

select borrower.姓名,系名,书名,结束日期

from borrower,loans,books

where borrower.借书证号=loans.借书证号

and books.图书登记号=loans.图书登记号

and 书名 in(selcet 书名

from borrower,loans,books

where borrower.借书证号=loans.借书证号

and books.图书登记号=loans.图书登记号

and 姓名='赵垒')

(3)

create view SB

as

select borrower.借书证号,姓名,班级,books.图书登记号,书名,出版社

,借书日期

from borrower,book,loans

where borrower.借书证号=loans.借书证号

and books.图书登记号=loans.图书登记号

and 系名='信息系'

1

create table student(

sno char[10] primary key,

sname char[20] not null,

ssex char[2],

sage smallint check( sage between 16 and 30),

sdept char[4])

create table course(

cno char[10] primary key,

cname char[20] not null,

cteacher char[20])

create table sc(

sno char[10],

cno char[10],

grade smallint check(grade is null or grade between 0 and

100),

primary key(sno,cno)

foreign key sno reference student(sno),

foreign key cno reference course(cno))

2

insert into student values('102','李四','男',16,'数学')

下同

insert into course values('203',' *** 作系统','程羽')

下同

insert into sc values('101','203',82)

下同

3

(1) select cname,grade

from sc,student,course

where student.sno=sc.sno and course.cno=sc.cno

and sname='张三'

(2) select sname from student

where sno in(select sno from sc x

where not exists(

select * from sc y

where x.sno=y.sno

and y.grade<60))

(3) select cname,sname,grade

from student,course sc,(select cno,max(grade) from sc group by cno

as temp(cno,max))

where student.sno=sc.sno and course.cno=sc.cno

and grade=max and course.cno=temp.cno

4

delete * from sc where grade<60

5

update sc

set grade=(select avg(grade) from sc where cno='203')

where sno=105

仅供参考

有两个问题:

1)将结果按学号升序存放 --- 必须加Order by Student.学号

2)库的结构同STUDENT,并在其后加入课程号和课程名字段 --- 所以Student.* 这些栏位必须放在课程名和课程号前,因为数据库不会自动帮你将值对应到各个栏位,在没有指明插入栏位时,你必须按照表中栏位的顺序来查询


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/9996079.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-04
下一篇 2023-05-04

发表评论

登录后才能评论

评论列表(0条)

保存