Select incorrect variable declarations
-
foo_text varchar2(10) := 'hello world';
-
foo_char char(1) := 'Y';
-
foo_number varchar2(10);
-
foo_text number(10);
The incorrect variable declarations are A
- A. foo_text varchar2(10) := 'hello world'; is incorrect because the variable
foo_textis declared as avarchar2type, but the initial value'hello world'is astring. Avarchar2type can only store a sequence of characters, while astringcan store a sequence of characters and other special characters, such as spaces and symbols.
The correct variable declarations are B, C, D.
- B. foo_char char(1) := 'Y'; is correct because the variable
foo_charis declared as achartype, which is a special type ofvarchar2type that can only store a single character. The initial value'Y'is a single character, so it is a valid value for thefoo_charvariable. - C. foo_number varchar2(10); is correct because the variable
foo_numberis declared as avarchar2type, which can store a sequence of characters. The initial value'hello world'is a sequence of characters, so it is a valid value for thefoo_numbervariable. - D. foo_text number(10); is correct because the variable
foo_textis declared as anumbertype, which can store an integer
Therefore, the correct answer is A.
Correct answer: foo_text varchar2(10) := 'hello world';
'hello world' is 11 characters, which exceeds the declared VARCHAR2(10) limit — assigning it at declaration time raises a runtime error (ORA-06502: character string buffer too small), so this declaration/initialization is invalid.
The other three are all valid: foo_char char(1) := 'Y'; assigns a single character to a CHAR(1), which fits; foo_number varchar2(10); declares a VARCHAR2 with no initial value, which is legal; and foo_text number(10); declares a NUMBER with no initializer, also legal (the variable name being "foo_text" is just a misleading label, not a type mismatch).