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

certleader.com

Q1. - (Topic 2) 

Examine the description of the CUSTOMERS table: 

The CUSTOMER_ID column is the primary key for the table. 

Which statement returns the city address and the number of customers in the cities Los Angeles or San Francisco? 

A. SELECT city_address, COUNT(*) FROM customers 

WHERE city_address IN ( ‘Los Angeles’, ‘San Fransisco’); 

B. SELECT city_address, COUNT (*) 

FROMcustomers 

WHERE city address IN ( ‘Los Angeles’, ‘San Fransisco’) 

GROUP BY city_address; 

C. SELECT city_address, COUNT(customer_id) 

FROMcustomers 

WHERE city_address IN ( ‘Los Angeles’, ‘San Fransisco’) 

GROUP BYcity_address, customer_id; 

D. SELECT city_address, COUNT (customer_id) 

FROM customers 

GROUP BY city_address IN ( ‘Los Angeles’, ‘San Fransisco’); 

Answer:

Explanation: 

Not C: The customer ID in the GROUP BY clause is wrong 

Q2. - (Topic 1) 

View the Exhibit and examine the structure of ORDERS and CUSTOMERS tables. There is only one customer with the cus_last_name column having value Roberts. Which INSERT statement should be used to add a row into the ORDERS table for the customer whose CUST_LAST_NAME is Roberts and CREDIT_LIMIT is 600? 

A. INSERT INTO orders VALUES (l.'10-mar-2007\ 'direct'. (SELECT customerid FROM customers WHERE cust_last_iiame='Roberts' AND credit_limit=600). 1000); 

B. INSERT INTO orders (order_id.order_date.order_mode. (SELECT customer id FROM customers WHERE cust_last_iiame='Roberts' AND redit_limit=600).order_total) VALUES(L'10-mar-2007'. 'direct', &&customer_id, 1000): 

C. INSERT INTO(SELECT o.order_id. o.order_date.o.order_modex.customer_id. 

o.ordertotal FROM orders o. customers c WHERE o.customer_id = c.customerid AND c.cust_la$t_name-RoberTs' ANDc.credit_liinit=600) VALUES (L'10-mar-2007\ 'direct'.( SELECT customer_id FROM customers WHERE cust_last_iiame='Roberts' AND credit_limit=600). 1000); 

D. INSERT INTO orders (order_id.order_date.order_mode. 

(SELECT customer_id 

FROM customers 

WHERE cust_last_iiame='Roberts' AND 

credit_limit=600).order_total) 

VALUES(l.'10-mar-2007\ 'direct'. &customer_id. 1000): 

Answer:

Q3. - (Topic 1) 

Evaluate the following SQL commands: 

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

(Choose all that apply.) 

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), 

Q4. - (Topic 2) 

Evaluate the following CREATE SEQUENCE statement: 

CREATE SEQUENCE seq1 

START WITH 100 

INCREMENT BY 10 

MAXVALUE 200 

CYCLE 

NOCACHE; 

The SEQ1 sequence has generated numbers up to the maximum limit of 200. You issue the following SQL statement: 

SELECT seq1.nextval FROM dual; 

What is displayed by the SELECT statement? 

A. 1 

B. 10 

C. 100 

D. an error 

Answer:

Explanation: 

But why the answer is not "C" ? Because you didn't specify the MINVALUE for the sequence. If you check the sequence definition that you created it will have the default value of 1, which it reverts to when cycling. If you wanted to keep the minimum value you would need to specify it in the sequence creation. sequence Is the name of the sequence generator INCREMENT BY n Specifies the interval between sequence numbers, where n is an integer (If this clause is omitted, the sequence increments by 1.) START WITH n Specifies the first sequence number to be generated (If this clause is omitted, the sequence starts with 1.) MAXVALUE n Specifies the maximum value the sequence can generate NOMAXVALUE Specifies a maximum value of 10^27 for an ascending sequence and –1 for a descending sequence (This is the default option.) MINVALUE n Specifies the minimum sequence value NOMINVALUE Specifies a minimum value of 1 for an ascending sequence and –(10^26) for a descending sequence (This is the default option.) 

CYCLE | NOCYCLE Specifies whether the sequence continues to generate values after reaching its maximum or minimum value (NOCYCLE is the default option.) CACHE n | NOCACHE Specifies how many values the Oracle server preallocates and keeps in memory (By default, the Oracle server caches 20 values.) 

Q5. - (Topic 1) 

Examine the structure of the INVOICE table: Exhibit: 

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

A. SELECT inv_no,NVL2(inv_date,'Pending','Incomplete') FROM invoice; 

B. SELECT inv_no,NVL2(inv_amt,inv_date,'Not Available') FROM invoice; 

C. SELECT inv_no,NVL2(inv_date,sysdate-inv_date,sysdate) FROM invoice; 

D. SELECT inv_no,NVL2(inv_amt,inv_amt*.25,'Not Available') FROM invoice; 

Answer: A,C 

Explanation: 

The NVL2 Function 

The NVL2 function provides an enhancement to NVL but serves a very similar purpose. It evaluates whether a column or expression of any data type is null or not. 5-6 The NVL function\ If the first term is not null, the second parameter is returned, else the third parameter is returned. Recall that the NVL function is different since it returns the original term if it is not null. The NVL2 function takes three mandatory parameters. Its syntax is NVL2(original, ifnotnull, ifnull), where original represents the term being tested. Ifnotnull is returned if original is not null, and ifnull is returned if original is null. The data types of the ifnotnull and ifnull parameters must be compatible, and they cannot be of type LONG. They must either be of the same type, or it must be possible to convert ifnull to the type of the ifnotnull parameter. The data type returned by the NVL2 function is the same as that of the ifnotnull parameter. 

Q6. - (Topic 2) 

Evaluate this SQL statement: 

SELECT ename, sal, 12*sal+100 FROM emp; 

The SAL column stores the monthly salary of the employee. Which change must be made to the above syntax to calculate the annual compensation as "monthly salary plus a monthly bonus of $100, multiplied by 12"? 

A. No change is required to achieve the desired results. 

B. SELECT ename, sal, 12*(sal+100) FROM emp; 

C. SELECT ename, sal, (12*sal)+100 FROM emp; 

D. SELECT ename, sal+100,*12 FROM emp; 

Answer:

Explanation: 

to achieve the result you must add 100 to sal before multiply with 12. Select ename, sal, 12*(sal+100) from EMP; 

Incorrect Answer: AMultiplication and division has priority over addition and subtraction in Operator precedence. CGive wrong results DWrong syntax 

Refer: Introduction to Oracle9i: SQL, Oracle University Study Guide, 1-11 

Q7. - (Topic 1) 

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

Exhibit: 

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:

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. 

Q8. - (Topic 2) 

Which statements are true regarding the FOR UPDATE clause in a SELECT statement? (Choose all that apply.) 

A. It locks only the columns specified in the SELECT list. 

B. It locks the rows that satisfy the condition in the SELECT statement. 

C. It can be used only in SELECT statements that are based on a single table. 

D. It can be used in SELECT statements that are based on a single or multiple tables. 

E. After it is enforced by a SELECT statement, no other query can access the same rows until a COMMIT or ROLLBACK is issued. 

Answer: B,D 

Explanation: 

FOR UPDATE Clause in a SELECT Statement Locks the rows in the EMPLOYEES table where job_id is SA_REP. Lock is released only when you issue a ROLLBACK or a COMMIT. If the SELECT statement attempts to lock a row that is locked by another user, the database waits until the row is available, and then returns the results of the SELECT statement. FOR UPDATE Clause in a SELECT Statement When you issue a SELECT statement against the database to query some records, no locks are placed on the selected rows. In general, this is required because the number of records locked at any given time is (by default) kept to the absolute minimum: only those records that have been changed but not yet committed are locked. Even then, others will be able to read those records as they appeared before the change (the “before image” of the data). There are times, however, when you may want to lock a set of records even before you change them in your program. Oracle offers the FOR UPDATE clause of the SELECT statement to perform this locking. When you issue a SELECT...FOR UPDATE statement, the relational database management system (RDBMS) automatically obtains exclusive row-level locks on all the rows identified by the SELECT statement, thereby holding the records “for your changes only.” No one else will be able to change any of these records until you perform a ROLLBACK or a COMMIT. You can append the optional keyword NOWAIT to the FOR UPDATE clause to tell the Oracle server not to wait if the table has been locked by another user. In this case, control will be returned immediately to your program or to your SQL Developer environment so that you can perform other work, or simply wait for a period of time before trying again. Without the NOWAIT clause, your process will block until the table is available, when the locks are released by the other user through the issue of a COMMIT or a ROLLBACK command. 

Q9. - (Topic 1) 

Which three tasks can be performed using SQL functions built into Oracle Database? (Choose three.) 

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

B. Displaying a date in a nondefault format 

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

D. Finding the number of characters in an expression 

Answer: B,C,D 

Q10. - (Topic 2) 

Which two statements about creating constraints are true? (Choose two) 

A. Constraint names must start with SYS_C. 

B. All constraints must be defines at the column level. 

C. Constraints can be created after the table is created. 

D. Constraints can be created at the same time the table is created. 

E. Information about constraints is found in the VIEW_CONSTRAINTS dictionary view. 

Answer: C,D 

Explanation: 

Constraints can be created after the table is created. Use ALTER TABLE command for 

that. 

Constraints can be created at the same time the table is created (CREATE TABLE 

command). 

Incorrect Answers 

A:There is no requirements in Oracle that constraint names must start with SYS_C. Oracle 

can use prefix “SYS” to build indexes for UNIQUE and NOT NULL constraints, but it is not 

required for user to follow this naming rule. 

B:Not all constraints must be defines at the column level. Only NOT NULL constraint must 

be. 

E:There is no VIEW_CONSTRAINTS dictionary view in Oracle. 

OCP Introduction to Oracle 9i: SQL Exam Guide, Jason Couchman, p. 227-232 

Chapter 5: Creating Oracle Database Objects