0

databases Online Quiz - 32

Description: databases Online Quiz - 32
Number of Questions: 20
Created by:
Tags: databases
Attempted 0/20 Correct 0 Score 0
  1. COMMIT

  2. MERGE

  3. UPDATE

  4. DELETE

  5. CREATE

  6. DROP


Correct Option: B,C,D
  1. Must begin with either a number or a letter

  2. Must be 1-30 characters long

  3. Should not be an Oracle Server reserved word

  4. Must contain only A-Z, a-z, 0-9, _, *, and #

  5. Must contain only A-Z, a-z, 0-9, _, $, and #

  6. Must begin with a letter


Correct Option: B,C,E,F

Which SQL statement generates the alias Annual Salary for the calculated column SALARY*12?

  1. SELECT ename, salary*12 'Annual Salary' FROM employees;

  2. SELECT ename, salary*12 "Annual Salary" FROM employees;

  3. SELECT ename, salary*12 AS Annual Salary FROM employees;

  4. SELECT ename, salary*12 AS INITCAP("ANNUAL SALARY") FROM employees


Correct Option: B

You need to display the last names of those employees who have the letter "A" as the second character in their names. Which SQL statement displays the required results?

  1. SELECT last_name FROM EMP WHERE last_name LIKE '_A%';

  2. SELECT last_name FROM EMP WHERE last name ='*A%'

  3. SELECT last_name FROM EMP WHERE last name ='_A%';

  4. SELECT last_name FROM EMP WHERE last name LIKE '*A%'


Correct Option: A
Explanation:

To solve this question, the user needs to know about the SQL SELECT statement and the LIKE operator. The LIKE operator is used to match a character pattern in a string. The underscore (_) represents a single character, while the percent sign (%) represents any number of characters.

Now, let's go through each option and explain why it is right or wrong:

A. SELECT last_name FROM EMP WHERE last_name LIKE '_A%'; This option is correct. It selects the last names of employees from the EMP table where the last name has any character as the first character and "A" as the second character, followed by any number of characters.

B. SELECT last_name FROM EMP WHERE last name ='A%' This option is incorrect because the equal sign (=) is used for exact matches, and the asterisk () is not a valid wildcard character in SQL.

C. SELECT last_name FROM EMP WHERE last name ='A%'; This option is incorrect because the equal sign (=) is used for exact matches, and the underscore () represents only a single character, not any number of characters.

D. SELECT last_name FROM EMP WHERE last name LIKE 'A%' This option is incorrect because the percent sign (%) is used to match any number of characters, not the asterisk ().

Therefore, the correct answer is:

The Answer is: A. SELECT last_name FROM EMP WHERE last_name LIKE '_A%';

Which two are character manipulation functions? (Choose two.)

  1. TRIM

  2. REPLACE

  3. TRUNC

  4. TO_DATE

  5. MOD

  6. CASE


Correct Option: A,B

Which clause should you use to exclude group results?

  1. WHERE

  2. HAVING

  3. RESTRICT

  4. GROUP BY

  5. ORDER BY


Correct Option: B

AI Explanation

To answer this question, you need to understand the purpose of each clause in a SQL query.

The WHERE clause is used to filter rows based on a condition. It is used to exclude individual rows from the result set based on a specific condition.

The HAVING clause, on the other hand, is used to filter groups based on a condition. It is typically used with the GROUP BY clause and is used to exclude groups from the result set based on a specific condition.

The RESTRICT clause does not exist in standard SQL syntax, so it is not the correct answer.

The GROUP BY clause is used to group rows based on one or more columns. It is used to create groups in the result set based on the specified columns.

The ORDER BY clause is used to sort the result set based on one or more columns. It is not used to exclude any rows or groups from the result set.

Therefore, the correct answer is B) HAVING. The HAVING clause is used to exclude groups from the result set based on a specific condition.

Which is an /SQL*Plus command?

  1. INSERT

  2. UPDATE

  3. SELECT

  4. DESCRIBE

  5. DELETE

  6. RENAME


Correct Option: D
  1. create groups of data

  2. sort data in a specific order

  3. convert data to a different format

  4. Retrieve data based on an unknown condition


Correct Option: D
Explanation:

To solve this question, the user needs to know the definition and purpose of a subquery.

A subquery is a query that is nested inside another query and returns data that will be used by the main query. It can be used to retrieve data based on an unknown condition and to filter data from a table.

Now, let's go through each option and explain why it is right or wrong:

A. create groups of data: This option is incorrect because creating groups of data is typically done using the GROUP BY clause, not a subquery.

B. sort data in a specific order: This option is incorrect because sorting data is typically done using the ORDER BY clause, not a subquery.

C. convert data to a different format: This option is incorrect because data conversion is typically done using functions like CAST or CONVERT, not a subquery.

D. Retrieve data based on an unknown condition: This option is correct. A subquery can be used to retrieve data based on an unknown condition, such as selecting all employees with salaries greater than the average salary.

Therefore, the answer is: D.

What does the TRUNCATE statement do?

  1. Removes the table

  2. Removes all rows from a table

  3. shortens the table to 10 rows

  4. Removes all columns from a table

  5. Removes foreign keys from a table


Correct Option: B

Which substitution variable would you use if you want to reuse the variable value without prompting the user each time?

  1. "&"

  2. ACCEPT

  3. PROMPT

  4. "&&"


Correct Option: D

Which two statements about views are true? (Choose two)

  1. A view can be created as read only

  2. A view can be created as a join on two or more tables.

  3. A view cannot have an ORDER BY clause in the SELECT statement

  4. A view cannot be created with a GROUP BY clause in the SELECT statement

  5. A view must have aliases defined for the column names in the SELECT statement


Correct Option: A,B
Explanation:

Explanation: To answer this question, we need to understand the concept of views in the context of databases.

A. A view can be created as read-only - This statement is true. A view can be created with the SELECT statement that restricts the columns and rows that are returned. This can be used to ensure a user only has read access to certain data.

B. A view can be created as a join on two or more tables - This statement is true. A view can be created as a SELECT statement that combines data from two or more tables. This can be used to simplify queries by combining data that is frequently used together.

C. A view cannot have an ORDER BY clause in the SELECT statement - This statement is false. A view can have an ORDER BY clause in the SELECT statement to sort the data returned by the view.

D. A view cannot be created with a GROUP BY clause in the SELECT statement - This statement is false. A view can be created with a GROUP BY clause in the SELECT statement to group the data returned by the view.

E. A view must have aliases defined for the column names in the SELECT statement - This statement is false. A view does not require aliases for the column names in the SELECT statement, although it can be useful to provide more meaningful names for the columns.

Therefore, options A and B are both true statements, making the correct answer B.

  1. SELECT last_name, 12*salary*commission_pct FROM emp;

  2. SELECT last_name, 12*salary* (commission_pct,0) FROM emp;

  3. SELECT last_name, 12*salary*(nvl(commission_pct,0)) FROM emp

  4. SELECT last_name, 12*salary*(decode(commission_pct,0)) FROM emp;


Correct Option: C

Evaluate the SQL statement: SELECT ROUND (TRUNC (MOD (1600, 10),-1), 2) FROM dual; What will be displayed?

  1. 0

  2. 1

  3. 0.00

  4. An error statement


Correct Option: A

AI Explanation

To evaluate the given SQL statement: SELECT ROUND (TRUNC (MOD (1600, 10),-1), 2) FROM dual;

Let's break it down step by step:

  1. MOD (1600, 10): This returns the remainder when 1600 is divided by 10. The result is 0.

  2. TRUNC (0, -1): This truncates the number 0 to the nearest 10th place. Since the decimal place is -1, it rounds down to the nearest 10th. The result is still 0.

  3. ROUND (0, 2): This rounds the number 0 to 2 decimal places. Since the number has no decimal places, it remains 0.

Therefore, the SQL statement will display 0 as the result.

The correct answer is A) 0.

  1. The statement executes successfully and returns the student ID and sum of all marks for each student who obtained more than the average mark in each subject.

  2. The statement returns an error at the SELECT clause.

  3. The statement returns an error at the WHERE clause.

  4. The statement returns an error at the ORDER BY clause.


Correct Option: C
  1. SELECT TO_CHAR(2000, '$#,###.##') FROM dual;

  2. SELECT TO_CHAR(2000, '$0,000.00') FROM dual;

  3. SELECT TO_CHAR(2000, '$9,999.00') FROM dual;

  4. SELECT TO_CHAR(2000, '$9,999.99') FROM dual;

  5. SELECT TO_CHAR(2000, '$2,000.00') FROM dual;

  6. SELECT TO_CHAR(2000, '$N,NNN.NN') FROM dual;


Correct Option: B,C,D
  1. The underlying tables must have data.

  2. You need SELECT privileges on the view.

  3. The underlying tables must be in the same schema.

  4. You need SELECT privileges only on the underlying tables.


Correct Option: B
  1. SELECT ENAME FROM EMP WHERE SYSDATE-HIRE_DATE > 5;

  2. SELECT ENAME FROM EMP WHERE HIRE_DATE-SYSDATE > 5;

  3. SELECT ENAME FROM EMP WHERE (SYSDATE-HIRE_DATE)/365 > 5;

  4. SELECT ENAME FROM EMP WHERE (SYSDATE-HIRE_DATE)* 365 > 5;


Correct Option: C

Evaluate these two SQL statements: SELECT last_name, salary , hire_date FROM EMPLOYEES ORDER BY salary DESC; SELECT last_name, salary, hire_date FROM EMPLOYEES ORDER BY 2 DESC; What is true about them?

  1. The two statements produce identical results.

  2. The second statement returns a syntax error.

  3. There is no need to specify DESC because the results are sorted in descending order by default.

  4. The two statements can be made to produce identical results by adding a column alias for the salary column in the second SQL statement.


Correct Option: A
Explanation:

To understand these SQL statements, the user needs to know how to query a database and sort the results in descending order based on a specific column.

The first SQL statement selects the last name, salary, and hire date columns from the EMPLOYEES table and orders the results by salary in descending order using the ORDER BY clause with the DESC keyword.

The second SQL statement is identical to the first one but uses the shorthand ORDER BY 2 DESC instead of explicitly specifying the salary column name.

Now let's go through each option and explain why it is right or wrong:

A. The two statements produce identical results: This option is correct. Both SQL statements select the same columns and sort the results in the same descending order based on the salary column. The shorthand ORDER BY 2 DESC in the second statement refers to the second column in the SELECT clause, which is the salary column.

B. The second statement returns a syntax error: This option is incorrect. The second SQL statement is a valid syntax and produces the same results as the first one.

C. There is no need to specify DESC because the results are sorted in descending order by default: This option is incorrect. SQL sorts the results in ascending order by default, so the DESC keyword is needed to sort the results in descending order.

D. The two statements can be made to produce identical results by adding a column alias for the salary column in the second SQL statement: This option is incorrect. Adding a column alias does not change the way the ORDER BY clause works. It only renames the column in the result set.

The Answer is: A

- Hide questions