完成下列操作,写出相应的SQL语句

创建表空间neuspace,数据文件命名为neudata.dbf,存放在d:\data目录下,文件大小为200MB,设为自动增长,增量5MB,文件最大为500MB。(8分)
答:create tablespace neuspace datafile ‘d:\data\neudata.dbf’ size 200m auto extend on next 5m maxsize 500m;
2. 假设表空间neuspace已用尽500MB空间,现要求增加一个数据文件,存放在e:\appdata目录下,文件名为appneudata,大小为500MB,不自动增长。(5分)
答:alter tablespace neuspace add datafile ‘e:\appdata\appneudata.dbf’ size 500m;
3. 以系统管理员身份登录,创建账号tom,设置tom的默认表空间为neuspace。为tom分配connect和resource系统角色,获取基本的系统权限。然后为tom分配对用户scott的表emp的select权限和对SALARY, MGR属性的update权限。(8分)
答:create user tom identified by jack default tablespace neuspace;
Grant connect, resource to tom;
Grant select, update(salary, mgr) on scott.emp to tom;
4. 按如下要求创建表class和student。(15分)
属性
类型(长度)
默认值
约束
含义

CLASSNO 数值 (2) 无 主键 班级编号
CNAME 变长字符 (10) 无 非空 班级名称
属性
类型(长度)
默认值
约束
含义

STUNO 数值 (8) 无 主键 学号
SNAME 变长字符 (12) 无 非空 姓名
SEX 字符 (2) 男 无 性别
BIRTHDAY 日期 无 无 生日
EMAIL 变长字符 (20) 无 唯一 电子邮件
SCORE 数值 (5, 2) 无 检查 成绩
CLASSNO 数值 (2) 无 外键,关联到表CLASS的CLASSNO主键 班级编号
答:create table class
(classno number(2) constraint class_classno_pk primary key,
cname varchar2(10) not null);
create table student
(stuno number(8) constraint student_stuno_pk primary key,
sname varchar2(12) not null,
sex char(2) default ‘男’,
birthday date,
email varchar2(20) constraint student_email_uk unique,
score number(5,2) constraint student_score_ck check(score>=0 and score<=100),
classno number(2) constraint student_classno_fk references class(classno)
);
5. 在表student的SNAME属性上创建索引student_sname_idx(5分)
答:create index student_sname_idx on student(sname);
6. 创建序列stuseq,要求初值为20050001,增量为1,最大值为20059999。(6分)
答:create sequence stuseq increment by 1 start with 20050001 maxvalue 20059999 nocache nocycle;
7. 向表student中插入如下2行。(5分)
STUNO SNAME SEX BIRTHDAY EMAIL SCORE CLASSNO
从stuseq取值 tom 男 1979-2-3 14:30:25 tom@163.net 89.50 1
从stuseq取值 jerry 默认值 空 空 空 2
答:insert into student values(stuseq.nextval, ’tom’, ’男’, to_date(‘1979-2-3
14:30:25’, ’yyyy-mm-dd fmhh24:mi:ss’), ’tom@163.net’, 89.50, 1);
insert into student (stuno, sname, classno) values(stuseq.nextval, ’jerry’, 2);
8. 修改表student的数据,将所有一班的学生成绩加10分。(4分)
答:update student set score=score+10 where classno=1;
9. 删除表student的数据,将所有3班出生日期小于1981年5月12日的记录删除。(4分)
答:delete from student where classno=3 and birthday > ’12-5月-81’;
10. 完成以下SQL语句。(40分)
(1) 按班级升序排序,成绩降序排序,查询student表的所有记录。
答:select * from student order by classno, score desc;
(2) 查询student表中所有二班的成绩大于85.50分且出生日期大于1982-10-31日的男生的记录。
答:select * from student where classno=2 and score>85.50 and birthday < ’31-10月-82’ and sex=’男’;
(3) 查询student表中所有三班成绩为空的学生记录。
答:select * from student where classno=3 and score is null;
(4) 表student与class联合查询,要求查询所有学生的学号,姓名,成绩,班级名称。(使用oracle与SQL 99两种格式)
答:select s.stuno, s.sname, s.score, c.cname from student s, class c where s.classno=c.classno;
(5) 按班级编号分组统计每个班的人数,最高分,最低分,平均分,并按平均分降序排序。
答:select classno, count(*), max(score), min(score), avg(score) from student group by classno order by avg(score) desc;
(6) 查询一班学生记录中所有成绩高于本班学生平均分的记录。
答:select * from student where classno=1 and score > (select avg(score) from student where classno=1);
(7) 统计二班学生中所有成绩大于所有班级平均分的人数。
答:select count(*) from student where classno=2 and score > all (select avg(socre) from student group by classno);
(8) 查询平均分最高的班级编号与分数。
答:select classno, avg(score) from student group by classno having avg(score) = (select max(avg(score)) from student group by classno);
(9) 查询所有学生记录中成绩前十名的学生的学号、姓名、成绩、班级编号。
答:select stuno, sname, score, classno from (select * from student order by score desc) where rownum<=10;
(10) 创建视图stuvu,要求视图中包含student表中所有一班学生的stuno, sname, score, classno四个属性,并具有with check option限制。
答:create view stuvu
as
select stuno, sname,score,classno from student where classno=1 with check option;

oracle_面试题01的更多相关文章

  1. Java设计模式面试题 01 - 六大原则

    Java设计模式面试题 01 - 六大原则 1. 单一职责原则 Single Responsibility Principle SRP原则 分清职责,接口一定要做到单一职责,方法也要做到,类尽量做到 ...

  2. Java实现 LeetCode 面试题 01.07. 旋转矩阵(按照xy轴转+翻转)

    面试题 01.07. 旋转矩阵 给你一幅由 N × N 矩阵表示的图像,其中每个像素的大小为 4 字节.请你设计一种算法,将图像旋转 90 度. 不占用额外内存空间能否做到? 示例 1: 给定 mat ...

  3. java面试题01

    一.JAVA基础 1.简述你所知道的JAVA修饰符及各自的使用机制?(public.abstract.final.synchronized.super…) 01.public:允许所有客户访问 02. ...

  4. 【程序员面试金典】面试题 01.03. URL化

    题目 URL化.编写一种方法,将字符串中的空格全部替换为%20.假定该字符串尾部有足够的空间存放新增字符,并且知道字符串的"真实"长度.(注:用Java实现的话,请使用字符数组实现 ...

  5. iOS面试题01

    1.#import和#include.@class有什么区别?#import<>和#import“”又有什么区别? 答:1.#import和#include都能完整地包含某个文件的内容,# ...

  6. oracle_面试题

    SELECT a.name ,IFNULL(b.name,"BOSS") FROM boss a LEFT JOIN boss b ON a.MANAGER_ID = b.ID 员 ...

  7. 算法进阶面试题01——KMP算法详解、输出含两次原子串的最短串、判断T1是否包含T2子树、Manacher算法详解、使字符串成为最短回文串

    1.KMP算法详解与应用 子序列:可以连续可以不连续. 子数组/串:要连续 暴力方法:逐个位置比对. KMP:让前面的,指导后面. 概念建设: d的最长前缀与最长后缀的匹配长度为3.(前缀不能到最后一 ...

  8. 算法初级面试题01——认识时间复杂度、对数器、 master公式计算时间复杂度、小和问题和逆序对问题

    虽然以前学过,再次回顾还是有别样的收获~ 认识时间复杂度 常数时间的操作:一个操作如果和数据量没有关系,每次都是固定时间内完成的操作,叫做常数操作. 时间复杂度为一个算法流程中,常数操作数量的指标.常 ...

  9. Linux--面试题-01

    1. 在Linux系统中,以 文件 方式访问设备 . 2. Linux内核引导时,从文件 /etc/fstab 中读取要加载的文件系统. 3. Linux文件系统中每个文件用 i节点 来标识. 4. ...

随机推荐

  1. poj 2408 Anagram Groups(hash)

    id=2408" target="_blank" style="">题目链接:poj 2408 Anagram Groups 题目大意:给定若干 ...

  2. [LeetCode169]Majority Element求一个数组中出现次数大于n/2的数

    题目: Given an array of size n, find the majority element. The majority element is the element that ap ...

  3. hibernate它 10.many2many单向

    在前文hibernate之5.many2one单向提到多对多关系,表结构设计是基于中间表来实现, 以下以用户与角色(多对多)为例,在Hibernate是怎样操作的 表结构设计: 类图: CRUD; S ...

  4. Windows 8实例教程系列 - 自定义应用风格

    原文:Windows 8实例教程系列 - 自定义应用风格 在Windows 8 XAML实例教程中,曾经提及过应用风格设计方法以及如何创建可复用样式代码.本篇将深入讨论如何创建自定义Windows8应 ...

  5. 静态常量(static final)在class文件里是如何的呢?

    近期写项目遇到一个问题,来回折腾了几次,最终探究清楚了.不废话.上样例. 背景:由于项目小,没有使用配置文件,全部静态常量都放在Config.java里面了 public class Config { ...

  6. 让你提前知道软件开发(24):C语言和主要特征的历史

    文章1部分 再次了解C语言 C语言的发展历史和主要特点 作为一门众所周知的计算机编程语言,C语言是谁发明的呢?它是怎样演进的?它有何特点?究竟有多少人在使用它? 1. C语言之父 C语言是1972年由 ...

  7. iOS多用连接、反向协议、安全

    资源 WWDC-2013-Session-708 BlackHat-US-2014-"It Just (Net)works" Understanding Multipeer Con ...

  8. 在高德地图应用api,和api展出的标记小的应用程序

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

  9. 初学者应学会如何加快seo

    新手学习如何加快seo 介绍: 应该如何初学者学习SEO,前弯路.真正的高手SEO知识. 作为一个新人,学习如何加快seo知识吧?        多人天天都在学习seo知识.看别人的文章.看多了就感觉 ...

  10. BizTalk开发小技巧

    BizTalk开发小技巧 随笔分类 - Biztalk Biztalk 使用BizTalk实现RosettaNet B2B So Easy 摘要: 使用BizTalk实现RosettaNet B2B ...