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.
it works now on 19c version !!!
I agree that correct answer is B.
Confirmed by executing following code
in OE demo schema.
set serveroutput on;
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;
/
ERROR at line 4:
ORA-06550: line 4, column 19:
PLS-00206: %TYPE must be applied to a variable, column, field or attribute, not
to “V_ORDER_TOTAL”
ORA-06550: line 4, column 19:
PL/SQL: Item ignored
Code without CONSTANT keyword works fine.
set serveroutput on;
declare
v_order_id orders.order_id%type;
v_order_total 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;
/
Order Total is 1000
PL/SQL procedure successfully completed.
Can NOT get %TYPE from CONSTANT