Sql Certificate 简明教程

SQL Certificate Mock Exams

1. What will be the outcome of the following query?

SELECT ROUND(144.23,-1) FROM dual;

2.In which of the following cases, parenthesis should be specified?

3. Which of the following are DML commands in Oracle Database?

4. Write a query to display employee details (Name, Department, Salary and Job) from EMP table.

5.What among the following are different types of Views?

6.What is true about the SET operators?

7.Which of the following multi-row operators can be used with a sub-query?

8. When a table can be created?

9. Which among the following is a common technique for inserting rows into a table? (Choose the most sensible and appropriate answer)

10. What among the following is true about a View?

11. Predict the output when below statement is executed in SQL Plus?*

DESC emp

12. What will be the outcome of the query given below?

SELECT 100+NULL+999 FROM dual;

13. With respect to the given query, if the JOIN used is replaced with NATURAL JOIN, it throws an error. What is the reason for this error?

14.Which of the following syntax models is used in extensively in the software systems worldwide?

  • 15. 关于相关子查询,哪些说法是正确的?*

  • [style="arabic"]1. 如下发出 UPDATE 语句:*

UPDATE employees
SET employee_id   = NULL;
WHERE job_id  = 'CLERK';

上述语句的结果会是什么?(此处通过设置约束,将 EMPLOYEE_ID 列标记为必需)

17.What is true with respect to the query given above?

18. Consider the following query.

SELECT e.job_id , e.first_name, d.department_id
FROM departments D JOIN employees e JOIN BONUS b
USING (job_id );

此查询导致错误。出错的原因是什么?

19. Predict the output of the below query

SELECT 50 || 0001
FROM dual

20. You create a table and name it as COUNT. What will be the outcome of CREATE TABLE script?

  • [style="arabic"]1. 以下查询会返回什么结果?*

SELECT *
FROM employees
WHERE salary BETWEEN (SELECT max(salary)
			FROM employees
			WHERE department_id  = 100)
AND (SELECT min(salary) FROM employees where department_id  = 100);

此查询返回错误。造成此错误的原因是什么?

22. Which of the following is not a property of functions?

23.What is true with respect to INNER JOINS and OUTER JOINS in Oracle DB?

24. Which of the following can create a view even if the base table(s) does not exist?

25. Which of the following ANSI SQL: 1999 join syntax joins are supported by Oracle?

26. What among the following are the pre-requisites for creating a table?

27. What is the syntax for creating a table?

28.You need to display all the non-matching rows from the EMPLOYEES table and the non-matching rows from the DEPARTMENT table without giving a Cartesian product of rows between them. Which of the following queries will give the desired output?

29. Which of the below alphanumeric characters are used to signify concatenation operator in SQL?

30.What is the best way to change the precedence of SET operators given the fact that they have equal precedence?

31.What will be displayed in the result of this query?

32. Which of the following commands ensures that no DML operations can be performed on a view?

33. What is true about the NOFORCE option in CREATE VIEW statement?

34. What is true about the OR REPLACE keyword?

35. What among the following is a type of Oracle SQL functions?

36. What among the following is a type of single-row function?

37. What is the most appropriate about Multiple Row Functions?

38. Which of the following are also called Group functions?

39. A table T_COUNT has 12 number values as 1, 2, 3, 32, 1, 1, null, 24, 12, null, 32, null. Predict the output of the below query.

SELECT COUNT (*) FROM t_count;

40. Pick the element which you must specify while creating a table.

41. What can be said about the statement given above?

42. A table T_COUNT has 12 number values as 1, 2, 3, 32, 1, 1, null, 24, 12, null, 32, null. Predict the output of the below query.

SELECT COUNT (num) FROM t_count;

43. You need to find the results obtained by the above query only for the departments 100 and 101. Which of the following clauses should be added / modified to the above query?

44. Which of the following is NOT a GROUP BY extensions in SQL?

45. What will happen if the above statement is modified as below?

CREATE OR REPLACE VIEW dept_sum_vu(name, maxsal, minsal, avgsal)
AS
SELECT d.dept_name, MIN(e.salary), MAX(e.salary), AVG (e.salary)
FROM employees e JOIN departments d
ON (e.department_id= d.dept_id)
GROUP BY d.dept_name;

46. What among the following is true about the DELETE statement?

47. Assuming the last names of the employees are in a proper case in the table employees, what will be the outcome of the following query?

SELECT employee_id, last_name, department_id  FROM employees WHERE last_name = 'smith';

48.当我们对表执行 DELETE 语句时,以下哪项会出现?(选择最恰当的答案)

49.What is true about the query given above?

50.What will happen if a value is provided to the &N variable in the above query (option C in question 76) does not match with any row? (Choose the best answer)

51.What is the default sorting order of the results when UNION ALL operator is used?

52. A table T_COUNT has 12 number values as 1, 2, 3, 32, 1, 1, null, 24, 12, null, 32, null. Predict the output of the below query.

SELECT COUNT (ALL num) FROM t_count;

53.What is the maximum level up to which Sub-queries can be nested?

54. A table T_COUNT has 12 number values as 1, 2, 3, 32, 1, 1, null, 24, 12, null, 32, null. Predict the output of the below query.

SELECT COUNT (DISTINCT num) FROM t_count;

55. Here are few statements about VARIANCE function in SQL.

  1. 该函数接受多个数字输入,并返回所有数值的方差

ii. 该函数接受一个数值列,并返回包括 NULL 值在内的所有列数值的方差

iii. 该函数接受一个数值列,并返回排除 NULL 值在内的所有列数值的方差

Chose the correct combination from the below options.

56. Which clause is used to filter the query output based on aggregated results using a group by function?

57. A user named "Kevin" wants to access a table which is owned by another user named "Jonathan". Which of the following will work for Kevin?

58.What is true about the ALL operator used for sub-queries? (Choose the most appropriate answer.)

59. Suppose you select DISTINCT departments and employee salaries in the view query used in above question. What will be the outcome if you try to remove rows from the view dept_sum_vu?

60.What will happen if the SELECT list of the compound queries returns both a VARCHAR2 and a NUMBER data type result?

61. What is true about a schema?

62. In which order the values will get inserted with respect to the above INSERT statement?

63. What among the following is true about tables?

65. Which of the below SQL query will display employee names, department, and annual salary?

66. What is true about the SUBSTR function in Oracle DB?

  • [style="arabic"]1. 以下哪个 SELECT 语句列出了“家庭”类别中所有书籍的最高零售价?*

68. Which of the following functions can be used to include NULL values in calculations?

69.Which statements best describes the inference drawn from the questions 34 and 35?

70. What will be the outcome of the following query?

SELECT length('hi') FROM dual;

Answer:

Answer(1): A. ROUND 函数将根据指定精度 -1 四舍五入 144.23 的值并返回 140。

Examine the structure of the EMPLOYEES table as given and answer the questions 2 and 3 that follow.

SQL> DESC employees
 Name			 Null?	  Type
 ----------------------- -------- ----------------
 EMPLOYEE_ID		 NOT NULL NUMBER(6)
 FIRST_NAME			  VARCHAR2(20)
 LAST_NAME		 NOT NULL VARCHAR2(25)
 EMAIL			 NOT NULL VARCHAR2(25)
 PHONE_NUMBER			  VARCHAR2(20)
 HIRE_DATE		 NOT NULL DATE
 JOB_ID 		 NOT NULL VARCHAR2(10)
 SALARY 			  NUMBER(8,2)
 COMMISSION_PCT 		  NUMBER(2,2)
 MANAGER_ID			  NUMBER(6)
 DEPARTMENT_ID			  NUMBER(4)

*答案 (2): A. *使用括号将在 INTERSECT 与其他运算符一起使用时明确更改计算顺序。

*答案 (3): A、D. *严格来说,SELECT 是一个 DML 命令,因为它是在表中操作数据的强制性子句之一。

*答案 (4): A. *从表中选择需要的,每个表逗号分隔。

*答案 (5): C. *简单视图和复杂视图是两种视图。简单视图基于仅引用一个表且不包括分组函数、表达式或 GROUP BY 子句的子查询。复杂视图基于从一个或更多表中检索或派生数据的子查询,并且可以包含函数或分组数据。

*答案 (6): C. *使用 SET 运算符时,所有组合都应具有相同数量的列。组成复合查询的查询中的对应列必须属于相同的数据类型组。

*答案 (7): D. *多行子查询返回多行结果。可与多行子查询搭配使用的运算符包括 IN、ALL、ANY 和 EXISTS。

*答案 (8): C. *可以创建索引以加快查询过程。存在索引时,DML 操作总是更慢。Oracle 11g 会自动为 PRIMARY Key 和 UNIQUE 约束创建索引。使用 CREATE INDEX 命令创建显式索引。如果查询条件或排序操作基于创建索引所用的列或表达式,Oracle 11g 可以自动使用索引。

*答案 (9): A. *使用 SELECT 子句是将行插入表的常用技术。可减少为每列手动键入值的工作。

*答案 (10): A. *视图定义可以使用子查询。

*答案 (11): C. *DESCRIBE 用于显示表结构以及表列、其数据类型和空值。

*答案 (12): C. *任何带 NULL 的算术运算都将产生一个 NULL。

*答案 (13): C、D. *

*答案 (14): C. *ANSI SQL: 1999 语法虽然不像传统 Oracle 语法用得多,但它仍然是 Oracle SQL 中可能使用的语法之一。

*答案 (15): B. *相关子查询引用外部查询中的列,并针对外部查询中的每一行执行子查询,而无相关子查询先执行子查询,并将值传递到外部查询。

*答案 (16): D. *在更新列值时,必须遵守列上的约束。在给定的 UPDATE 语句中,将引发错误,因为 EMPLOYEE_ID 列是 EMPLOYEES 表中的主键,这意味着它不能为 NULL。

*答案 (17): D. *WHERE 子句可以省略,相关条件可以容纳在 JOIN.ON 子句中,如给定查询所示。

*答案 (18): A. *在没有每个 JOIN 之间的 ON 子句的情况下,不允许 Table1 JOIN table2 JOIN table3。

*答案 (19): C. *Oracle 忽略表达式右侧操作数中的前导零。

*答案 (20): A、C. *你不能创建一个与 Oracle Server 保留字同名的表。

*解答 (21):C。*BETWEEN 运算符可以在子查询中使用,但不能与子查询一起使用。

Answer(22): D. 函数可以执行计算、进行大小写转换和类型转换。

*解答 (23):A、C。*联接可以是内部联接,其中仅返回在所有表中都有匹配记录的记录,也可以是外部联接,其中无论联接中是否存在匹配记录都可以返回记录。当需要在结果中包含记录,而联接表中没有相应记录时,会创建外部联接。这些记录与 NULL 记录进行匹配,以便将它们包含在输出中。

*解答 (24):B。*如果您在 CREATE 子句中包含 FORCE 关键字,Oracle 11g 会创建视图,而不考虑缺少任何引用表的情况。NOFORCE 是 CREATE VIEW 命令的默认模式,这意味着所有表和列必须有效,否则视图将不会创建。

解答 (25):D。

*解答 (26):A、B。*用户必须拥有 CREATE TABLE 权限,并且必须有足够的空间将初始范围分配给表段。

解答 (27):A。

*解答 (28):C。*FULL OUTER JOIN 返回来自两个表的未匹配行。完整外部联接包含来自两个表的所有记录,即使在另一张表中找不到相应记录也是如此。

*解答 (29):B。*在 SQL 中,连接运算符由两个竖线 (||) 表示。

*解答 (30):C。*括号可用于对特定查询进行分组以显式更改优先级。在执行期间,括号优先于其他 SET 运算符。

*解答 (31):A。*UNION 返回两个查询的组合行,对其进行排序并删除重复项。

*解答 (32):C。*WITH READ ONLY 选项防止对视图执行任何 DML 操作。当确保用户只能查询数据,而不进行任何更改时,通常会使用此选项。

*解答 (33):B、C。*NOFORCE 是 CREATE VIEW 命令的默认模式,这意味着所有表和列必须有效,否则视图将不会创建。

*解答 (34):B。*OR REPLACE 选项通知 Oracle 11g 可能已经存在同名视图;如果存在,则视图的先前版本应替换为新命令中定义的版本。

*解答 (35):A。*基本上有两种类型的函数 - 单行和多行函数。

*解答 (36):B。*字符、日期、转换、常规、数字是单行函数的类型。

*解答 (37):B。*多行函数始终针对一组行工作,并为每组行返回一个值。

*解答 (38):C。*组函数与多行函数和聚合函数相同。

Answer(39): A. *The COUNT( ) 统计行数,包括重复项和 NULL。使用 DISTINCT 和 ALL 关键字来限制重复项和 NULL 值。

*答案(40):D。*表至少必须具有一个列、其数据类型规范和精度(如果需要)。

*答案(41):C。*指定别名是提高代码和视图查询可读性的好习惯。

*答案(42):C。*COUNT(column)会忽略 NULL 值,但会计算重复项。

*答案(43):C。*NATURAL JOIN 子句会隐式匹配所有同名列。要添加其他条件,可以使用 WHERE 子句。

*答案(44):A。*GROUPING SETS 操作可用于通过一次查询执行多个 GROUP BY 聚合。

*答案(45):B。*列别名的顺序并不重要,因为它们不携带任何行为属性。

*答案(46):B。*WHERE 子句谓词在 DELETE 语句中是可选的。如果省略 WHERE 子句,表中的所有行都将被删除。

*答案(47):B。*假设 employees 表中的姓氏是正确的大写形式,则条件 WHERE last_name = 'smith' 将不会得到满足,因此不会显示任何结果。

*答案(48):C。*作为活动事务或新事务的一部分,表中的行将被删除。

*答案(49):D。*复合查询是由使用不同表的多个查询组成的查询。

答案(50):D。

*答案(51):B。*默认情况下,复合查询会按从左到右升序的方式对所有列中的行进行排序。唯一例外是 UNION ALL,其中不会对行进行排序。只有在复合查询的末尾才允许使用 ORDER BY 子句。

*答案(52):C。*COUNT(ALL column) 会忽略 NULL 值,但会计算重复项。

答案(53):A。

*答案(54):B。*COUNT (DISTINCT column) 计算非空值的个数。

*答案(55):C。*VARIANCE 函数接受单一数字参数,作为列名,并考虑 NULL 值返回所有列值的方差。

*答案(56):D。*HAVING 子句用于限制组结果。使用 HAVING 子句可指定要显示的组,从而根据聚合信息进一步限制组。HAVING 子句可以位于 GROUP BY 子句之前,但建议先放置 GROUP BY 子句,因为这样更符合逻辑。在将 HAVING 子句应用于 SELECT 列表中的组之前,先形成组并计算组函数。

答案(57):B。

答案(58):C。' > ALL' 大于子查询返回的最大值。'< ALL' 小于子查询返回的最小值。'< ANY' 小于子查询返回的最大值。'> ANY' 大于子查询返回的最小值。'= ANY' 等于子查询返回的任何值(与 IN 相同)。'[NOT] EXISTS' 行必须与子查询中的值匹配。

*答案 (59):C. *视图 DEPT_SUM_VU 仍然是一个复杂视图,因为它使用了 DISTINCT 关键字。因此,它不支持 DML 操作。

*答案 (60):C. *Oracle 不隐式地转换数据类型。

*答案 (61):D. *数据库中的用户空间称为模式。模式包含由该用户拥有或访问的对象。每个用户可以拥有自己的单个模式。

*答案 (62):B. *如果在 INSERT 子句中提到了这些列,那么 VALUES 关键字应按相同顺序包含这些值

*答案 (63):B. *使用 DEFAULT 关键字在定义列时,可以指定其默认值。

*答案 (65):C. *在 SELECT 语句中使用数字表达式执行基本算术计算。

Answer(66): A. SUBSTR(string, x, y) 函数接受三个参数,并返回一个字符串,该字符串由从源字符串提取的指定数量的字符组成,从指定开始位置 (x) 开始。当位置为正时,该函数从 string 的开头开始计数以找到第一个字符。当位置为负时,该函数从 string 的末尾向前计数。

*答案 (67):A. *由于 category FAMILY 必须在分组之前进行限制,因此必须使用 WHERE 子句(而不是 HAVING 子句)对表行进行筛选。

*答案 (68):B. *NVL 是一个通用函数,用于向 NULL 值提供备用值。它确实可以在使用 AVG、STDDEV 和 VARIANCE 组函数进行算术计算时有所不同。

*答案 (69):C. *由于作业代码和部门的组合是唯一的,因此不会获得重复项。

*答案 (70):A. *LENGTH 函数仅给出字符串的长度。