(4)在Oracle的安装目录下找到当前已安装的TEST数据库的所有物理文件,分类
写出文件名称。
(1)文件类型是Visual Basic User Control: CONTROL01、CONTROL02、CONTROL03、 (3)文件类型是文本文档:RED001、 RED002、RED003 实验二 2 (2)
① 查询性别为女生的平均成绩。
select avg(grade) 女生的平均成绩 from sc,student s where ssex='女' and
s.sno=sc.sno ② 查询选修了课程号为3的所有学生的姓名。
select sname from sc , s where cno='3' and s.sno=sc.sno;
③ 查询既选修了课程2又选修了课程3的学生姓名和学号。
select sname,s.sno from sc,student s where sc.sno=s.sno and cno='2' and sc.sno
in (select sno from sc where cno='3');
select sname,s.sno from sc,student s where sc.sno=s.sno and cno='2' intersect
select sname,s.sno from sc,s where sc.sno=s.sno and cno='3'; ④ 查询与“孙兰”在同一个系学习的学生
select sno,sname,sclass from student where sclass in (select sclass from student
where sname='孙兰');
select s1.sno,s1.sname,s1.sclass from student s1,student s2 where
s1.sclass=s2.sclass and s2.sname='孙兰'
实验3 (1)创建一个过程avg_sal,用于输出emp表中的某个部门的平均工资,并在PL/SQL
匿名块调用该过程输出部门SALES的平均工资;
create or replace procedure avg_sal(depName in varchar2, avgSal out number) is begin
select avg(sal) into avgSal from emp,dept where emp.deptNo=dept.deptNo and
dname=depName group by emp.deptNo;
dbms_output.put_line('部门'||depName||'的平均工资是'||to_char(avgSal)); end
测试函数:
set serveroutput on; declare
dname dept.dname%type; avgSal emp.sal%type; begin
dname:='ACCOUNTING'; avg_sal(dname,avgsal); end;
(2)创建一个函数sum_n(n int), 用于输出在1到n之间的偶数之和,并条用该
函数,输出1到1500之间的偶数和。
CREATE OR REPLACE FUNCTION SUM_N(N NUMBER ) RETURN NUMBER AS I NUMBER(3);
SUM_VAL NUMBER:=0;
BEGIN
FOR I IN 1..N LOOP
IF MOD(I+1,2)!=0 THEN SUM_VAL:=SUM_VAL+I; END IF; END LOOP;
RETURN SUM_VAL; END SUM_N; 测试函数:
declare n number; begin n:=10;
dbms_output.put_line(sum_n(1500)); end;
(2)创建一个函数find_loc, 用于返回某个员工所在的工作地点。并调用该函数,显示员工号为7788的工作地点。
CREATE OR REPLACE FUNCTION find_loc(emp_no NUMBER) RETURN VARCHAR2 AS
location VARCHAR2(13); BEGIN
SELECT loc INTO location FROM emp, dept WHERE emp.deptno=dept.deptno AND
empno=emp_no; RETURN location; END find_loc;
(3)创建一个触发器tr_emp_sal,当进行update操作时,员工的工资只能涨不能降,
不允许删除员工记录。
create or replace trigger tr_emp_sal before update of sal or delete on emp for each row begin case
when updating('sal') then if :new.sal-:old.sal<0 then
raise_application_error(-20001, '员工的工资只能涨不能降!'); end if;
when deleting then
raise_application_error(-20002, '不能删除员工记录!'); end case; end;
Oracle复习/ch1数据库的完整性,有哪些约束/ch2体系结构/物理:物理文件(数据、控制、日志)/逻辑:表空间、段、区、数据块/进程:7个进程 内存:SGA/PGA/数据字典/ch3/SQL*Plus命令:DESC/SAVE/GET/EDIT/START/COLUMN/ACCEPT 例3.17/ch4 创建基本表空间和临时表空间/ch5 表、视图、索引和序列的创建 ch6 备份控制文件、管理日志文件组/ch7、ch8 select语句/ch9 /IF语句例9.7/CASE语句例9.8/游标:声明、打开、检索和关闭
ch10/存储过程、函数和触发器的创建/触发器的两种级别
因篇幅问题不能全部显示,请点此查看更多更全内容