1Z0-051 Exam - Oracle Database: SQL Fundamentals I

certleader.com

Q1. - (Topic 2) 

View the Exhibits and examine the structures of the COSTS and PROMOTIONS tables. 

Evaluate the following SQL statement: 

SQL> SELECT prod_id FROM costs WHERE promo_id IN (SELECT promo_id FROM promotions WHERE promo_cost < ALL (SELECT MAX(promo_cost) FROM promotions GROUP BY (promo_end_datepromo_ begin_date))); 

What would be the outcome of the above SQL statement? 

A. It displays prod IDs in the promo with the lowest cost. 

B. It displays prod IDs in the promos with the lowest cost in the same time interval. 

C. It displays prod IDs in the promos with the highest cost in the same time interval. 

D. It displays prod IDs in the promos with cost less than the highest cost in the same time interval. 

Answer:

Q2. - (Topic 1) 

View the Exhibits and examine the structures of the PRODUCTS SALES and CUSTOMERS tables. 

You need to generate a report that gives details of the customer's last name, name of the product, and the quantity sold for all customers in Tokyo'. Which two queries give the required result? (Choose two.) 

A. 

SELECT c.cust_last_name,p.prod_name, s.quantity_sold FROM sales s JOIN products p 

USING(prod_id) 

JOIN customers c 

USING(cust_id) 

WHERE c.cust_city='Tokyo' 

B. 

SELECT c.cust_last_name, p.prod_name, s.quantity_sold 

FROM products p JOIN sales s JOIN customers c 

ON(p.prod_id=s.prod_id) 

ON(s.cust_id=c.cust_id) 

WHERE c.cust_city='Tokyo' 

C. 

SELECT c.cust_last_name, p.prod_name, s.quantity_sold 

FROM products p JOIN sales s 

ON(p.prod_id=s.prod_id) 

JOIN customers c 

ON(s.cust_id=c.cust_id) 

AND c.cust_city='Tokyo' 

D. 

SELECT c.cust_id,c.cust_last_name,p.prod_id, p.prod_name, s.quantity_sold FROM 

products p JOIN sales s 

USING(prod_id) 

JOIN customers c 

USING(cust_id) 

WHERE c.cust_city='Tokyo' 

Answer: A,C 

Q3. - (Topic 2) 

You need to create a table named ORDERS that contain four columns: 

1. 

an ORDER_ID column of number data type 

2. 

a CUSTOMER_ID column of number data type 

3. 

an ORDER_STATUS column that contains a character data type 

4. 

a DATE_ORDERED column to contain the date the order was placed. 

When a row is inserted into the table, if no value is provided when the order was placed, today’s date should be used instead. 

Which statement accomplishes this? 

A. CREATE TABLE orders (order_id NUMBER (10),customer_id NUMBER (8),order_status VARCHAR2 (10),date_ordered DATE = SYSDATE); 

B. CREATE TABLE orders (order_id NUMBER (10),customer_id NUMBER (8),order_status VARCHAR2 (10),date_ordered DATE DEFAULT SYSDATE); 

C. CREATE OR REPLACE TABLE orders (order_id NUMBER (10),customer_id NUMBER (8),order_status VARCHAR2 (10),date_ordered DATE DEFAULT SYSDATE); 

D. CREATE OR REPLACE TABLE orders (order_id NUMBER (10),customer_id NUMBER (8),order_status VARCHAR2 (10),date_ordered DATE = SYSDATE); 

E. CREATE TABLE orders (order_id NUMBER (10),customer_id NUMBER (8),order_status NUMBER (10),date_ordered DATE = SYSDATE); 

F. CREATE TABLE orders (order_id NUMBER (10),customer_id NUMBER (8),order_status NUMBER (10),date_ordered DATE DEFAULT SYSDATE); 

Answer:

Explanation: Requirement that Order_Status should be a character data type 

Not E: Order_status must be a character data type. There is also a syntax error. 

Q4. - (Topic 2) 

Examine the structure of the PROMOTIONS table: 

The management wants to see a report of unique promotion costs in each promotion category. 

Which query would achieve the required result? 

A. SELECT DISTINCT promo_cost, promo_category FROM promotions; 

B. SELECT promo_category, DISTINCT promo_cost FROM promotions; 

C. SELECT DISTINCT promo_cost, DISTINCT promo_category FROM promotions; 

D. SELECT DISTINCT promo_category, promo_cost FROM promotions ORDER BY 1; 

Answer:

Q5. - (Topic 1) 

Examine the structure of the STUDENTS table: 

You need to create a report of the 10 students who achieved the highest ranking in the course INT SQL and who completed the course in the year 1999. 

Which SQL statement accomplishes this task? 

A. SELECT student_ id, marks, ROWNUM "Rank" 

FROM students 

WHERE ROWNUM <= 10 

AND finish_date BETWEEN '01-JAN-99' AND '31-DEC-99 

AND course_id = 'INT_SQL' 

ORDER BY marks DESC; 

B. SELECT student_id, marks, ROWID "Rank" 

FROM students 

WHERE ROWID <= 10 

AND finish_date BETWEEN '01-JAN-99' AND '31-DEC-99' 

AND course_id = 'INT_SQL' 

ORDER BY marks; 

C. SELECT student_id, marks, ROWNUM "Rank" 

FROM (SELECT student_id, marks 

FROM students 

WHERE ROWNUM <= 10 

AND finish_date BETWEEN '01-JAN-99' AND '31-DEC-

99' 

AND course_id = 'INT_SQL' 

ORDER BY marks DESC); 

D. SELECT student_id, marks, ROWNUM "Rank” 

FROM (SELECT student_id, marks 

FROM students 

WHERE (finish_date BETWEEN ’01-JAN-99 AND ’31-DEC-99’ 

AND course_id = ‘INT_SQL’ 

ORDER BY marks DESC) 

WHERE ROWNUM <= 10 ; 

E. SELECTstudent id, marks, ROWNUM “Rank” 

FROM(SELECT student_id, marks 

FROM students 

ORDER BY marks) 

WHEREROWNUM <= 10 

ANDfinish date BETWEEN ’01-JAN-99’ AND ’31-DEC-99’ 

ANDcourse_id = ‘INT_SQL’; 

Answer:

Q6. - (Topic 2) 

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

You want to display only those product names with their list prices where the list price is at least double the minimum price. The report should start with the product name having the maximum list price satisfying this 

condition. 

Evaluate the following SQL statement: 

SQL>SELECT prod_name,prod_list_price FROM products WHERE prod_list_price >= 2 * prod_min_price 

Which ORDER BY clauses can be added to the above SQL statement to get the correct output? 

(Choose all that apply.) 

A. ORDER BY prod_list_price DESC, prod_name; 

B. ORDER BY (2*prod_min_price)DESC, prod_name; 

C. ORDER BY prod_name, (2*prod_min_price)DESC; 

D. ORDER BY prod_name DESC, prod_list_price DESC; 

E. ORDER BY prod_list_price DESC, prod_name DESC; 

Answer: A,E 

Explanation: 

Using the ORDER BY Clause The order of rows that are returned in a query result is undefined. The ORDER BY clause can be used to sort the rows. However, if you use the ORDER BY clause, it must be the last clause of the SQL statement. Further, you can specify an expression, an alias, or a column position as the sort condition. Syntax SELECT expr FROM table [WHERE condition(s)] [ORDER BY {column, expr, numeric_position} [ASC|DESC]]; In the syntax: ORDER BY specifies the order in which the retrieved rows are displayed ASC orders the rows in ascending order (This is the default order.) 

DESC orders the rows in descending order If the ORDER BY clause is not used, the sort order is undefined, and the Oracle server may not fetch rows in the same order for the same query twice. Use the ORDER BY clause to display the rows in a specific order. Note: Use the keywords NULLS FIRST or NULLS LAST to specify whether returned rows containing null values should appear first or last in the ordering sequence. 

Q7. - (Topic 1) 

You work as a database administrator at ABC.com. You study the exhibit carefully. 

Exhibit: 

and examine the structure of CUSTOMRS AND SALES tables: 

Evaluate the following SQL statement: 

Exhibit: 

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

A. It would not execute because the SELECT statement cannot be used in place of the table name 

B. It would execute and restrict modifications to only the column specified in the SELECT statement 

C. It would not execute because a sub query cannot be used in the WHERE clause of an UPDATE statement 

D. It would not execute because two tables cannot be used in a single UPDATE statement 

Answer:

Q8. - (Topic 1) 

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. The total number of columns in the NEW_CUSTOMERS table does not match the total number of columns in the CUSTOMERS table 

C. The WHERE clause cannot be used in a sub query embedded in an INSERT statement 

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

Answer:

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. 

Q9. - (Topic 1) 

View the Exhibit and examine the description for the CUSTOMERS table. 

You want to update the CUST_INCOME_LEVEL and CUST_CREDIT_LIMIT columns for the customer with the CUST_ID 2360. You want the value for the CUST_INCOME_LEVEL to have the same value as that of the customer with the CUST_ID 2560 and the CUST_CREDIT_LIMIT to have the same value as that of the customer with CUST_ID 2566. 

Which UPDATE statement will accomplish the task? 

A. 

UPDATE customers SET cust_income_level = (SELECT cust_income_level FROM customers WHERE cust_id = 2560), cust_credit_limit = (SELECT cust_credit_limit FROM customers WHERE cust_id = 2566) WHERE cust_id=2360; 

B. 

UPDATE customers SET (cust_income_level,cust_credit_limit) = (SELECT cust_income_level, cust_credit_limit FROM customers WHERE cust_id=2560 OR cust_id=2566) WHERE cust_id=2360; 

C. 

UPDATE customers SET (cust_income_level,cust_credit_limit) = (SELECT cust_income_level, cust_credit_limit FROM customers WHERE cust_id IN(2560, 2566) WHERE cust_id=2360; 

D. 

UPDATE customers SET (cust_income_level,cust_credit_limit) = (SELECT cust_income_level, cust_credit_limit FROM customers WHERE cust_id=2560 AND cust_id=2566) WHERE cust_id=2360; 

Answer:

Explanation: 

Updating Two Columns with a Subquery 

You can update multiple columns in the SET clause of an UPDATE statement by writing 

multiple subqueries. The syntax is as follows: 

UPDATE table 

SET column = 

(SELECT column 

FROM table 

WHERE condition) 

[ , 

column = 

(SELECT column 

FROM table 

WHERE condition)] 

[WHERE condition ] ; 

Q10. - (Topic 1) 

See the Exhibit and examine the structure and data in the INVOICE table: Exhibit: 

Which two SQL statements would execute successfully? (Choose two.) 

A. SELECT MAX(inv_date),MIN(cust_id) FROM invoice; 

B. SELECT AVG(inv_date-SYSDATE),AVG(inv_amt) FROM invoice; 

C. SELECT MAX(AVG(SYSDATE-inv_date)) FROM invoice; 

D. SELECT AVG(inv_date) FROM invoice; 

Answer: A,B