Multiple choice technology databases

On which line will the following command fail? INSERT INTO plsql101_product ( product_name, product_price, quantity_on_hand, last_stock_date ) VALUES ( 'New Product', 1.95, 10, TO_CHAR(USER) ) ;

  1. 1

  2. 2

  3. 7

  4. 10

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The TO_CHAR(USER) function converts a username string to character format, creating a type mismatch when inserting into a DATE column (last_stock_date). DATE columns require proper date values like SYSDATE or TO_DATE expressions, not string conversions. The TO_CHAR function returns a VARCHAR2, which cannot be directly inserted into a DATE column without implicit conversion.

AI explanation

Counting each clause on its own numbered line, the VALUES list supplies TO_CHAR(USER) for the last_stock_date column, which is a DATE column. TO_CHAR(USER) returns a character string (the current schema/user name, e.g. 'SCOTT'), and Oracle will attempt an implicit character-to-date conversion using the session's default date format — since a username string isn't a valid date literal, this raises a runtime conversion error (ORA-01858/ORA-01861-style) at that line, which is line 10 in this layout. The earlier lines (1, 2, 7) are syntactically fine column/keyword lines and don't fail.