Oracle Database 12c: SQL Fundamentals

QUESTION NO: 1

Evaluate the following SQL statement:

Which statement is true regarding the outcome of the above query?

A. It executes successfully and displays rows in the descending order of PROMO_CATEGORY.

B. It produces an error because positional notation cannot be used in the order by clause with set operators.

C. It executes successfully but ignores the order by clause because it is not located at the end of the compound statement.

D. It produces an error because the order by clause should appear only at the end of a compound query-that is, with the last select statement.

Answer: D

QUESTION NO: 2

View the Exhibit and examine the structure of the product, component, and PDT_COMP tables.

In product table, PDTNO is the primary key.

In component table, COMPNO is the primary key.

In PDT_COMP table, <PDTNO, COMPNO) is the primary key, PDTNO is the foreign key referencing PDTNO in product table and COMPNO is the foreign key referencing the COMPNO in component table.

You want to generate a report listing the product names and their corresponding component names, if the component names and product names exist.

Evaluate the following query:

SQL>SELECT pdtno, pdtname, compno, compname

FROM product _____________ pdt_comp

USING (pdtno) ____________ component USING (compno)

WHERE compname IS NOT NULL;

Which combination of joins used in the blanks in the above query gives the correct output?

A. JOIN; JOIN

B. FULL OUTER JOIN; FULL OUTER JOIN

C. RIGHT OUTER JOIN; LEFT OUTER JOIN

D. LEFT OUTER JOIN; RIGHT OUTER JOIN

Answer: C

QUESTION NO: 3

View the Exhibit for the structure of the student and faculty tables.

You need to display the faculty name followed by the number of students handled by the faculty at the base location.

Examine the following two SQL statements:

Which statement is true regarding the outcome?

A. Only statement 1 executes successfully and gives the required result.

B. Only statement 2 executes successfully and gives the required result.

C. Both statements 1 and 2 execute successfully and give different results.

D. Both statements 1 and 2 execute successfully and give the same required result.

Answer: D

QUESTION NO: 4

View the Exhibits and examine products and sales tables.

You issue the following query to display product name and the number of times the product has been sold:

What happens when the above statement is executed?

A. The statement executes successfully and produces the required output.

B. The statement produces an error because item_cnt cannot be displayed in the outer query.

C. The statement produces an error because a subquery in the from clause and outer-joins cannot be used together.

D. The statement produces an error because the group by clause cannot be used in a subquery in the from clause.

Answer: A

QUESTION NO: 5

You want to create a table employees in which the values of columns EMPLOYEES_ID and LOGIN_ID must be unique and not null. Which two SQL statements would create the required table?

A. Option A

B. Option B

C. Option C

D. Option D

E. Option E

F. Option F

Answer: DE

QUESTION NO: 6

View the Exhibit and examine the structure of the products table.

Using the products table, you issue the following query to generate the names, current list price, and discounted list price for all those products whose list price falls below $10 after a discount of 25% is applied on it.

The query generates an error. What is the reason for the error?

A. The parenthesis should be added to enclose the entire expression.

B. The double quotation marks should be removed from the column alias.

C. The column alias should be replaced with the expression in the where clause.

D. The column alias should be put in uppercase and enclosed within double quotation marks in the where clause.

Answer: C

QUESTION NO: 7

Examine the structure proposed for the transactions table:

Which two statements are true regarding the creation and storage of data in the above table structure?

A. The CUST_STATUS column would give an error.

B. The TRANS_VALIDITY column would give an error.

C. The CUST_STATUS column would store exactly one character.

D. The CUST_CREDIT_LIMIT column would not be able to store decimal values.

E. The TRANS_VALIDITY column would have a maximum size of one character.

F. The TRANS_DATE column would be able to store day, month, century, year, hour, minutes, seconds, and fractions of seconds

Answer: B, C

Explanation:

VARCHAR2(size)Variable-length character data (A maximum size must be specified: minimum size is 1; maximum size is 4, 000.)

CHAR [(size)] Fixed-length character data of length size bytes (Default and minimum size is 1; maximum size is 2, 000.)

NUMBER [(p, s)] Number having precision p and scale s (Precision is the total number of decimal digits and scale is the number of digits to the right of the decimal point; precision can range from 1 to 38, and scale can range from –84 to 127.)

DATE Date and time values to the nearest second between January 1, 4712 B.C., and December 31, 9999 A.D.

QUESTION NO: 8

You need to create a table for a banking application. One of the columns in the table has the following requirements:

1) You want a column in the table to store the duration of the credit period.

2) The data in the column should be stored in a format such that it can be easily added and subtracted with date data type without using conversion functions.

3) The maximum period of the credit provision in the application is 30 days.

4) The interest has to be calculated for the number of days an individual has taken a credit for.

Which data type would you use for such a column in the table?

A. DATE

B. NUMBER

C. TIMESTAMP

D. INTERVAL DAY TO SECOND

E. INTERVAL YEAR TO MONTH

Answer: D

QUESTION NO: 9

Which three tasks can be performed using SQL functions built into Oracle Database?

A. Displaying a date in a nondefault format

B. Finding the number of characters in an expression

C. Substituting a character string in a text expression with a specified string

D. Combining more than two columns or expressions into a single column in the output

Answer: A, B, C

QUESTION NO: 10

View the Exhibit and examine the description of SALES and PROMOTIONS tables.

You want to delete rows from the sales table, where the PROMO_NAME column in the promotions table has either blowout sale of everyday low prices as values.

Which three delete statements are valid?

A. Option A

B. Option B

C. Option C

D. Option D

Answer: B, C, D

QUESTION NO: 11

Which three SQL statements would display the value 1890.55 as $1, 890.55?

A. Option A

B. Option B

C. Option C

D. Option D

E. Option E

Answer: A, D, E

QUESTION NO: 12

You want to display 5 percent of the employees with the highest salaries in the EMPLOYEES table.

Which query will generate the required result?

A. Option A

B. Option B

C. Option C

D. Option D

Answer: D

QUESTION NO: 13

In the customers table, the CUST_CITY column contains the value 'Paris' for the CUST_FIRST_NAME 'Abigail'.

Evaluate the following query:

What would be the outcome?

A. Abigail PA

B. Abigail Pa

C. Abigail IS

D. An error message

Answer: B

QUESTION NO: 14

View the Exhibit and evaluate the structure and data in the CUST_STATUS table.

You issue the following SQL statement:

Which statement is true regarding the execution of the above query?

A. It produces an error because the AMT_SPENT column contains a null value.

B. It displays a bonus of 1000 for all customers whose AMT_SPENT is less than CREDIT_LIMIT.

C. It displays a bonus of 1000 for all customers whose AMT_SPENT equals CREDIT_LIMIT, or AMT_SPENT is null.

D. It produces an error because the TO_NUMBER function must be used to convert the result of the NULLIF function before it can be used by the NVL2 function.

Answer: C

Explanation:

The NULLIF Function

The NULLIF function tests two terms for equality. If they are equal the function returns a null, else it returns the first of the two terms tested.

The NULLIF function takes two mandatory parameters of any data type. The syntax is NULLIF(ifunequal, comparison_term), where the parameters ifunequal and

comparison_term are compared. If they are identical, then NULL is returned. If they differ, the ifunequal parameter is returned.

QUESTION NO: 15

Which normal form is a table in if it has no multi-valued attributes and no partial dependencies?

A. First normal form

B. Second normal form

C. Third normal form

D. Fourth normal form

Answer: B

QUESTION NO: 16

Examine the types and examples of relationships that follow:

1. One-to-one a) Teacher to students

2. One-to-many b) Employees to Manager

3. Many-to-one c) Person to SSN

4. Many-to-many d) Customers to products

Which option indicates the correctly matched relationships?

A. 1-a, 2-b, 3-c, and 4-d

B. 1-c, 2-d, 3-a, and 4-b

C. 1-c, 2-a, 3-b, and 4-d

D. 1-d, 2-b, 3-a, and 4-c

Answer: C

QUESTION NO: 17

You execute the following commands:

For which substitution variables are you prompted for the input?

A. None, because no input required

B. Both the substitution variables 'hiredate' and 'mgr_id\

C. Only 'hiredate'

D. Only 'mgr_id'

Answer: B

QUESTION NO: 18

View the Exhibit and examine the structure of the customers table.

Using the customers table, you need to generate a report that shows the average credit limit for customers in Washington and NEW YORK.

Which SQL statement would produce the required result?

A. Option A

B. Option B

C. Option C

D. Option D

Answer: C

QUESTION NO: 19

View the Exhibit and examine the data in the employees table:

You want to display all the employee names and their corresponding manager names.

Evaluate the following query:

Which join option can be used in the blank in the above query to get the required output?

A. INNER JOIN

B. FULL OUTER JOIN

C. LEFT OUTER JOIN

D. RIGHT OUTER JOIN

Answer: C

QUESTION NO: 20

Evaluate the following query:

What would be the outcome of the above query?

A. It produces an error because flower braces have been used.

B. It produces an error because the data types are not matching.

C. It executes successfully and introduces an 's at the end of each PROMO_NAME in the output.

D. It executes successfully and displays the literal "{'s start date was \} * for each row in the output.

Answer: C

Explanation:

So, how are words that contain single quotation marks dealt with? There are essentially two mechanisms available. The most popular of these is to add an additional single quotation mark next to each naturally occurring single quotation mark in the character string

Oracle offers a neat way to deal with this type of character literal in the form of the alternative quote (q) operator. Notice that the problem is that Oracle chose the single quote characters as the special pair of symbols that enclose or wrap any other character literal. These character-enclosing symbols could have been anything other than single quotation marks.

Bearing this in mind, consider the alternative quote (q) operator. The q operator enables you to choose from a set of possible pairs of wrapping symbols for character literals as alternatives to the single quote symbols. The options are any single-byte or multibyte character or the four brackets: (round brackets), {curly braces}, [squarebrackets], or <angle brackets>. Using the q operator, the character delimiter can effectively be changed from a single quotation mark to any other character

The syntax of the alternative quote operator is as follows:

q'delimiter'character literal which may include the single quotes delimiter' where delimiter can be any character or bracket.

Alternative Quote (q) Operator

Specify your own quotation mark delimiter.

Select any delimiter.

Increase readability and usability.

SELECT department_name || q'[ Department's Manager Id: ]'

|| manager_id

AS "Department and Manager"

FROM departments;

Alternative Quote (q) Operator

Many SQL statements use character literals in expressions or conditions. If the literal itself contains a single quotation mark, you can use the quote (q) operator and select your own quotation mark delimiter.

You can choose any convenient delimiter, single-byte or multi byte, or any of the following character pairs: [ ], { }, ( ), or < >.

In the example shown, the string contains a single quotation mark, which is normally interpreted as a delimiter of a character string. By using the q operator, however, brackets [] are used as the quotation mark delimiters. The string between the brackets delimiters is interpreted as a literal character string.

QUESTION NO: 21

Examine the structure of the transactions table:

You want to display the date, time, and transaction amount of transactions that where done before 12 noon. The value zero should be displayed for transactions where the transaction amount has not been entered.

Which query gives the required result?

A. Option A

B. Option B

C. Option C

D. Option D

Answer: B

QUESTION NO: 22

Examine the data in the ename and hiredate columns of the employees table:

You want to generate a list of user IDs as follows:

You issue the following query:

What is the outcome?

A. It executes successfully and gives the correct output.

B. It executes successfully but does not give the correct output.

C. It generates an error because the REPLACE function is not valid.

D. It generates an error because the SUBSTR function cannot be nested in the CONCAT function.

Answer: A

Explanation:

REPLACE (text, search_string, replacement_string)

Searches a text expression for a character string and, if found, replaces it with a specified replacement string

The REPLACE Function

The REPLACE function replaces all occurrences of a search item in a source string with a replacement term and returns the modified source string. If the length of the replacement term is different from that of the search item, then the lengths of the returned and source strings will be different. If the search string is not found, the source string is returned unchanged. Numeric and date literals and expressions are evaluated before being implicitly cast as characters when they occur as parameters to the REPLACE function.

The REPLACE function takes three parameters, with the first two being mandatory. Its syntax is REPLACE (source string, search item, [replacement term]).

If the replacement term parameter is omitted, each occurrence of the search item is removed from the source string. In other words, the search item is replaced by an empty string. .

The following queries illustrate the REPLACE function with numeric and date expressions:

Query 1: select replace(10000-3, '9', '85') from dual

Query 2: select replace(sysdate, 'DEC', 'NOV') from dual

QUESTION NO: 23

Evaluate the following SQL commands:

The command to create a table fails. Identify the two reasons for the SQL statement failure?

A. You cannot use SYSDATE in the condition of a check constraint.

B. You cannot use the BETWEEN clause in the condition of a check constraint.

C. You cannot use the NEXTVAL sequence value as a default value for a column.

D. You cannot use ORD_NO and ITEM_NO columns as a composite primary key because ORD_NO is also the foreign key.

Answer: A, C

Explanation:

CHECK Constraint

The CHECK constraint defines a condition that each row must satisfy. The condition can use the same constructs as the query conditions, with the following exceptions:

References to the CURRVAL, NEXTVAL, LEVEL, and ROWNUM pseudocolumns

Calls to SYSDATE, UID, USER, and USERENV functions

Queries that refer to other values in other rows

A single column can have multiple CHECK constraints that refer to the column in its definition.

There is no limit to the number of CHECK constraints that you can define on a column.

CHECK constraints can be defined at the column level or table level.

CREATE TABLE employees

(...

Salary NUMBER(8, 2) CONSTRAINT emp_salary_min

CHECK (salary > 0),

QUESTION NO: 24

View the Exhibit and examine the structure of the SALES table.

The following query is written to retrieve all those product IDs from the SALES table that have more than 55000 sold and have been ordered more than 10 times.

Which statement is true regarding this SQL statement?

A. It executes successfully and generates the required result.

B. It produces an error because count(*) should be specified in the SELECT clause also.

C. It produces an error because count{*) should be only in the HAVING clause and not in the WHERE clause.

D. It executes successfully but produces no result because COUNT (prod_id) should be used instead of COUNT (*).

Answer: C

Explanation:

Restricting Group Results with the HAVING Clause

You use the HAVING clause to specify the groups that are to be displayed, thus further restricting the groups on the basis of aggregate information.

In the syntax, group_condition restricts the groups of rows returned to those groups for which the specified condition is true.

The Oracle server performs the following steps when you use the HAVING clause:

1. Rows are grouped.

2. The group function is applied to the group.

3. The groups that match the criteria in the HAVING clause are displayed.

The HAVING clause can precede the GROUP BY clause, but it is recommended that you place the GROUP BY clause first because it is more logical. Groups are formed and group functions are calculated before the HAVING clause is applied to the groups in the SELECT list.

Note: The WHERE clause restricts rows, whereas the HAVING clause restricts groups.

QUESTION NO: 25

View the Exhibit and examine the structure of the customers table.

Using the customers table, you need to generate a report that shows an increase in the credit limit by 15% for all customers. Customers whose credit limit has not been entered should have the message "Not Available" displayed.

Which SQL statement would produce the required result?

A. Option A

B. Option B

C. Option C

D. Option D

Answer: D

Explanation:

NVL Function

Converts a null value to an actual value:

Data types that can be used are date, character, and number.

Data types must match:

– NVL(commission_pct, 0)

– NVL(hire_date, '01-JAN-97')

– NVL(job_id, 'No Job Yet')

QUESTION NO: 26

View the Exhibit and examine the structure of the promotions table.

Evaluate the following SQL statement:

Which statement is true regarding the outcome of the above query?

A. It shows COST_REMARK for all the promos in the table.

B. It produces an error because the SUBQUERY gives an error.

C. It shows COST_REMARK for all the promos in the promo category 'TV'

D. It produces an error because SUBQUERIES cannot be used with the case expression.

Answer: A

QUESTION NO: 27

Examine the structure and data of the CUST_TRANS table:

Dates are stored in the default date format dd-mon-rr in the CUST_TRANS table. Which three SQL statements would execute successfully?

A. SELECT transdate + '10' FROM cust_trans;

B. SELECT * FROM cust_trans WHERE transdate = '01-01-07';

C. SELECT transamt FROM cust_trans WHERE custno > "11";

D. SELECT * FROM cust_trans WHERE transdate='01-JANUARY-07';

E. SELECT custno + 'A' FROM cust_trans WHERE transamt > 2000;

Answer: A, C, D

QUESTION NO: 28

View the Exhibit and examine the structure of the customers table.

NEW_CUSTOMERS is a new table with the columns CUST_ID, CUST_NAME and CUST_CITY that have the same data types and size as the corresponding columns in the customers table.

Evaluate the following insert statement:

The insert statement fails when executed.

What could be the reason?

A. The values clause cannot be used in an INSERT with a subquery.

B. Column names in the NEW_CUSTOMERS and CUSTOMERS tables do not match.

C. The where clause cannot be used in a subquery embedded in an INSERT statement.

D. The total number of columns in the NEW_CUSTOMERS table does not match the total number of columns in the CUSTOMERS table.

Answer: A

Explanation:

Copying Rows from Another Table

Write your INSERT statement with a subquery:

Do not use the VALUES clause.

Match the number of columns in the INSERT clause to those in the subquery.

Inserts all the rows returned by the subquery in the table, sales_reps.

QUESTION NO: 29

YOU need to display the date ll-oct-2007 in words as ‘Eleventh of October, Two Thousand Seven'.

Which SQL statement would give the required result?

A. Option A

B. Option B

C. Option C

D. Option D

Answer: A

QUESTION NO: 30

Examine the data in the ORD_ITEMS table:

Evaluate the following query:

Which statement is true regarding the outcome of the above query?

A. It gives an error because the having clause should be specified after the group by clause.

B. It gives an error because all the aggregate functions used in the having clause must be specified in the select list.

C. It displays the item nos with their average quantity where the average quantity is more than double the minimum quantity of that item in the table.

D. It displays the item nos with their average quantity where the average quantity is more than double the overall minimum quantity of all the items in the table.

Answer: C

QUESTION NO: 31

View the Exhibit and examine the data in the promotions table.

PROMO_BEGIN_DATE is stored in the default date format, dd-mon-rr.

You need to produce a report that provides the name, cost, and start date of all promos in the post category that were launched before January 1, 2000.

Which SQL statement would you use?

A. Option A

B. Option B

C. Option C

D. Option D

Answer: D

QUESTION NO: 32

You need to create a table with the following column specifications:

1. Employee ID (numeric data type) for each employee

2. Employee Name (character data type) that stores the employee name

3. Hire date, which stores the date of joining the organization for each employee

4. Status (character data type), that contains the value 'active1 if no data is entered

5. Resume (character large object [CLOB] data type), which contains the resume submitted by the employee

Which is the correct syntax to create this table?

A. Option A

B. Option B

C. Option C

D. Option D

Answer: D

Explanation:

CLOB Character data (up to 4 GB)

NUMBER [(p, s)] Number having precision p and scale s (Precision is the total number of decimal digits and scale is the number of digits to the right of the decimal point; precision can range from 1 to 38, and scale can range from –84 to 127.)

QUESTION NO: 33

Examine the structure of the sales table:

Evaluate the following create table statement:

Which two statements are true about the creation of the SALES1 table?

A. The SALES1 table is created with no rows but only a structure.

B. The SALES1 table would have primary key and unique constraints on the specified columns.

C. The SALES1 table would not be created because of the invalid where clause.

D. The SALES1 table would have not null and unique constraints on the specified columns.

E. The SALES1 table would not be created because column-specified names in the select and create table clauses do not match,

Answer: A

QUESTION NO: 34

Which two statements are true regarding subqueries?

A. A subquery can retrieve zero or more rows.

B. Only two subqueries can be placed at one level.

C. A subquery can be used only in SQL query statements.

D. A subquery can appear on either side of a comparison operator.

E. There is no limit on the number of subquery levels in the WHERE clause of a SELECT statement.

Answer: A, D

Explanation:

Using a Subquery to Solve a Problem

Suppose you want to write a query to find out who earns a salary greater than Abel’s salary.

To solve this problem, you need two queries: one to find how much Abel earns, and a second query to find who earns more than that amount.

You can solve this problem by combining the two queries, placing one query inside the other query. The inner query (or subquery) returns a value that is used by the outer query (or main query).

Using a subquery is equivalent to performing two sequential queries and using the result of the first query as the search value in the second query.

Subquery Syntax

A subquery is a SELECT statement that is embedded in the clause of another SELECT statement. You can build powerful statements out of simple ones by using subqueries. They can be very useful when you need to select rows from a table with a condition that depends on the data in the table itself.

You can place the subquery in a number of SQL clauses, including the following:

WHERE clause

HAVING clause

FROM clause

In the syntax:

operator includes a comparison condition such as >, =, or IN

Note: Comparison conditions fall into two classes: single-row operators (>, =, >=, <, <>, <=) and multiple-row operators (IN, ANY, ALL, EXISTS).

The subquery is often referred to as a nested SELECT, sub-SELECT, or inner SELECT statement. The subquery generally executes first, and its output is used to complete the query condition for the main (or outer) query.

Guidelines for Using Subqueries

Enclose subqueries in parentheses. Place subqueries on the right side of the comparison condition for readability. (However, the subquery can appear on either side of the comparison operator.) Use single-row operators with single-row subqueries and multiple-row operators with multiple-row subqueries.

Subqueries can be nested to an unlimited depth in a FROM clause but to “only” 255 levels in a WHERE clause. They can be used in the SELECT list and in the FROM, WHERE, and HAVING clauses of a query.

QUESTION NO: 35

Examine the structure of the products table:

You want to display the names of the products that have the highest total value for UNIT_PRICE * QTY_IN_HAND.

Which SQL statement gives the required output?

A. Option A

B. Option B

C. Option C

D. Option D

Answer: A

QUESTION NO: 36

Which statement is true regarding the UNION operator?

A. By default, the output is not sorted.

B. Null values are not ignored during duplicate checking.

C. Names of all columns must be identical across all select statements.

D. The number of columns selected in all select statements need not be the same.

Answer: D

Explanation:

The SQL UNION query allows you to combine the result sets of two or more SQL SELECT statements. It removes duplicate rows between the various SELECT statements.

Each SQL SELECT statement within the UNION query must have the same number of fields in the result sets with similar data types.

QUESTION NO: 37

View the Exhibit and examine the data in the PROMO_NAME and PROMO_END_DATE columns of the promotions table, and the required output format.

Which two queries give the correct result?

A. Option A

B. Option B

C. Option C

D. Option D

Answer: C, D

Site Search:

Close

Close
Download Free Demo of VCE
Exam Simulator

Experience Avanset VCE Exam Simulator for yourself.


Simply submit your e-mail address below to get started with our interactive software demo of your free trial.


Enter Your Email Address

Free Demo Limits: In the demo version you will be able to access only first 5 questions from exam.