欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

oracle基础测试1

程序员文章站 2024-02-26 23:53:40
...

Oracle试题

得分 一、选择题(每小题2分,共20分)

1.关于类型定义Number(9,2)说法正确的有( B )
A.整数部分9位,小数部分2位,共11位
B.整数部分7位,小数部分2位,共9位
C.整数部分6位,小数点一位,小数部分2位,共9位
D.以上说法均不正确

  1. 获取当前系统时间的查询语句是( C )
    A.Sysdate
    B.Select sysdate
    C.Select sysdate from dual;
    D.以上都可以

  2. 在数据库中可以创建和删除表、视图、索引,可以修改表。这是因为数据库管理系统提供了( A )
    A.数据定义功能
    B.数据操纵功能
    C.数据维护功能
    D.数据控制功能

    1. 下列属于DDL语言的是( C )
      A.insert
      B.select
      C.create
      D.commit
  3. 数据库的并发操作可能带来的问题包括( B )
    A.非法用户的使用
    B.丢失更新
    C.数据独立性会提高
    D.增加数据冗余度

    6.使用sql查询时,使用where子句指出的是( B )
    A.查询目标
    B.查询条件
    C.查询视图
    D.查询结果

  4. 有表一的查询结果如下,该表为学生成绩表:
    select id,grade from student_grade
    ID GRADE


    1 50
    2 40
    3 70
    4 80
    5 30
    6 90
    表二为补考成绩表
    select id,grade from student_makeup
    ID GRADE


1            60 
2            80 
5            60 

现在通过如下语句把补考成绩更新到成绩表中,并提交:
update student_grade s set s.grade =
(select t.grade from student_makeup t
where s.id=t.id);
commit;
请问之后查询:
select GRADE from student_grade where id = 3;结果为( C )
A. 0
B. 70
C. Null
D. 以上都不对

  1. 在Oracle中,下面哪条语句当COMM字段为空时显示0,不为空时显示COMM的值( A )
    A.SELECT ename, NVL(comm, 0) FROM emp;
    B.SELECT ename, NULL(comm, 0) FROM emp;
    C.SELECT ename, NULLIF(comm, 0) FROM emp;
    D.SELECT ename, DECODE(comm, NULL, 0) FROM emp;

    1. 在Oracle中,有一个教师表teacher的结构如下:
      ID NUMBER(5)
      NAME VARCHAR2(25)
      EMAIL VARCHAR2(50)
      下面哪个语句显示没有Email地址的教师姓名( C )
      A.SELECT name FROM teacher WHERE email = NULL;
      B.SELECT name FROM teacher WHERE email <> NULL;
      C.SELECT name FROM teacher WHERE email IS NULL;
      D.SELECT name FROM teacher WHERE email IS NOT NULL;

10.根据上述语法规则,以下哪个不是有效的Lambda表达式?(C)
A.(Double d) -> {}
B.() -> “tom”
C.(Integer i) -> return “Rose” + i;
D.(String s)-> {return “Nana”;}

得分    二、填空题 (第1题4分,其余每空2分,共30分)


	1. 使用SELECT语句显示当前系统时间,显示格式为如:2018-01-09 22:22:22
     Select to char(sysdate,’yyyy-mm-dd hh24:mi:ss’) from dual;
  1. 数据库事务的特性__原子性__、一致性隔离性_、持久性__。

  2. 执行脚本estore.sql文件的两种方式[email protected]和_start_。

     4. oracle通配符:“_”代表:  通配一个字符   ;“%”代表 通配任意多个字符  ,
    

通过 escape 关键字将字符转义。

  1. oracle数据库字符函数的substr(‘helloworld’,3,4)操作的结果是:llow

  2. select ‘123’ + 123 from dual;的查询为结果 246。

  3. select ‘123’ || 123 from dual;的查询为结果 123123 。

  4. 查看当前用户是谁的命令是 show uesr。

得分 三、简答题 (每题5分,共25分)

1、什么是ACID?
事务特征ACID:
原子性:Atomicity
同时成功或者同时失败
一致性:Consistency
事务执行的结果必须是使数据库从一个一致性状态变到另一个一致性状态。
隔离性:Isolation
事务操作应该相互独立
持久性:Durability
事务所做的影响 ,在事务结束之后应该能够是持久的。
2、说一下视图的作用?
视图的作用:
1.限制数据访问
2.简化复杂查询
3.提供数据的相互独立
4.同样的数据,可以有不同的显示方式

3、请简述jdbc的六大步骤。
一、 注册驱动
二、 获取连接
三、 创建statement对象
四、 执行sql语句
五、 处理结果集
六、 关闭资源
4、请简述Statement对象和PreparedStatement对象的关系和区别。
Statement:
1.创建时不需要传递sql语句,但是执行时需要传递sql语句
2.如果涉及到动态参数的传递,必须使用字符串拼接

PreparedStatement:
1.创建时就需要传递sql语句,执行的时候不需要传递sql语句
2.如果涉及到动态参数的传递,可以使用字符串拼接,也可以使用?占位的形式
3.提供预编译的功能,某种程度上可以避免sql注入的问题
4.提前做语法检查,在给?赋值的过程中要求数据类型一定要匹配,这样在某种程度上可以避免因为数据类型不匹配而发生的异常

5、阐述java8中接口的新特性。
(1) 增加default方法。default方法作用范围也是public,只是有了具体实现的方法体。对已有的接口,如果想对接口增加一个新方法,那么需要对所有实现该接口的类进行修改。而有了default方法,可以解决该问题。
(2) 新增static方法。static修饰的方法也是非抽象方法,使用同类的静态方法一样,给方法的调用带来了方便。程序入口main方法也是static,现在接口也可以运行了。

得分    四、代码设计题 (第1题8分,第二题5分,第三题6分,第四题6分,共25分)

1.完成下列sql语句的编写。(8分)
1).精确计算现在到年底还有多少个月?(2分)
select months_between(’31-12月-18’,sysdate) from dual;
2).统计公司有多少个不重复的部门?(2分)
select count(distinct dept_id) from s_emp;
3).查询工资比20号部门任意一个员工工资低的员工信息?(2分)
select * from s_emp
where salary<any(select salary from s_emp
where dept_id=20);
4).查看薪资高于Chang的经理薪资的员工信息?(2分)
select * from s_emp where salary >(
select salary
from s_emp
where id = (
select manager_id
from s_emp
where last_name=‘Chang’
)
);

2.使用子查询 查询除了31号部门平均工资大于1200的部门中员工信息。(5分)
select last_name,salary,dept_id
from s_emp
where dept_id != 31
and dept_id in(
select dept_id
from s_emp
group by dept_id
having avg(salary)>1200
);

3.创建表student,包括id,name,gender,salary字段,使用check约束(id作为主键,性别只能是男或女,salary介于6000到8000之间,所有字段都不能为空)。创建完成后并完成下列操作。(建表2分)
1).将student表重命名为stu;(1分)
2).修改student表中salary列的名字为sal;(1分)
3).以最快的方式将student表中salary字段的值全部置为0;(2分)
create table students(
id number(3) primary key,
name varchar2(4) not null unique,
gender varchar2(2) not null check(gender in(‘男’,‘女’)),
salary number(6) not null check(salary between 6000 and 8000)
);

			1) rename student to stu;

			2) alter table student rename column salary to sal;

			3) alter table student drop column salary;
			    alter table student add salary number(5) default 0;

4.请使用Dom4j解析以下xml文件,将解析内容封装成对象,打印到控制台。(6分)

<?xml version="1.0" encoding="utf-8"?> java与模式 80 java编程思想 95 疯狂java讲义 90

public class Dom4jTest {
private static List listBook = new ArrayList<>();

public static void main(String[] args) {
	try {
		SAXReader reader = new SAXReader();
		Document document = reader.read(new File("src/com/briup/work/exercise4/book.xml"));
		Element root = document.getRootElement();
		List<Element> list = root.elements();
		for (Element e : list) {
			String value = e.attributeValue("bid");
			int id = Integer.parseInt(value);
			String name = e.element("name").getText();
			double price = Double.parseDouble(e.element("price").getText());
			Book book = new Book(id,name,price);
			listBook.add(book);
		}
		
		for(Book b:listBook){
			System.out.println(b);
		}
		
	} catch (DocumentException e) {
		e.printStackTrace();
	}
}

}

上一篇: 测试学习7

下一篇: 7.测试结果