整理大公司的oracle笔试题附参考答案

nvl(name,0) 空则取0。 sustrb(manth,1,4)第一位开始取4位。 Decode(je,1,1,2),je为1的时候显示1,否则显示2.

select classno, avg(score) from student group by classno having avg(score) = (select max(avg(score)) from student group by classno);

创建表空间neuspace,数据文件命名为neudata.dbf,存放在d:data目录下,文件大小为200MB,设为自动增长,增量5MB,文件最大为500MB。(8分)

答:create tablespace neuspace datafile ‘d:dataneudata.dbf’ size 200m auto extend on next 5m maxsize 500m;

2. 假设表空间neuspace已用尽500MB空间,现要求增加一个数据文件,存放在e:appdata目录下,文件名为appneudata,大小为500MB,不自动增长。(5分)

答:alter tablespace neuspace add datafile ‘e:appdataappneudata.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分)

STUNOSNAMESEXBIRTHDAYEMAILSCORECLASSNO

从stuseq取值tom男1979-2-3 14:30:25tom@163.net89.501

从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;

1、比较大小

select decode(sign(变量1-变量2),-1,变量1,变量2) from dual; –取较小值

sign()函数根据某个值是0、正数还是负数,分别返回0、1、-1

例如:

变量1=10,变量2=20

则sign(变量1-变量2)返回-1,decode解码结果为“变量1”,达到了取较小值的目的。

2、表、视图结构转化

现有一个商品销售表sale,表结构为:

month    char(6)      –月份

sell    number(10,2)   –月销售金额

现有数据为:

200001  1000

200002  1100

200003  1200

200004  1300

200005  1400

200006  1500

200007  1600

200101  1100

200202  1200

200301  1300

想要转化为以下结构的数据:

year   char(4)      –年份

month1  number(10,2)   –1月销售金额

month2  number(10,2)   –2月销售金额

month3  number(10,2)   –3月销售金额

month4  number(10,2)   –4月销售金额

month5  number(10,2)   –5月销售金额

month6  number(10,2)   –6月销售金额

month7  number(10,2)   –7月销售金额

month8  number(10,2)   –8月销售金额

month9  number(10,2)   –9月销售金额

month10  number(10,2)   –10月销售金额

month11  number(10,2)   –11月销售金额

month12  number(10,2)   –12月销售金额

结构转化的SQL语句为:

create or replace view

v_sale(year,month1,month2,month3,month4,month5,month6,month7,month8,month9,month10,month11,month12)

as

select

substrb(month,1,4),

sum(decode(substrb(month,5,2),’01′,sell,0)),

sum(decode(substrb(month,5,2),’02′,sell,0)),

sum(decode(substrb(month,5,2),’03′,sell,0)),

sum(decode(substrb(month,5,2),’04′,sell,0)),

sum(decode(substrb(month,5,2),’05′,sell,0)),

sum(decode(substrb(month,5,2),’06′,sell,0)),

sum(decode(substrb(month,5,2),’07′,sell,0)),

sum(decode(substrb(month,5,2),’08′,sell,0)),

sum(decode(substrb(month,5,2),’09′,sell,0)),

sum(decode(substrb(month,5,2),’10′,sell,0)),

sum(decode(substrb(month,5,2),’11′,sell,0)),

sum(decode(substrb(month,5,2),’12′,sell,0))

from sale

group by substrb(month,1,4);

79、CASE语句的用法?

Oracle用法很简单:

SELECT last_name, job_id, salary

CASE job_id

WHEN ‘IT_PROG’ THEN 1.10*salary

WHEN ‘ST_CLERK’ THEN 1.15*salary

WHEN ‘SA_REP’ THEN 1.20*salary

ELSE salary END “REVISED_SALARY”

FROM employees

80、 truncate和delete的区别?

1、TRUNCATE在各种表上无论是大的还是小的都非常快。如果有ROLLBACK命令DELETE将被撤销,而TRUNCATE则不会被撤销。

2、TRUNCATE是一个DDL语言而DELETE是DML语句,向其他所有的DDL语言一样,他将被隐式提交,不能对TRUNCATE使用ROLLBACK命令。

3、TRUNCATE将重新设置高水平线和所有的索引。在对整个表和索引进行完全浏览时,经过TRUNCATE操作后的表比DELETE操作后的表要快得多。

4、TRUNCATE不能触发触发器,DELETE会触发触发器。

5、不能授予任何人清空他人的表的权限。

6、当表被清空后表和表的索引讲重新设置成初始大小,而delete则不能。

7、不能清空父表。

81、 表空间如何扩展?并用语句写出?

两种扩展方式:

a) 增加数据文件

alter tablespace tablespace_name add datafile ‘’ xxMB

b) 扩展数据文件大小

alter database datafile ‘’ resize newMB

82、 表空间区管理方式?哪种方式现在是推荐使用的?

a) 字典管理方式

extent management dictionary;默认方式

b) 本地管理方式

extent management local[autoallocate/uniform xxmb];

83、 用什么函数获得日期?和日期中的月,日,年

to_char(sysdate,’year’):tow thsound six to_char(sysdate,’yyyy’) :2006

to_char(sysdate,’month’):8月 to_char(sysdate,’mm’):08

to_char(sysdate,’day’):星期4 to_char(sysdate,’dd’):22

84、 分区表的应用?

a) 一个分区表有一个或多个分区,每个分区通过使用范围分区、散列分区、或组合分区分区的行

b) 分区表中的每一个分区为一个段,可各自位于不同的表空间中

c) 对于同时能够使用几个进程进行查询或操作的大型表分区非常有用

85、 谈谈索引的用法及原理?

索引是若干数据行的关键字的列表,查询数据时,通过索引中的关键字可以快速定位到要访问的记录所在的数据块,从而大大减少读取数据块的I/O次数,因此可以显著提高性能。

86、 存储过程的应用,如何既有输入又有输出?

Create procedure pro_name

(xxxx in/out type;

yyyy in/out/inout type;

) is/as

zzzz type;

begin

sqlpro;

exception

exceptionxxxxx;

commit;

end;

87、 常发生的异常有哪些?

常用预定义例外

CURSOR_ALREADY_OPEN — ORA-06511 SQLCODE = -6511 游标已经打开

DUP_VAL_ON_INDEX — ORA-00001 SQLCODE = -1 违反唯一性约束

INVALID_CURSOR — ORA-01001 SQLCODE = -1001 非法游标操作

INVALID_NUMBER — ORA-01722 SQLCODE = -1722 字符向数字转换失败

LOGIN_DENIED — ORA-01017 SQLCODE = -1017

NO_DATA_FOUND — ORA-01403 SQLCODE = +100 没有找到数据

NOT_LOGGED_ON — ORA-01012 SQLCODE = -1012 没有连接到数据库

PROGRAM_ERROR — ORA-06501 SQLCODE = -6501 内部错误

STORAGE_ERROR — ORA-06500 SQLCODE = -6500

TIMEOUT_ON_RESOURCE — ORA-00051 SQLCODE = -51

TOO_MANY_ROWS — ORA-01422 SQLCODE = -1422 返回多行

TRANSACTION_BACKED_OUT — ORA-00061 SQLCODE = -61

VALUE_ERROR — ORA-06502 SQLCODE = -6502 数值转换错误

ACCESS_INTO_NULL试图为NULL对象的属性赋值

ZERO_DIVIDE — ORA-01476 SQLCODE = -1476 被零除

OTHERS — 其它任何错误的处理

88、 如何使用异常?

在oracle中有三种类型的异常。预定义的异常 非预定义的异常 用户定义的异常 第二种非预定义的异常是与特定的oracle错误关联。并且用PRAGM EXCEPTION_INIT(EXCEPTION_NAME,ERROR_NUMBER)关联一起的。但是到底有什么用啊? 例如:declare dup_primary_key exception; pragma exception_init(dup_primary_key,-1); begin insert into itemfile values(‘i201′,’washer’,'spares’,100,50,250,12,30); exception when dup_primary_key then dbms_output.put_line(‘重复项编号-主键冲突’); end

第一种的使用方法:exception

when 异常名称 then

异常处理代码;

第三种的用法:if 条件 then

raise_application_error(-20000“““`-20999,提示信息);

end if;

89、优化的策略一般包括:

• 内存优化

• 操作系统优化

• 数据存储的优化

• 网络优化等方法

具体到不同的数据库涉及到要调整不同的数据库配置文件、不同的操作系统参数、网络参数等等, 不同的数据库不同

时间: 2024-08-01 11:35:08

整理大公司的oracle笔试题附参考答案的相关文章

15道非常经典的Java面试题 附详细答案_java

试题如下: 参考答案: import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; /** * Created by ysc on 7/26/16. */ public class Interview {

整理的2014年各大互联网公司前端JavaScript笔试题

前面几题是会很基础,越下越有深度. 初级Javascript: 1JavaScript是一门什么样的语言,它有哪些特点? 没有标准答案. 2.JavaScript的数据类型都有什么? 基本数据类型:String,boolean,Number,Undefined, Null 引用数据类型:Object(Array,Date,RegExp,Function) 那么问题来了,如何判断某变量是否为数组数据类型?     方法一.判断其是否具有"数组性质",如slice()方法.可自己给该变量定

‘大公司’的PHP面试题

http://topic.111cn.net/u/20071202/16/e53996de-4725-4dfa-bf14-c197afeed93c.html     <?phpclass engage{    public function getArray()    {        $arr1 = array (        ''0'' => array (''fid'' => 1, ''tid'' => 1, ''name'' => ''Name1'' ),     

网页设计制作试题及参考答案

网页设计与制作试题 第一部分 选择题一.单项选择题(本大题共20小题,每小题1分,共20分.在每小题的四个备选答案中,选出一个正确答案,并将正确答案的字母填在题干的括号内) 1.目前在Internet上应用最为广泛的服务是(      )  A.FTP服务                 B.WWW服务  C.Telnet服务              D.Gopher服务2.在域名系统中,域名采用(      )  A.树型命名机制            B.星型命名机制  C.层次型命名机制

Spring,hibernate,struts经典面试笔试题(含答案)_java

本文讲述了Spring,hibernate,struts经典面试笔试题及其参考答案.分享给大家供大家参考,具体如下: 1.Hibernate工作原理及为什么要用? 原理: 1.读取并解析配置文件 2.读取并解析映射信息,创建SessionFactory 3.打开Sesssion 4.创建事务Transation 5.持久化操作 6.提交事务 7.关闭Session 8.关闭SesstionFactory 为什么要用: ① . 对JDBC访问数据库的代码做了封装,大大简化了数据访问层繁琐的重复性代

JS经典正则表达式笔试题汇总_javascript技巧

本文实例总结了JS经典正则表达式笔试题.分享给大家供大家参考,具体如下: 一.复习字符串的传统操作 如何获取一个字符串中的数字字符,并按数组形式输出,如 dgfhfgh254bhku289fgdhdy675gfh 输出[254,289,675] 分析:循环用charAt()的方法获取到每一个子字符串,判断他是不是在0~9之间,是就把他扔到准备好的数组里 var str="dgfhfgh254bhku289fgdhdy675gfh"; findNum(str); function fin

Java面试笔试题大汇总(最全+详细答案)

声明:有人说, 有些面试题很变态,个人认为其实是因为我们基础不扎实或者没有深入.本篇文章来自一位很资深的前辈对于最近java面试题目所做的总结归纳,有170道题目 ,知识面很广 ,而且这位前辈对于每个题都自己测试给出了答案 ,如果你对某个题有疑问或者不明白,可以电脑端登录把题目复制下来然后发表评论,大家一起探讨,也可以电脑端登录后关注我给我发私信,我们一起进步! 以下内容来自这位前辈 2013年年底的时候,我看到了网上流传的一个叫做<Java面试题大全>的东西,认真的阅读了以后发现里面的很多题

要出发公司笔试题

前言 招聘高峰期来了,大家都非常积极地准备着跳槽,那么去一家公司面试就会有一堆新鲜的问题,可能不会,也可能会,但是了解不够深.本篇文章为群里的小伙伴们去要出发公司的笔试题,由笔者整理并提供笔者个人参考答案.注意,仅供参考,不代表绝对正确. 参考答案不唯一,大家可以根据自己的理解回答,没有必要跟笔者的一样.参考笔者的答案,也许给你带来灵感! 题目照 1.编程规范问题 这题看不清楚,不过可以看得出来是编程规范问题.所以呢,笔者也就没有办法说明哪些不合理了.不过笔者曾经为公司的出过一个编程规范文档,后

java算法题,公司的笔试题

问题描述 java算法题,公司的笔试题 suppose you have N cakes, N is an interger>0 // at each time, you can either eat 1 cake, or 2 cakes or 3 cakes // PROBLEM: How many ways can you eat all N cakes // for example, N = 4, (1,2,1) and (1,1,2) are considered to be diffe