2011-10-20% use of TYPE
Http://www.itpub.net/thread-1499223-7-1.html
65th floor
I created these types and tables:
CREATE TYPE plch_food_t AS OBJECT (name VARCHAR2); / CREATE or replace TYPE plch_food_nt IS TABLE OF VARCHAR2 / CREATE TABLE plch_food (name VARCHAR2) / CREATE OR REPLACE PACKAGE plch_pkgIS TYPE food_rt IS RECORD (name VARCHAR2); END;/
Which of the following options will display "Brussels Sprouts" after execution?
(A)
DECLARE l_var plch_food.name%TYPE: = 'Brussels Sprouts';BEGIN DBMS_OUTPUT.put_line (l_var); END;/SQL > DECLARE 2 l_var plch_food.name%TYPE: =' Brussels Sprouts'; 3 BEGIN 4 DBMS_OUTPUT.put_line (l_var); 5 END; 6 / Brussels SproutsPL/SQL procedure successfully completedSQL >
(B)
DECLARE l_var plch_food_nt%TYPE: = 'Brussels Sprouts';BEGIN DBMS_OUTPUT.put_line (l_var); END;/SQL > DECLARE 2 l_var plch_food_nt%TYPE: =' Brussels Sprouts'; 3 BEGIN 4 DBMS_OUTPUT.put_line (l_var); 5 END; 6 / DECLARE l_var plch_food_nt%TYPE: = 'Brussels Sprouts';BEGIN DBMS_OUTPUT.put_line (l_var); END ORA-06550: line 2, column 12: PLS-00206:% TYPE must be used for variables, columns, fields or attributes, not 'PLCH_FOOD_NT'ORA-06550: line 2, column 12: PL/SQL: Item ignoredORA-06550: line 4, column 26: PLS-00320: the type declaration of this expression is incomplete or malformed ORA-06550: line 4, column 4: PL/SQL: Statement ignoredSQL >
(C)
DECLARE l_var plch_food_t.name%TYPE: = 'Brussels Sprouts';BEGIN DBMS_OUTPUT.put_line (l_var); END;/SQL > DECLARE 2 l_var plch_food_t.name%TYPE: =' Brussels Sprouts'; 3 BEGIN 4 DBMS_OUTPUT.put_line (l_var); 5 END; 6 / DECLARE l_var plch_food_t.name%TYPE: = 'Brussels Sprouts';BEGIN DBMS_OUTPUT.put_line (l_var); END ORA-06550: line 2, column 12: PLS-00206:% TYPE must be used for variables, columns, fields or attributes, not 'PLCH_FOOD_T.NAME'ORA-06550: line 2, column 12: PL/SQL: Item ignoredORA-06550: line 4, column 26: PLS-00320: the type declaration of this expression is incomplete or malformed ORA-06550: line 4, column 4: PL/SQL: Statement ignoredSQL >
(D)
DECLARE l_var plch_pkg.food_rt.name%TYPE: = 'Brussels Sprouts';BEGIN DBMS_OUTPUT.put_line (l_var); END;/SQL > DECLARE 2 l_var plch_pkg.food_rt.name%TYPE: =' Brussels Sprouts'; 3 BEGIN 4 DBMS_OUTPUT.put_line (l_var); 5 END; 6 / DECLARE l_var plch_pkg.food_rt.name%TYPE: = 'Brussels Sprouts' BEGIN DBMS_OUTPUT.put_line (l_var); END ORA-06550: line 2, column 12: PLS-00206:% TYPE must be used for variables, columns, fields or attributes, not 'PLCH_PKG.FOOD_RT.NAME'ORA-06550: line 2, column 12: PL/SQL: Item ignoredORA-06550: line 4, column 26: PLS-00320: the type declaration of this expression is incomplete or malformed ORA-06550: line 4, column 4: PL/SQL: Statement ignoredSQL >
Answer A
The answer shows that the 70th floor
2011-10-20 answer Why not AD? You cannot use% TYPE directly for a record type. You must first declare a variable based on that record type, and then use% TYPE:DECLARE l_food plch_pkg.food_rt; l_var l_food.name%TYPE: = 'Brussels Sprouts';BEGIN DBMS_OUTPUT.put_line (l_var); END;/SQL > DECLARE 2 l_food plch_pkg.food_rt for this variable 3 l_var l_food.name%TYPE: = 'Brussels Sprouts'; 4 BEGIN 5 DBMS_OUTPUT.put_line (l_var); 6 END; 7 / Brussels SproutsPL/SQL procedure successfully completedSQL >