oracle数据库SQL
发布网友
发布时间:2022-04-08 06:11
我来回答
共4个回答
热心网友
时间:2022-04-08 07:41
1、写出创建此数据库表的sql语句(student,course,score三个表任意写一个创建语句)
CREATE TABLE STUDENT
(
stu_id VARCHAR2(20),
name VARCHAR2(20),
Age INTEGER,
sex CHAR(2),
stu_class VARCHAR2(12)
)
2、给表course的课程号(co_id)字段添加主键约束,给成绩表score的课程号(co_id)字段添加外键约束,其中主表是course,从表示score,写出sql语句
ALTER TABLE COURSE ADD CONSTRAINT COURSE_P_COID PRIMARY KEY (CO_ID);
ALTER TABLE SCORE ADD CONSTRAINT SCORE_F_COID FOREIGN KEY(CO_ID) REFERENCES COURSE(CO_ID) ;
3、向score表中插入一条记录,写出此sql语句
INSERT INTO SCORE VALUES ('1111000',1,90);
4、查询课程成绩大于80分的学生姓名和课程名,写出sql语句
SELECT B.NAME,C.CO_NAME FROM SCORE A,STUDENT B,COURSE C
WHERE A.STU_ID=B.STU_ID
AND A.CO_ID=C.CO_ID
AND A.SCORE>80
5、编写函数返回女同学的平均课程成绩是多少(女同学:sex=’ 女),写出sql语句
CREATE OR REPLACE FUNCTION FUN_GETSCORE
RETURN NUMBER
IS
V_SCORE NUMBER;
BEGIN
SELECT AVG(A.SCORE) INTO V_SCORE FROM SCORE A,STUDENT B
WHERE A.STU_ID=B.STU_ID
AND B.SEX='女';
RETURN V_SCORE;
END;
6、编写存储过程,更新学生成绩表score的课程成绩(score)字段,更新语句为:update score set score=newscore where stu_id=stuid and co_id=coid其中新的成绩,学号,课程号作为传人的形式参数,定义为:newscore in number,stuid in varchar2,coid in varchar2,写出此sql语句
CREATE OR REPLACE PROCEDURE P_UPDATE_SCORE(newscore in number,stuid in varchar2,coid in varchar2)
AS
BEGIN
update score set score=newscore where stu_id=stuid and co_id=coid;
COMMIT;
END;
热心网友
时间:2022-04-08 08:59
投影图一天、
追问大概什么时候?
热心网友
时间:2022-04-08 10:33
建议查看oracle数据库手册,基础的上面都有
热心网友
时间:2022-04-08 12:25
其实都是一些很简单的问题,好好看书应该能解决。我这给你写几个,以供参考。
1、create table student( stu_id varchar2(10) NOT NULL, name varchar2(20) NOT NULL, age number(3) default 0, sex varchar2(2) default '男', stu_class varchar2(10) default ' ');
2、alter table course add constraint pk_id primary key(co_id);
alter table score add constraint fk_id foreign key(co_id) reference course(co_id);
3、 insert into score values(1111111, 1212, 90);
4、
select score.stu_id, student.name, course.co_name
from score, student, course
where score > 80
and score.stu_id = student.stu_id
and score.co_id = course.co_id
5、
create or replace function avg_score ( sex varchar2)
return number
is
v_avgscore
begin
select avg(score) into v_avgscore
from score, student
where score.stu_id = student.stu_id
and student.sex = sex;
return v_avgscore;
exception
dbms_output.put_line(sqlcode||'-'||sqlerrm);
end avg_score;
6、
create or replace procere update_score
( newscore in number,
stuid in varchar2,
coid in varchar2)
is
begin
update score
set score=newscore
where stu_id=stuid
and co_id=coid;
commit;
exception
dbms_output.put_line(sqlcode||'-'||sqlerrm);
end update_score;