ORDER_TOTAL is a column in the orders table with the data type and size as number (8, 2)
Examine the following code:
Which statement is correct about the above code?
A.
It gives an error in line 3
B.
It gives an error in line 4
C.
It gives an error in line 6
D.
It executes successfully and displays the output.
B
%Type result in error for conststant
B
b
It gives an error in line 4 because a constant always needs to have a value.
nope… just you cannot use %type with constants.
B
%TYPE cannot be applied to CONSTANTS
B. A variable defined as CONSTANT cannot be referenced for %TYPE.
used my existing tables for data types.
DECLARE
v_order_id plc.IPLCID%type;
v_order_total CONSTANT plc.ICUSNUM%TYPE := 1000;
v_all_order_total v_order_total%TYPE;
BEGIN
v_order_id := NULL;
DBMS_OUTPUT.PUT_LINE(‘Order Total is ‘||v_order_total);
END;
LINE 4 COLUMN 19
PLS-00206: %TYPE must be applied to a variable,
column, field or ettribute, not to V_ORDER_TOTAL.
IF delete word ‘CONSTANT’ THEN block will work. 🙂
Thanks Tal, nice explaination
But is on line 3, so the answer should be A.
No, “B”.
This code gives an error in line 4, while line 3 is valid.
%TYPE cannot be applied to constants.
( erase the constant keyword )
create table orders (ORDER_TOTAL number(8,2), order_id number);
/
drop table orders;
/
DECLARE
v_order_id orders.order_id%TYPE;
v_order_total constant orders.order_total%TYPE := 1000; <– delete the constant keyword
v_all_order_total v_order_total%TYPE;
BEGIN
v_order_id := NULL;
End;
B is correct.
B
Error report –
ORA-06550: line 4, column 18:
PLS-00206: %TYPE must be applied to a variable, column, field or attribute
So the correct answer is B (It gives an error in line 4)
B
OK, tested the code using Oracle Live SQL and i get the following output:
Order Total is 1000
Maybe the indicated option(B) is available for an older version of Oracle SQL.
Code used:
DECLARE
v_order_id orders.order_id%TYPE;
v_order_total CONSTANT orders.order_total%TYPE := 1000;
v_all_order_total v_order_total%TYPE;
BEGIN
v_order_id := NULL;
DBMS_OUTPUT.PUT_LINE(‘Order Total is ‘ || v_order_total);
END;
Oracle 11g answer B, Oracle 12c answer D, but on exam you have to choose ans B because exam is for 11g.