1Z0-051 Premium Bundle

1Z0-051 Premium Bundle

Oracle Database: SQL Fundamentals I Certification Exam

4.5 
(24435 ratings)
0 QuestionsPractice Tests
0 PDFPrint version
May 20, 2024Last update

Oracle 1Z0-051 Free Practice Questions

Q1. - (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), 

Q2. - (Topic 2) 

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

Examine the data in the ENAME and HIREDATE columns of the EMPLOYEES table: 

ENAME HIREDATE 

SMITH 17-DEC-80 ALLEN 20-FEB-81 WARD 22-FEB-81 

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

Smi17DEC80 All20FEB81 War22FEB81 

You issue the following query: 

SQL>SELECT CONCAT(SUBSTR(INITCAP(ename),1,3), REPLACE(hiredate,'-')) 

"USERID" 

FROM employees; 

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:

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 

Q3. - (Topic 2) 

Which SQL statement accepts user input for the columns to be displayed, the table name, and WHERE condition? 

A. SELECT &1, "&2" 

FROM &3 

WHERE last_name = '&4' 

B. SELECT &1, '&2' 

FROM &3 

WHERE '&last_name = '&4' ' 

C. SELECT &1, &2 

FROM &3 

WHERE last_name = '&4' 

D. SELECT &1, '&2' 

FROM EMP 

WHERE last_name = '&4' 

Answer:

Explanation: 

In a WHERE clause, date and characters values must be enclosed within single quotation marks. 

Sample of the correct syntax 

SELECT EMPLOYEE_ID, &COLUMN_NAME FROM EMPLOYEES 

Incorrect Answers : 

A. Incorrect use of " symbol 

B. Incorrect use of ' symbol 

D. No input for table name as EMP has been use in the statement. 

Refer: Introduction to Oracle9i: SQL, Oracle University Student Guide, Producing Readable Output with iSQL*PLUS, p. 7-8 

Q4. - (Topic 2) 

Which two statements are true regarding constraints? (Choose two.) 

A. A foreign key cannot contain NULL values. 

B. A column with the UNIQUE constraint can contain NULL values. 

C. A constraint is enforced only for the INSERT operation on a table. 

D. A constraint can be disabled even if the constraint column contains data. 

E. All constraints can be defined at the column level as well as the table level. 

Answer: B,D 

Explanation: 

Including Constraints 

Constraints enforce rules at the table level. 

Constraints prevent the deletion of a table if there are dependencies. 

The following constraint types are valid: 

– 

NOT NULL 

– 

UNIQUE 

– 

PRIMARY KEY 

– 

FOREIGN KEY 

– 

CHECK 

Q5. - (Topic 1) 

Which statement is true regarding sub queries? 

A. The LIKE operator cannot be used with single- row subqueries. 

B. The NOT IN operator is equivalent to IS NULL with single- row subqueries. 

C. =ANY and =ALL operators have the same functionality in multiple- row subqueries. 

D. The NOT operator can be used with IN, ANY, and ALL operators in multiple- row subqueries. 

Answer:

Explanation: 

Using the ANY Operator in Multiple-Row Subqueries 

The ANY operator (and its synonym, the SOME operator) compares a value to each value 

returned by a subquery. 

<ANY means less than the maximum. 

>ANY means more than the minimum. 

=ANY is equivalent to IN 

Using the ALL Operator in Multiple-Row Subqueries 

The ALL operator compares a value to every value returned by a subquery. 

>ALL means more than the maximum and 

<ALL means less than the minimum. 

The NOT operator can be used with IN, ANY, and ALL operators. 

Q6. - (Topic 1) 

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

Examine the structure of 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 fails below $10 after a discount of 25% is applied on it. 

Exhibit: 

The query generates an error. 

What is the reason of generating error? 

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

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

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

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

Answer:

Explanation: Note: You cannot use column alias in the WHERE clause. 

Q7. - (Topic 1) 

Which three statements are true regarding the data types in Oracle Database 10g/11g? (Choose three.) 

A. The BLOB data type column is used to store binary data in an operating system file 

B. The minimum column width that can be specified for a VARCHAR2 data type column is one 

C. A TIMESTAMP data type column stores only time values with fractional seconds 

D. The value for a CHAR data type column is blank-padded to the maximum defined column width 

E. Only One LONG column can be used per table 

Answer: B,D,E 

Explanation: 

LONG Character data in the database character set, up to 2GB. All the functionality of LONG (and more) is provided by CLOB; LONGs should not be used in a modern database, and if your database has any columns of this type they should be converted to CLOB. There can only be one LONG column in a table. DVARCHAR2 Variable-length character data, from 1 byte to 4KB. The data is stored in the database character set. The VARCHAR2 data type must be qualified with a number indicating the maximum length of the column. If a value is inserted into the column that is less than this, it is not a problem: the value will only take up as much space as it needs. If the value is longer than this maximum, the INSERT will fail with an error. VARCHAR2(size) Variable-length character data (A maximum size must be specified: minimum size is 1; maximum size is 4,000.) BLOB Like CLOB, but binary data that will not undergo character set conversion by Oracle 

Net. 

BFILE A locator pointing to a file stored on the operating system of the database server. 

The size of the files is limited to 4GB. 

TIMESTAMP This is length zero if the column is empty, or up to 11 bytes, depending on 

the precision specified. 

Similar to DATE, but with precision of up to 9 decimal places for the seconds, 6 places by 

default. 

Q8. - (Topic 1) 

Examine the structure of the EMPLOYEES table: 

Which INSERT statement is valid? 

A. 

INSERT INTO employees (employee_id, first_name, last_name, hire_date) VALUES ( 1000, ‘John’, ‘Smith’, ‘01/01/01’); 

B. 

INSERT INTO employees(employee_id, first_name, last_name, hire_date) VALUES ( 1000, ‘John’, ‘Smith’, ’01 January 01’); 

C. 

INSERT INTO employees(employee_id, first_name, last_name, Hire_date) VALUES ( 1000, ‘John’, ‘Smith’, To_date(‘01/01/01’)); 

D. 

INSERT INTO employees(employee_id, first_name, last_name, hire_date) VALUES ( 1000, ‘John’, ‘Smith’, 01-Jan-01); 

Answer:

Explanation: It is the only statement that has a valid date; all other will result in an error. Answer A is incorrect, syntax error, invalid date format 

Q9. - (Topic 2) 

The user Sue issues this SQL statement: 

GRANT SELECT ON sue.EMP TO alice WITH GRANT OPTION; 

The user Alice issues this SQL statement: 

GRANT SELECT ON sue.EMP TO reena WITH GRANT OPTION; 

The user Reena issues this SQL statement: 

GRANT SELECT ON sue.EMP TO timber; 

The user Sue issues this SQL statement: 

REVOKE select on sue.EMP FROM alice; 

For which users does the revoke command revoke SELECT privileges on the SUE.EMP table? 

A. Alice only 

B. Alice and Reena 

C. Alice, Reena, and Timber 

D. Sue, Alice, Reena, and Timber 

Answer:

Explanation: use the REVOKE statement to revoke privileges granted to other users. Privilege granted to others through the WITH GRANT OPTION clause are also revoked. Alice, Reena and Timber will be revoke. 

Incorrect Answer: Athe correct answer should be Alice, Reena and Timber Bthe correct answer should be Alice, Reena and Timber Dthe correct answer should be Alice, Reena and Timber 

Refer: Introduction to Oracle9i: SQL, Oracle University Study Guide, 13-17 

Q10. - (Topic 1) 

See the structure of the PROGRAMS table: 

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

A. SELECT NVL(ADD_MONTHS(END_DATE,1),SYSDATE) FROM programs; 

B. SELECT TO_DATE(NVL(SYSDATE-END_DATE,SYSDATE)) FROM programs; 

C. SELECT NVL(MONTHS_BETWEEN(start_date,end_date),'Ongoing') FROM programs; 

D. SELECT NVL(TO_CHAR(MONTHS_BETWEEN(start_date,end_date)),'Ongoing') FROM programs; 

Answer: A,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') 

MONTHS_BETWEEN(date1, date2): Finds the number of months between date1 and date2 The result can be positive or negative. If date1 is later than date2, the result is positive; if date1 is earlier than date2, the result is negative. The noninteger part of the result represents a portion of the month. MONTHS_BETWEEN returns a numeric value. - answer C NVL has different datatypes -numeric and strings, which is not possible! 

The data types of the original and if null parameters must always be compatible. They must either be of the same type, or it must be possible to implicitly convert if null to the type of the original parameter. The NVL function returns a value with the same data type as the original parameter. 

Q11. - (Topic 1) 

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:

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 multibyte, 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. 

Q12. - (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 ] ; 

Q13. - (Topic 2) 

Examine the description of the EMPLOYEES table: 

EMP_ID NUMBER(4) NOT NULL LAST_NAME VARCHAR2(30) NOT NULL FIRST_NAME VARCHAR2(30) DEPT_ID NUMBER(2) 

Which statement produces the number of different departments that have employees with last name Smith? 

A. SELECT COUNT(*) FROM employees WHERE last_name='Smith' 

B. SELECT COUNT (dept_id) FROM employees WHERE last_name='Smith' 

C. SELECT DISTINCT(COUNT(dept_id)) FROM employees WHERE last_name='Smith' 

D. SELECT COUNT(DISTINCT dept_id) FROM employees WHERE last_name='Smith' 

E. SELECT UNIQUE(dept_id) FROM employees WHERE last_name='Smith' 

Answer:

Q14. - (Topic 1) 

When does a transaction complete? (Choose all that apply.) 

A. When a PL/SQL anonymous block is executed B. When a DELETE statement is executed 

C. When a data definition language statement is executed 

D. When a TRUNCATE statement is executed after the pending transaction 

E. When a ROLLBACK command is executed 

Answer: C,D,E 

Q15. - (Topic 2) 

The STUDENT_GRADES table has these columns: 

STUDENT_ID NUMBER(12) 

SEMESTER_END DATE 

GPA NUMBER(4,3) 

Which statement finds the highest grade point average (GPA) per semester? 

A. SELECT MAX(gpa) FROM student_grades WHERE gpa IS NOT NULL; 

B. SELECT (gpa) FROM student_grades GROUP BY semester_end WHERE gpa IS NOT NULL; 

C. SELECT MAX(gpa) FROM student_grades WHERE gpa IS NOT NULL GROUP BY semester_end; 

D. SELECT MAX(gpa) GROUP BY semester_end WHERE gpa IS NOT NULL FROM student_grades; 

E. SELECT MAX(gpa) FROM student_grades GROUP BY semester_end WHERE gpa IS NOT NULL; 

Answer:

Explanation: Explanation: For highest gpa value MAX function is needed, for result with per semester GROUP BY clause is needed 

Incorrect Answer: Aper semester condition is not included Bresult would not display the highest gpa value Dinvalid syntax error Einvalid syntax error Refer: Introduction to Oracle9i: SQL, Oracle University Study Guide, 5-7 

START 1Z0-051 EXAM