Oracle SQL and Database Practice Questions Set 2

Oracle SQL and database questions: views, indexes, joins and subqueries, NULL handling, functions, privileges and roles, tuning and architecture. This set has 34 multiple-choice questions, each with a short explanation (set 2 of 2). Click Start quiz to answer one question at a time and get instant feedback, or use Study mode to read every question with its answer.

All 34 questions with answers

  1. How can you enable a trace for a session 1) DBMS_SESSION.SET_SQL_TRACE; 2) ALTER SESSION SET SQL_TRACE = TRUE; 3) FND_SESSION.SET_SQL_TRACE;
    1. 1
    2. 2
    3. 1 & 2
    4. 2,3
    Show answer

    Answer: C. 1 & 2

    Both DBMS_SESSION.SET_SQL_TRACE(TRUE) and ALTER SESSION SET SQL_TRACE = TRUE enable tracing. FND_SESSION.SET_SQL_TRACE does not exist.

  2. You cannot grant privileges on remote objects to other users.
    1. TRUE
    2. FALSE
    Show answer

    Answer: A. TRUE

    You cannot GRANT privileges on objects in a remote database through a database link.

  3. is a database structure that provides quick lookup of data in a column or columns of a table.
    1. PRIMARY KEYS
    2. UNIQUE KEY
    3. INDEX
    4. Option 1 & Option 2
    Show answer

    Answer: C. INDEX

    An index is a separate structure that gives fast lookup of rows by the values of one or more columns.

  4. A —- is a specific representation of data from one or more tables
    1. Synonym
    2. Views
    3. collections
    4. Recordset
    Show answer

    Answer: B. Views

    A view is a stored query that presents data from one or more tables.

  5. Maximum number of columns that can be defined in a view
    1. 1000
    2. 512
    3. same as for a table
    4. Option 1,3
    Show answer

    Answer: D. Option 1,3

    A view can have up to 1,000 columns, the same limit as a table (4,096 in Oracle 23ai).

  6. what is true about inline views
    1. Inline view is a subquery that appears in the from clause of the select statement
    2. Inline view is enclosed in parenthesis and may be given an alias name.
    3. The columns selected in the inline view can be referenced in the parent query
    4. All of the above
    Show answer

    Answer: D. All of the above

    An inline view is a subquery in the FROM clause, written in parentheses, often with an alias, and its columns can be used by the outer query.

  7. For a view to be inherently updatable,which of the following conditions must be met?
    1. Each column in the view must map to a column of a single table
    2. if an inherently updatable view contains pseudocolumns or expressions, then you cannot update base table rows with an UPDATE statement that refers to any of these pseudocolumns or expressions
    3. the select statement should not contains a DISTINCT operator
    4. All of the above
    Show answer

    Answer: D. All of the above

    An updatable view maps each column to one base table and has no DISTINCT, GROUP BY, aggregates or set operators. Expression columns cannot be updated.

  8. Which is not a pseudocolumns?
    1. ROWNUM
    2. ROWID
    3. NEXTVAL
    4. ROWCOUNT
    Show answer

    Answer: D. ROWCOUNT

    ROWNUM, ROWID, NEXTVAL, CURRVAL and LEVEL are pseudocolumns. ROWCOUNT is a cursor attribute (%ROWCOUNT), not a pseudocolumn.

  9. What is a nested subquery?
    1. It’s a subquery in the FROM clause with an alias that can be used as a view within the SQL statement
    2. The subquery used in WHERE clause
    3. The subquery used in WHERE clause and it refers to any column in the parent statement
    Show answer

    Answer: B. The subquery used in WHERE clause

    A nested subquery sits in the WHERE clause and runs on its own, independent of the outer query.

  10. What is a correlated subquery?
    1. It’s a subquery in the FROM clause with an alias that can be used as a view within the SQL statement
    2. The subquery used in WHERE clause
    3. The subquery used in WHERE clause and it refers to any column in the parent statement
    Show answer

    Answer: C. The subquery used in WHERE clause and it refers to any column in the parent statement

    A correlated subquery refers to columns of the outer query, so it is evaluated once for each outer row.

  11. Which statement is correct?
    1. GRANT UPDATE ON CUSTOMER (title,address) TO ANDREW;
    2. GRANT UPDATE (title,address) ON CUSTOMER TO ANDREW;
    3. GRANT UPDATE ON customer COLUMNS(title,addres) TO Adrew
    4. GRANT UPDATE ON customer.title,customer.address TO Adrew;
    Show answer

    Answer: B. GRANT UPDATE (title,address) ON CUSTOMER TO ANDREW;

    Column-level grants list the columns right after the privilege: GRANT UPDATE (title, address) ON customer TO andrew;

  12. MERGE command is a combination of?
    1. INSERT & UPDATE
    2. INSERT & DELETE
    3. UPDATE & DELETE
    4. None of these
    Show answer

    Answer: A. INSERT & UPDATE

    MERGE updates rows that match and inserts rows that don’t. From 10g it can also delete matched rows.

  13. What does the below statement does? select * from emp where (rowid,1) in (select rowid, mod(rownum,2) from emp);
    1. Dispalys odd number of records
    2. Give runtime error
    3. Get execution error
    4. Display all records in table emp.
    Show answer

    Answer: A. Dispalys odd number of records

    MOD(ROWNUM, 2) is 1 for rows 1, 3, 5 and so on, so the query returns the odd-numbered rows.

  14. Which date function returns a number value
    1. ADD_MONTHS
    2. MONTHS_BETWEEN
    3. NEXT_DAY
    4. ROUND
    Show answer

    Answer: B. MONTHS_BETWEEN

    MONTHS_BETWEEN returns a number. ADD_MONTHS, NEXT_DAY and ROUND on a date return dates.

  15. Omitting the WHERE clause of an UPDATE or DELETE statement has what effect?
    1. All rows in the specified table are affected
    2. The query returns an error because the WHERE clause is required.
    3. Only the current row is affected.
    4. Only the rows with the correct data type are affected
    Show answer

    Answer: A. All rows in the specified table are affected

    Without a WHERE clause, UPDATE and DELETE act on every row in the table.

  16. What statement could you use in the WHERE clause to select all the rows in a table where no price is defined
    1. WHERE price IS NOT NULL
    2. WHERE price IS < 0
    3. WHERE price IS NULL
    4. WHERE price != 0
    Show answer

    Answer: C. WHERE price IS NULL

    Missing values are stored as NULL, and NULL can only be tested with IS NULL.

  17. Which of the following is not a aggregate functions?
    1. SUM
    2. ABS
    3. COUNT
    4. MAX
    Show answer

    Answer: B. ABS

    ABS is a single-row function. SUM, COUNT and MAX are aggregate functions.

  18. How many rows the table DUAL has
    1. No rows
    2. Multiple
    3. one row
    4. DBA creates the table and inserts rows as needed
    Show answer

    Answer: C. one row

    DUAL has exactly one row and one column (DUMMY = ‘X’).

  19. RTRIM function is used to
    1. elimiate leading spaces
    2. eliminate trailing spaces
    3. to trim a string to a given length
    4. not a valid function
    Show answer

    Answer: B. eliminate trailing spaces

    RTRIM removes characters, spaces by default, from the right end of a string.

  20. LTRIM function is used to
    1. elimiate leading spaces
    2. eliminate trailing spaces
    3. to trim a string to a given length
    4. not a valid function
    Show answer

    Answer: A. elimiate leading spaces

    LTRIM removes characters, spaces by default, from the left end of a string.

  21. TRIM function is used to
    1. elimiate leading spaces
    2. eliminate trailing spaces
    3. to trim a string to a given length
    4. eliminate both leading and trailing spaces
    Show answer

    Answer: D. eliminate both leading and trailing spaces

    TRIM removes leading and trailing spaces (or another given character).

  22. What can you do to ignore the time portion of a DATE variable
    1. TRUNC
    2. TRIM
    3. SUBSTR
    4. A&D
    Show answer

    Answer: A. TRUNC

    TRUNC(date) sets the time part to midnight, so comparisons ignore the time.

  23. IS NULL operator is used
    1. when checking for NULL values
    2. not a valid command
    3. when checking for an empty string
    4. is equal to comparing with ”
    Show answer

    Answer: A. when checking for NULL values

    IS NULL checks for NULL. In Oracle an empty string ” is NULL, but = ” never returns TRUE.

  24. Which of these are conversion functions
    1. TO_DATE
    2. TO_NUMBER
    3. TO_CHAR
    4. All of the above
    Show answer

    Answer: D. All of the above

    TO_DATE, TO_NUMBER and TO_CHAR are all conversion functions.

  25. Converts either a number or a date to a character string
    1. TO_CHAR
    2. TO_DATE
    3. TO_NUMBER
    4. TO_VARCHAR
    Show answer

    Answer: A. TO_CHAR

    TO_CHAR converts a number or a date into a character string.

  26. Expression TRUE AND NULL evaluates to
    1. TRUE
    2. FALSE
    3. NULL
    4. RAISES syntax eror
    Show answer

    Answer: C. NULL

    TRUE AND NULL is NULL, because the result depends on the unknown value.

  27. Expression TRUE OR NULL evaluates to
    1. TRUE
    2. FALSE
    3. NULL
    4. RAISES syntax eror
    Show answer

    Answer: A. TRUE

    TRUE OR anything is TRUE, so TRUE OR NULL is TRUE.

  28. Which is the right way of dealing with NULL values
    1. x=NULL
    2. x IS NULL
    3. x=”
    4. x=’ ‘
    Show answer

    Answer: B. x IS NULL

    NULL can only be tested with IS NULL or IS NOT NULL. x = NULL is never true.

  29. TO_CHAR(SYSDATE,’Mon’) results if the sysdate is 12-JAN-2009
    1. JAN
    2. Jan
    3. JANUARY
    4. 9-Jan
    Show answer

    Answer: B. Jan

    The case of the format is copied: ‘Mon’ gives Jan, ‘MON’ gives JAN and ‘Month’ gives January.

  30. Which of the below is a DML statement
    1. INSERT
    2. UPDATE
    3. DELETE
    4. All of the above
    Show answer

    Answer: D. All of the above

    INSERT, UPDATE and DELETE (and MERGE) are DML statements.

  31. DDL statements means
    1. Data definition language
    2. Data dictionary language
    3. Data driven language
    Show answer

    Answer: A. Data definition language

    DDL stands for Data Definition Language: CREATE, ALTER, DROP, TRUNCATE and so on.

  32. Which statement will implicitly issue a commit
    1. DELETE
    2. INSERT
    3. TRUNCATE
    4. ROLLBACK
    Show answer

    Answer: C. TRUNCATE

    TRUNCATE is DDL, so it commits implicitly. INSERT and DELETE wait for an explicit COMMIT.

  33. Which of these are Pseudo columns
    1. ROWNUM
    2. NEXTVAL
    3. ROWID
    4. All of the above
    Show answer

    Answer: D. All of the above

    ROWNUM, NEXTVAL and ROWID are all pseudocolumns.

  34. Functionality of Right OUTER JOIN is same as right join. Is this statement true?
    1. No
    2. Yes
    Show answer

    Answer: B. Yes

    RIGHT JOIN and RIGHT OUTER JOIN are the same; the word OUTER is optional.

More Oracle practice questions

These questions come from interview and training material collected over years of Oracle EBS project work by Amol Jadhav. They are not copied from Oracle certification exams.