Oracle Database Sql Certified Associate · Free Practice Question Hard

Question 35

View and examine the following SQL exhibit.

Exhibit: 1

 

Given: The above command fails when executed.

Identify the reason for the failed execution.

  • A

    ORD_NO and ITEM_NO cannot be used as a composite primary key because ORD_NO is also the FOREIGN KEY.

  • B

    The CHECK constraint cannot be placed on columns having the DATE data type.

  • C

    The BETWEEN clause cannot be used for the CHECK constraint.

  • D

    SYSDATE cannot be used with the CHECK constraint.

Reveal correct answer

Correct answer: D

Explanation

Correct option: SYSDATE cannot be used with the CHECK constraint.

The CHECK constraint in Oracle cannot reference functions like SYSDATE because it must be evaluated at the time of insertion or update using fixed column values. Since SYSDATE is dynamic and constantly changing, it cannot be enforced as a constraint in this way.

If you need to impose a restriction involving SYSDATE, consider using:

  • Triggers: You can write a BEFORE INSERT or BEFORE UPDATE trigger to enforce the condition.

  • Default Values: Use DEFAULT SYSDATE for timestamp columns where needed.

  • Computed Expressions: Instead of a constraint, check conditions within queries or application logic.


Oracle’s CHECK constraints must be deterministic, meaning they must evaluate to the same result for the same input, every time.

  • SYSDATE is non-deterministic — it changes constantly.

  • As a result, you cannot use SYSDATE (or CURRENT_DATE, etc.) in a CHECK constraint.

Example – Invalid:

This will throw an ORA-02436: date or system variable wrongly specified in CHECK constraint.

Alternative Approaches:

  • Use a trigger to validate SYSDATE-based conditions using a BEFORE INSERT OR UPDATE trigger:

What This Trigger Does:

  • Runs before any insert or update on the orders table.

  • Checks if the new ord_date is greater than the current system date.

  • If so, it raises an error and prevents the operation.

The Oracle SYSDATE function returns the current date and time of the Operating System (OS) where the Oracle Database installed.

Syntax

Since the SYSDATE function does not require any argument, you can call it without specifying the parentheses:

Return value

The SYSDATE function returns the current date and time value whose type is DATE.

The format of the returned date time value depends on the value of the NLS_DATE_FORMAT parameter.

Remarks

The Oracle SYSDATE function cannot be used in the condition of a CHECK constraint.

A. The error in the execution is not related to the composite primary key constraint on ORD_NO and ITEM_NO. The issue lies in the usage of the SYSDATE function in the CHECK constraint, not in the primary key definition.

B. The CHECK constraint can be applied to columns with the DATE data type to enforce specific conditions on the values stored in those columns. Therefore, the failure of the execution is not due to the data type of the columns.

C. The BETWEEN clause can be used in a CHECK constraint to define a range of values that a column can hold. However, in this specific case, the issue is not related to the use of the BETWEEN clause.

D. The SYSDATE function is not allowed in a CHECK constraint because the value of SYSDATE changes every time the constraint is evaluated, making it unsuitable for defining a static condition.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need