Which statement is correct about the above code?

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?

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.



Leave a Reply 18

Your email address will not be published. Required fields are marked *


Uladzimir

Uladzimir

B

%Type result in error for conststant

alex

alex

It gives an error in line 4 because a constant always needs to have a value.

Fabio

Fabio

nope… just you cannot use %type with constants.

sud

sud

B

%TYPE cannot be applied to CONSTANTS

dudeman

dudeman

B. A variable defined as CONSTANT cannot be referenced for %TYPE.

tal

tal

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. 🙂

Leo Yu

Leo Yu

Thanks Tal, nice explaination

A.

A.

But is on line 3, so the answer should be A.

Vitaly

Vitaly

No, “B”.
This code gives an error in line 4, while line 3 is valid.
%TYPE cannot be applied to constants.

Alisa

Alisa

( 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;

palvch

palvch

B is correct.

alex

alex

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)

Alvornic

Alvornic

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;

N

N

Oracle 11g answer B, Oracle 12c answer D, but on exam you have to choose ans B because exam is for 11g.