Khóa học miễn phí SQL – The SQL SELECT Statement nhận dự án làm có lương

SQL – The SQL SELECT Statement Questions



1. Identify the capabilities of SELECT statement.

  1. Projection
  2. Selection
  3. Data Control
  4. Transaction

Answer: A, B. The SELECT statement can be used for selection, projection and joining.

2. Determine the capability of the SELECT statement demonstrated in the given query.

SELECT e.ename, d.dname
FROM   emp e, dept d
WHERE  e.deptno = d.deptno
AND    e.sal > 1000;
  1. Selection
  2. Filtering
  3. Joining
  4. Projection

Answer: A, C, D. Projection is including only the required columns in query, while Selection is selecting only the required data. Joining means combining two tables together through a connecting column.

3. Which of the following clause is used to suppress duplicates in a SELECT statement?

  1. INTERSECT
  2. DUPLICATE
  3. DISTINCT
  4. UNIQUE

Answer: C, D. Duplicate data can be restricted with the use of DISTINCT or UNIQUE in the SELECT statement.

4. Chose the statements which correctly specify a rule to write a SQL statement

  1. SQL statements are case sensitive
  2. Keywords can be abbreviated to build a standard
  3. SQL statements are case in-sensitive
  4. clauses must be placed together

Answer: C.SQL statements are not case sensitive.

5. Determine the output of the below query –

SELECT ''5+7'' 
FROM dual;
  1. 12
  2. 5+7
  3. 5
  4. 7

Answer: B.Oracle treats the values within double quotes as string expressions.

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

  1. SELECT ename, deptno, sal, job FROM emp;
  2. SELECT * FROM emp;
  3. SELECT DISTINCT ename, deptno, sal, job FROM emp;
  4. SELECT ename, deptno, sal FROM emp;

Answer A.Select the required from the tables each separated by a comma.

7. Which of the below queries displays employees” name and new salary after the increment of 1000?

  1. SELECT ename, sal FROM emp;
  2. SELECT ename, sal=sal+1000 FROM emp;
  3. SELECT ename, sal+1000 FROM emp;
  4. SELECT ename, 1000 FROM emp;

Answer: C. Basic arithmetic calculations can be done using the columns in SELECT statements.

8. Determine the output of the below query

SELECT 36/2-5*10 FROM dual;
  1. 130
  2. -32
  3. -120
  4. 175

Answer: B. Multiplication and Division occur before addition and subtraction.

9. Determine the output of the below query

SELECT (100-25)/15*(20-3) FROM dual;
  1. 0.294
  2. -85
  3. 63.67
  4. 85

Answer: D. Expression within the brackets are executed before the divisions and multiplications in the expression.

10. Chose the statements which correctly define a NULL value.

  1. NULL is a special value with zero bytes
  2. NULL is no value or unknown value
  3. NULL is represented by a blank space
  4. NULL is not same as zero

Answer: B, D.NULL is NO VALUE but neither same as zero nor as blank or space character.

11. Determine the output of the below query

SELECT sal + NULL 
FROM emp
WHERE empno = 7369;
  1. sal + NULL
  2. NULL
  3. 0
  4. 1250

Answer: B. Any arithmetic operation with NULL results in NULL.

12. Which of the below statements define column alias correctly?

  1. A column alias renames a column heading
  2. A column alias is an alternate column in a table
  3. A column alias can be specified during table definition
  4. A column alias immediately follows the column or expression in the SELECT statement

Answer: A, D. Column Alias can be used to name an expression in the SELECT statement.

13. Specify the column alias NEWSAL for the expression containing salary in the below SQL query

SELECT ename, job, sal + 100 FROM emp;
  1. (sal + 100) AS NEWSAL
  2. (sal + 100) NEWSAL
  3. (sal + 100) IS NEWSAL
  4. sal + 100 IS NEWSAL

Answer: A, B.Use ”AS” to signify new alias to a column expression.

14. Specify the column alias “New Salary” for the expression containing salary in the below SQL query

SELECT ename, job, sal + 100 FROM emp;
  1. (sal + 100) AS New Salary
  2. (sal + 100) “New Salary”
  3. (sal + 100) IS New Salary
  4. sal + 100 as “New Salary”

Answer: B, D. Column alias with space and special characters must be enquoted within double quotes.

15. Which command is used to display the structure of a table?

  1. LIST
  2. SHOW
  3. DESCRIBE
  4. STRUCTURE

Answer: C.DESCRIBE is used to show the table structure.

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

DESC emp
  1. Raises error “SP2-0042: unknown command “desc emp” – rest of line ignored.”
  2. Lists the columns of EMP table
  3. Lists the EMP table columns, their data type and nullity
  4. Lists the columns of EMP table along with their data types

Answer: C. DESCRIBE is used to show the table structure along with table columns, their data type and nullity

17. Which of the below statements are true about the DESCRIBE command?

  1. It can be used in SQL*Plus only
  2. It can be used in both SQL*Plus as well as SQL Developer
  3. It doesn”t works for object tables
  4. It doesn”t works for SYS owned tables

Answer: B.

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

  1. +
  2. ||
  3. ::

Answer: B.In SQL, concatenation operator is represented by two vertical bars (||).

19. Which of the below statements are correct about the usage of concatenation operator in SQL?

  1. It creates a virtual column in the table
  2. It generates a character expression as the result of concatenation of one or more strings
  3. It creates a link between two character columns
  4. It can be used to concatenate date expressions with other columns

Answer: B, D. Concatenation operator joins two values as an expression.

20. Predict the output of the below query

SELECT ename || NULL
FROM emp
WHERE empno = 7369
  1. SMITH
  2. SMITH NULL
  3. SMITHNULL
  4. ORA-00904: “NULL”: invalid identifier

Answer: A. Concatenation with NULL results into same value.

21. Predict the output of the below query

SELECT 50 || 0001
FROM dual
  1. 500001
  2. 51
  3. 501
  4. 5001

Answer: C. The leading zeroes in the right operand of expression are ignored by Oracle.

22. You execute the below query

SELECT e.ename||'' departments''s name is:''|| d.dname
FROM emp e, dept d
where e.deptno=d.deptno;

And get the exception – ORA-01756: quoted string not properly terminated. Which of the following solutions can permanently resolve the problem?

  1. Use double quote marks for the literal character string
  2. Use [q] operator to enquote the literal character string and selecting the delimiter of choice
  3. Remove the single quote mark (apostrophe) from the literal character string
  4. Use another delimiter to bypass the single quote apostrophe in the literal string

Answer: B. The [q] operator is used to enquote character literals with a quote.

23. Which of the below SELECT statement shows the correct usage of [q] operator?

  1. SELECT e.ename || q''[department''s name is]''|| d.dname
       FROM emp e, dept d
       WHERE e.deptno = d.deptno;
  2. SELECT e.ename || q[''department''s name is'']|| d.dname
       FROM emp e, dept d
       WHERE e.deptno = d.deptno;
  3. SELECT e.ename || q[department''s name is]|| d.dname
       FROM emp e, dept d
       WHERE e.deptno = d.deptno;
  4. SELECT e.ename || q''(department''s name is)''|| d.dname
       FROM emp e, dept d
       WHERE e.deptno = d.deptno;

Answer: A

24. Which of the below SELECT statement is used to select all columns of EMP table?

  1. SELECT ALL FROM emp
  2. SELECT # FROM emp
  3. SELECT * FROM emp
  4. SELECT empno,ename,deptno,sal,job,mgr,hiredate FROM emp

Answer: C. The character ”*” is used to select all the columns of the table.

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

  1. SELECT ename, deptno, sal FROM emp;
  2. SELECT ename, deptno, sal + comm FROM emp;
  3. SELECT ename, deptno, (sal * 12) Annual_Sal FROM emp;
  4. Annual salary cannot be queried since the column doesn”t exists in the table

Answer: C. Use numeric expressions in SELECT statement to perform basic arithmetic calculations.

Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc