一、选择题(每题1分)
A Oracle发出下列select语句:
SQL> select e.empno, e.ename, d.loc
2 from emp e, dept d
3 where e.deptno = d.deptno
4 and substr(e.ename, 1, 1) = ‘S’;
下列哪个语句是Oracle数据库中可用的ANSI兼容等价语句?
A.select empno, ename, loc from emp join dept on emp.deptno = dept.deptno where
substr(emp.ename, 1, 1) = ‘S’;
B.select empno, ename, loc from emp, dept on emp.deptno = dept.deptno where
substr(emp.ename, 1, 1) = ‘S’;
C.select empno, ename, loc from emp join dept where emp.deptno = dept.deptno and
substr(emp.ename, 1, 1) = ‘S’;
D.select empno, ename, loc from emp left join dept on emp.deptno = dept.deptno and
substr(emp.ename, 1, 1) = ‘S’;
C你要对操纵Oracle数据库中的数据。下列哪个选项表示Oracle中select语句的功能,并且不需要使用子查询?
A.可以用select语句改变Oracle中的数据 B.可以用select语句删除Oracle中的数据
C.可以用select语句和另一个表的内容生成一个表 D.可以用select语句对表截断
D Oracle数据库中发出一个查询。下列哪个选项不能查询对用户定义静态表达式执行数学运算时的查询组件?
A.列子句 B.表子句 C.DUAL表 D.W==here子句
B你要操纵Oracle数据,下列哪个不是SQL命令?
A.select * from dual; B.set define
C.update emp set ename = 6543 where ename = ‘SMITHERS’;
D.create table employees(empid varchar2(10) primary key);
C你要在Oracle中定义SQL查询。下列哪个数据库对象不能直接从select语句中引用?
A.表 B.序列 C.索引 D.视图
C你要根据PRODUCT_NAME列从PROFITS表查询中过滤返回的数据。下列哪个子句包含相应过滤条件的引用?
A.select B.from C.where D.having
C下列代码显示了PROFITS表输出的局部:
PRODUCT_NAME PRODUCT_TYPE QTR_END_DATE PROFIT
------------ ------------ ------------ -------------
BARNEY DOLL TOY 31-MAR-2001 6575430.30
GAS GRILL APP 31-MAR-2001 1234023.88
PENCIL OFFICE 30-JUN-2001 34039.99
下列查询的where子句哪个能正确计算2001年1月1日到6月1日六个月内销售的所有家电总利润?
A.where product_name = ‘GAS GRILL’ and qtr_end_date between ’01-JAN-2001’ and ‘01-JUN-2001’;
B.where proeuct_type = ‘APPLIANCE’ and name = ‘GAS GRILL’ and qtr_end_date
= ’31-JAN-2001’ or ‘30-JUN-2001’;
C.where proeuct_type = ‘APPLIANCE’ and qtr_end_date between ’01-JAN-2001’ and ’01-JUN-2001;
D.where proeuct_name = ‘GAS GRILL’ and qtr_end_date = ’01-JAN-2001’ or ‘01-JUN-2001’;
用下列代码所示的内容回答后面八个问题:
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
------ ---------- --------- ---- --------- ---- ---- ------
7369 SIMTH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-82 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SET-81 1500 0 30
7876 ADAMS CLERK 7788 23-DEC-82 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10
D以下选项中哪个是下列查询返回的值:select sum(sal) + sum(comm) from emp where job = ‘ANALYST’ or ename like ‘J%’ ?
A.6000 B.9925 C.9975 D.NULL
C以下选项中哪个是下列查询返回的值:select count(mgr) from emp where deptno = 10 ?
A.1 B.2 C.3 D.NULL
A以下选项中哪个是下列查询返回的值:select count(*) from emp where mgr = 7700-2 ?
A.5 0 B.6 C.7 D.NUL
D以下选项中哪个是下列SQL命令产生的第三个员工:select ename, sal from emp where job= ‘SALESMAN’ order by empno desc ?
A.ALLEN B.MARTIN C.TURNER D.WARD
B以下选项中哪个是下列SQL命令产生的第三个员工:ename, sal from emp where job= ‘SALESMAN’ order by 1 desc ?
A.ALLEN B.MARTIN C.TURNER D.WARD
C以下选项中哪个是发出下列查询后Oracle返回的值:select substr(job, 1, 3) from emp where ename like upper(‘__ar%’) ?
A.ANA B.CLE C.MAN D.SAL
C以下选项中哪个是发出下列查询后Oracle返回的值:select trunc(months_between(min(hiredate), max(hiredate))) from emp ?
A.24 B.25 C.-24 D.-25
AC以下选项中哪个是发出下列查询后Oracle返回的值:select * from emp where hiredate >
’23-JAN-82’ ?(选择两个答案)
A.ADAMS B.MILLER C.SCOTT D.SMITH
DDTEST表包含两个列,TESTCOL定义为数据类型NUMBER(10),TESTCOL_2定义为数据类型VARCHAR2(10)。在Oracle中发出下列语句:insert into test(testcol, testcol_2) values (null, ‘FRANCIS’),然后对表进行下列查询:select nvl(testcol, ‘EMPTY’) as testcol from test where testcol_2 = ‘FRANCIS’。下列选项哪个是得到的结果?
A.Oracle返回结果0 B.Oracle返回结果EMPTY
C.Oracle返回结果NULL D.Oracle返回错误结果
D要从ORDERS表中取得数据,其中包括三个列CUSTOMER、ORDER_DATE与ORDER_AMT。可以用下列哪个where子句查询ORDERS表,取得客户LESLIE超过2700的订单?
A.where customer = ‘LESLIE’;
B.where customer = ‘LESLIE’ and order_amt < 2700;
C.where customer = ‘LESLIE’ or order_amt > 2700;
D.where customer = ‘LESLIE’ and order_amt > 2700;
B用下列输出回答问题(假设这里的信息来自本章使用的EMP表):
EMPNO
----------
SMITH-dog-
ALLEN-dog-
WARD-dog-d
JONES-dog-
MARTIN-dog
BLAKE-dog-
CLARK-dog-
SCOTT-dog-
KING-dog-d
TURNER-dog
JAMES-dog-
FORD-dog-d
MILLER-dog
下列哪个SQL语句产生这个输出?
A.select trim(trailing ‘-dog’ from ename) as ename from emp;
B.select rpad(ename, 10, ‘-dog’) as ename from emp;
C.select substr(ename,1 , 10) as ename from emp;
D.select lpad(ename, 10, ‘-dog’) as ename from emp;
A用下列代码块回答问题:
SQL> select ______(-45) as output from dual;
OUTPUT
------
-45
下列哪个单行函数无法产生这个输出?
A.abs() B.ceil() C.floor() D.round()
B对表中的某一行,VARCHAR2列包含数值SMITHY,应用程序在右侧填充七个空格。length()函数处理这个列值时,返回什么值?
A.6 B.13 C.30 D.60
B SQL *Plus中发出的下列语句:
SQL> select ceil(-97.342),
2 floor(-97.342),
3 round(-97.342),
4 trunc(-97.342)
5 from dual;
下列哪个函数不返回结果-97?
A.ceil() B.floor() C.round() D.trunc()
A SQL *Plus中发出的下列语句:
SQL> select ceil(256.342),
2 floor(256.342),
3 round(256.342),
4 trunc(256.342)
5 from dual;
下列哪个函数不返回结果256?
A.ceil() B.floor() C.round() D.trunc()
D在Oracle中发出的下列查询:
SQL> select months_between(‘15-MAR-83’,’15-MAR-97’) form dual;
Oracle返回什么?
A.14 B.-14 C.168 D.-166
D你要在Oracle中使用日期信息的格式掩码。下列哪种情形不适合这个格式掩码?
A.to_date() B.to_char() C.alter session set nls_date_format D.to_number()
C数据库中有两表PRODUCT与STORAGE_BOX,PRODUCT表中列出各个产品的惟一ID号、产品名和特定产品所在的箱子。另一个表中列出各个存储箱(用数字标识)可以包含许多产品,但每个箱子只能在一个地方。下列哪个语句能正确显示这个数据库中所有产品ID、名称和箱子地址?
A.select p.prod_id, p.prod_name, b.box_loc from product p, storage_box b where
p.prod_id = b.prod_id and prod_name=’WIDGET’;
B.select p.prod_id, p.prod_name, b.box_loc from product p, storage_box b where
prod_name=’WIDGET’;
C.select p.prod_id, p.prod_name, b.box_loc from product p, storage_box b where
p.stor_box_num = b.stor_box_num and prod_name=’WIDGET’;
D.select prod_id, prod_name, box_loc from product , storage_box where
stor_box_num = stor_box_num and prod_name=’WIDGET’;
B开发报表时,要连接三个表的信息,这些表为EMP、DEPT与SALGRADE。只需要公司10级以上员工相应的员工、部门地址与工资范围的记录。这个查询需要多少比较运算?
A.2 B.3 C.4 D.5
C要连接两个表PRODUST与STOTAGE的内容,列出所有包含产品的箱子地址。PRODUCT有三列ID、NAME与BOX#;STORAGE有两列BOX#与LOC。下列哪个选项无法得到想要的结果?
A.select product.id, product.name, storage.loc from product, storage where product.box#=storage.box#;
B.select product.id, product.name, storage.loc from product join storage on product.box#=storage.box#;
C.select product.id, product.name, storage.loc from product natural join storage on product.box#=storage.box#;
D.select product.id, product.name, storage.loc from product natural join storage;
D你要定义外连接,下列哪个选项正确描述了外连接语句?
A.由于外连接操作允许一个表中有NULL值,因此连接这些表时不必指定相等性比较。
B.在表A与B的外连接语句中,如果不管B表有无相应记录,都要显示表A的所有行,
则可以使用右外连接。
C.在表A与B的外连接语句中,如果不管A表有无相应记录,都要显示表B的所有行,
则可以使用左外连接。
D.尽管外连接操作允许一个表中有NULL值,但连接这些表时仍要指定相等性比较。
B数据库中有两个表PRODUCT与STORAGE_BOX,表中列出各个产品的惟一ID号、产品名和特定产品所在的箱子。另一个表中列出各个存储箱(用数字标识)可以包含许多产品,但每个箱子只能在一个地方。下列哪个语句能正确显示这个数据库中所有产品ID、名称和箱子地址,不管有没有指定存储箱?
A.select p.prod_id, p.prod_name, b.box_loc from product p left outer join storage_box b on p.stor_bax_num = b. stor_bax_num where prod_name=’WIDGET’(+);
B.select p.prod_id, p.prod_name, b.box_loc from product p left outer join storage_box b on p.stor_bax_num = b. stor_bax_num where prod_name=’WIDGET’ ;
C.select p.prod_id, p.prod_name, b.box_loc from product p right outer join storage_box b where b.stor_bax_num = p. stor_bax_num(+) and prod_name=’WIDGET’(+);
D.select p.prod_id, p.prod_name, b.box_loc from product p full outer join storage_box b on p.stor_bax_num = b. stor_bax_num where b.stor_box_num is NULL ;
C Oracle中发出下列命令:
SQL> select e.ename,a.street_address,a.city,a.post_code
2 from emp e,addr a
3 where e.empno = a.empno(+)
4 and a.state = ‘TEXAS’;
下列哪个选项显示等价ANSI/ISO语句?
A.select e.ename, a.street_address, a.city, a.state, a.post_code from emp e outer join addr a on e.empno = a.empno where a.state = ‘TEXAS’;
B.select e.ename, a.street_address, a.city, a.state, a.post_code from emp e left outer join addr a on e.empno = a.empno where a.state = ‘TEXAS’;
C.select e.ename, a.street_address, a.city, a.state, a.post_code from emp e right outer join addr a on e.empno = a.empno where a.state = ‘TEXAS’;
D.select e.ename, a.street_address, a.city, a.state, a.post_code from emp e right outer join addr a where e.empno = a.empno(+) and a.state = ‘TEXAS’;
A检查SQL *Plus的下列输出:
PRODUCT.ID PRODUCT.NAME BOX.LOCATION
---------- ------------ ------------
578-X WIDGET IDAHO
TENNESSEE
456-Y WIDGET
下列哪个选项是产生这个结果的查询类型?
A.全外连接 B.左外连接 C.右外连接 D.等连接
DPROFITS表存储公司不同地区、产品类型和季度的利润信息。下列哪个SQL语句显示不同地区、产品类型和季度的利润的交叉表输出?
A.select region, product_type, time, sum(profit) from profits group by region, prod_type, time;
B.select region, product_type, time from profits group by rollup(region, prod_type, time);
C.select region, product_type, time, from profits group by cube(region, prod_type, time);
D.select region, product_type, time,sum(profit) from profits group by cube(region, prod_type, time);
C对数据库运行下列哪个group by查询时会从Oracle产生错误?
A.select deptno, job, sum(sal) from emp group by job, deptno;
B.select sum(sal), deptno, job from emp group by job, deptno;
C.select deptno, job, sum(sal) from emp;
D.select deptno, sum(sal), job from emp group by job, deptno;
D检查下列SQL的输出
SQL> select a.deptno,a.job,b.loc,sum(a.sal)
2 from dmp a,dept b
3 where a.deptno = b.depton
4 group by a.deptno,a.job,b.loc
5 order by sum(a.sal);
这个查询按哪个列的顺序返回输出?
A.A.DEPTON B.A.JOB C.B.LOC D.SUM(A.SAL)
C要查询的PROFITS表存储公司不同地区、产品类型和季度的利润信息。下列哪个SQL语句按不同地区、产品类型和季度求出平均利润大于100000美元的利润?
A.select region, prod_type, period, avg(profits) from profits where avg(prodit) > 100000 group by region, prod_type, period;
B.select region, prod_type, period, avg(profits) from profits where avg(prodit) > 100000 order by region, prod_type, period;
C.select region, prod_type, period, avg(profits) from profits group by region, prod_type, period having avg(prodit) > 100000;
D.select region, prod_type, period, avg(profits) from profits group by region, prod_type, period having avg(prodit) < 100000;
C公司的员工费用应用程序有两表,一个是EMP,包含所有员工数据,一个是EXPENSE,包含公司每个员工提交的费用票据。下列哪个查询取得提交的费用总和超过其工资值的员工ID与姓名?
A.select e.empno, e.ename from emp e where e.sal < (select sum(x.vouch_amt) from expense x) and x.empno = e.empno;
B.select e.empno, e.ename from emp e where e.sal < (select x.vouch_amt from expense x where x.empno = e.empno);
C.select e.empno, e.ename from emp e where e.sal < (select sum(x.vouch_amt) from expense x where x.empno = e.empno);
D.select e.empno, e.ename from emp e where exists (select sum(x.vouch_amt) from expense x where x.empno = e.empno);
B看看下列语句:
SQL> select ename
2 from emp
3 where empno in
4 ( select empno
5 from expense
6 where vouch_amt > 10000 );
下列哪个SQL语句产生与上面相同的输出,改写成使用运算符?
A.select e.ename from emp e where exists(select x.empno from expense x where x.vouch_amt>10000) and x.empno = e.empno;
B.select e.ename from emp e where exists(select x.empno from expense x where x.vouch_amt>10000 and x.empno = e.empno);
C.select e.ename from emp e where x.empno = e.empno and exists(select x.empno from expense x where x.vouch_amt>10000)
D.select e.ename from emp e, expense x where x.empno = e.empno and x.vouch_amt>10000 and exists(select x.empno from expense x where)
A用下列代码块回答问题:
SQL> select deptno,job,avg(sal)
2 from emp
3 group by deptno,job
4 having avg(sal)>
5 ( select sal
6 from emp
7 where ename = ‘MARTIN’ );
上述语句使用下面哪种子查询?
A.单行子查询 B.多行子查询 C.from子句子查询 D.多列子查询
A公司销售数据库有两个表,PROFITS存储不同地区不同季度的产品销售利润,REGIONS存储每个部门地区名称、该地区总部地址和该地区副总裁姓名。下列哪个查询取得SMITHERS、FUJIMORI与LIKKARAJU领导的地区的玩具销售利润?
A.select sum(profit) from profits where region in (select region froms regions where reg_head in (‘SMITHERS’, ‘FUJMORI’, ‘LAKKARAJU’)) and product =’TOYS’;
B.select sum(profit) from profits where region like (select region froms regions where reg_head in (‘SMITHERS’, ‘FUJMORI’, ‘LAKKARAJU’) and product =’TOYS’ );
C.select sum(profit) from profits where region = (select region froms regions where reg_head in (‘SMITHERS’, ‘FUJMORI’, ‘LAKKARAJU’)) and product =’TOYS’;
D.select sum(profit) from profits where region is (select region froms regions where reg_head in (‘SMITHERS’, ‘FUJMORI’, ‘LAKKARAJU’)) and product =’TOYS’;
C下列代码块显示的查询包含一个子查询:
SQL> select dname, avg(sal) as dept_avg
2 from emp, dept
3 where emp.deptno = dept.deptno
4 group by dname having avg(sal) >
5 ( select avg(sal)*1/4
6 from emp,dept
7 where emp.deptno = dept.deptno )
8 order by avg(sal);
可以用下列哪个子句重新定义这个查询,删除子查询与主查询中组函数执行的重复?
A.group by B.order by C.with D.having
B用下列代码块回答问题:
SQL> select e.deptno,e.ename,e.job,e.sal
2 from emp e
3 where e.sal =
4 ( select max(e2.sal)
5 from emp e2
6* where nvl(e.deptno,99) = nvl(e2.deptno,99));
DEPTNO ENAME JOB SAL
--------- ---------- ---------- ---------
30 BLAKE MANAGER 2850
10 CLARK MANAGER 2450
20 SCOTT ANALYST 3000
KING PRESIDENT 5000
20 FORD ANALYST 3000
要在上述返回集的DEPTNO列中显示99,可以用下列哪个SQL语句?
A.select nvl(e.deptno,99), e.ename, e.sal from emp e where (e.deptno, e.sal) = (select max(e2.sal) from emp e2 where nvl(e.dept, 99) = nvl(e2.deptno, 99));
B.select nvl(e.deptno,99), e.ename, e.sal from emp e where e.sal = (select max(e2.sal) from emp e2 where nvl(e.dept, 99) = nvl(e2.deptno, 99));
C.select nvl(e.deptno,99), e.ename, e.sal from emp e where (e.deptno, e.sal) = (select e2.deptno,max(e2.sal) from emp e2 where nvl(e.dept, 99) = nvl(e2.deptno, 99));
D.select nvl(e.deptno,99), e.ename, e.sal from emp e where (e.deptno, e.sal) = (select e2.deptno,max(e2.sal) from emp e2 where nvl(e.dept, 99) = nvl(e2.deptno, 99) group by e1.deptno);
C公司销售数据库包含一个PROFITS表,按产品名、销售地区和季度列出利润信息。如果要取得公司五个最畅销产品清单,可以用下列哪个SQL语句:
A.select p.prod_name, p.profit from (select prod_name, profit from profits order by profit desc) where rownum <= 5;
B.select p.prod_name, p.profit from (select prod_name, sum(profit) from profits group by prod_name order by sum(profit) desc) subq where p.prod_name = subq.prod_name;
C.select p.prod_name, p.profit from (select prod_name, sum(profit) from profits group by prod_name order by sum(profit) desc) where rownum <= 5;
D.select p.prod_name, p.profit from (select prod_name, sum(profit) from profits
order by sum(profit) desc) where rownum <= 5;
A检查下列代码段中的脚本dates.sql:
accept v_hiredate prompt ‘enter hire date => ’
select empno, ename, job
from emp
where trunc(hiredate) = trunc(‘&v_hiredate’);
为了使脚本正确工作,要改变哪个方面?
A.变量v_hiredate应变成接受DATE信息。 B.查询中的trunc()函数应删除。
C.accept命令中的prompt子句是多余的。 D.这个脚本很好。
D Oracle中要生成数据库表,下列哪个选项是无效表生成的语句?
A.create table cats(c_name varchar2(10), c_weight number, c_owner varchar2(10));
B.create table my_cats as select * from cats where owner = ‘ME’;
C.create global temporary table temp_cats(c_name varchar2(10), c_weight number, c_owner varchar2(10));
D.create table 51cats as select c_name, c_weight from cats where c_weight > 5;
C试图在Oracle生成表时遇到下列错误:ORA-00955-name is already used by existing object。下列哪个选项无法纠正这个错误?
A.以不同的用户身份生成对象。 B.删除现有同名对象
C.改变生成对象中的列名。 D.更名现有同名对象。
BSALES表中的PROFITS列声明为NUMBER(10, 2)。下列哪个值无法在这个列中存储?
A.5392845.324 B.871039453.1 C.75439289.34 D.60079829.25
B员工KING于1981年11月17日聘用,你对Oracle数据库发出下列查询:select vsize(hiredate) from emp where ename = ‘KING’。下列哪个选项是返回的值?
A.4 B.7 C.9 D.17
CSALES表中将PRODUCT_NAME列定义为CHAR(40)。后面要在表中增加一行,PRODUCT_NAME值为CAT_TOYS。然后发出下列命令:select vsize(product_name) from sales。下列哪个选项是返回的值?
A.8 B.12 C.40 D.4000
DJOB表有三个列JOB_NAME、JOB_DESC和JOB_WAGE。用下列命令在JOB_DESC表中插入新行:
SQL> insert into job(job_name, job_desc)
2 values (‘LUCKEY’, ‘MAKES COFFEE’);
之后查询这个表时得到的结果:
SQL> select * from job where job_name = ‘LUCKEY’;
JOB_NAME JOB_DESC JOB_WAGE
--------- ------------ --------
LUCKEY MAKES COFFEE 35
数据是如何填信JOB_WAGE表的?
A.JOB表中的LACKEY行已经存在,JOB_WAGE设置为35。
B.生成表时JOB_WAGE列定义的default子句指定插入行时的值。
C.insert语句的values子句包含隐藏值,在插入行时加入。
D.惟一理由是对JOB表发出的后一个update语句增加了JOB_WAGE值
B删除Oracle数据库中父/子关系中的父表。在删除父表时下列哪个对象不会删除?
A.相关约束 B.子表 C.相关触发器 D.相关索引
二、问答题(每题10分)
1. 什么是事务、特点、在Oracle中具体的应用?
2. oracle中如何获取系统时间?
3. Truncate与 delete的区别?
4. DDL和DML分别代表什么?
5. Oracle使用什么语句给用户分配权限?
答案:
选择题:
1.A 2.C 3.D 4.B 5.C
6.C 7.C 8.D 9.C 10.A
11.D 12.B 13.C 14.C 15.AC
16.D 17.D 18.B 19.A 20.B
21.B 22.A 23.D 24.D 25.C
26.B 27.C 28.D 29.B 30.C
31.A 32.D 33.C 34.D 35.C
36.C 37.B 38.A 39.A 40.C
41.B 42.C 43.A 44.D 45.C
46.B 47.B 48.C 49.B 50.B
问答题:
1. 事务是数据库中最小的一个逻辑工作单元。
特点:ACID,分别指
事务的原子性:就是事务所包含的数据库操作要么都做,要么都不做;
事务的一致性:是事务原子性的体现,事务所对应的数据库操作要么成功要么失败没有第三种情况。事务不管是提交成功与否都不能影响数据库数据的一致性状态;
事务的隔离性:事务对数据的操作不能够受到其他事务的影响;
事务的持续性:也就是说事务对数据的影响是永久的。
在oracle中已commit或rollback作为上一个事务的结束标志及下一个新事物开始的标志。
2. select sysdate from dual;
3. delete一般用于删除少量记录的操作,而且它是要使用回滚段并且要进行显示的提交事务。而truncate则使用于大量删除数据,而且隐式提交事务,其速度要比使用delete快的
4. DDL表示数据定义语言,在ORACLE中主要包括CREATE,ALTER,DROP;
DML表示数据操作语言,主要的DML有SELECT,INSERT,UPDATE,DELETE.
5. GRANT 权限列表TO 用户;