您好,登錄后才能下訂單哦!
這篇文章主要介紹“怎么使用CONSTANT變量與INDEX BY數(shù)組”,在日常操作中,相信很多人在怎么使用CONSTANT變量與INDEX BY數(shù)組問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”怎么使用CONSTANT變量與INDEX BY數(shù)組”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
我創(chuàng)建了如下包頭:
CREATE OR REPLACE PACKAGE plch_pkg AUTHID DEFINER IS TYPE names_t IS TABLE OF VARCHAR2 (20) INDEX BY PLS_INTEGER; END plch_pkg; /
哪些選項在執(zhí)行之后會顯示"3"?
(A)
DECLARE l_names CONSTANT plch_pkg.names_t := plch_pkg.names_t ('Horton', 'Hears', 'A Who') ; BEGIN DBMS_OUTPUT.put_line (l_names.COUNT); END; /
SQL> DECLARE 2 l_names CONSTANT plch_pkg.names_t 3 := plch_pkg.names_t ('Horton', 'Hears', 'A Who') ; 4 BEGIN 5 DBMS_OUTPUT.put_line (l_names.COUNT); 6 END; 7 / DECLARE l_names CONSTANT plch_pkg.names_t := plch_pkg.names_t ('Horton', 'Hears', 'A Who') ; BEGIN DBMS_OUTPUT.put_line (l_names.COUNT); END; ORA-06550: 第 3 行, 第 10 列: PLS-00222: 在此范圍中不存在名為 'NAMES_T' 的函數(shù) ORA-06550: 第 2 行, 第 14 列: PL/SQL: Item ignored ORA-06550: 第 5 行, 第 26 列: PLS-00320: 此表達式的類型聲明不完整或格式不正確 ORA-06550: 第 5 行, 第 4 列: PL/SQL: Statement ignored SQL>
(B)
DECLARE l_names CONSTANT plch_pkg.names_t := plch_pkg.names_t () ; BEGIN l_names (1) := 'Horton'; l_names (2) := 'Hears'; l_names (3) := 'A Who'; DBMS_OUTPUT.put_line (l_names.COUNT); END; /
SQL> DECLARE 2 l_names CONSTANT plch_pkg.names_t 3 := plch_pkg.names_t () ; 4 BEGIN 5 l_names (1) := 'Horton'; 6 l_names (2) := 'Hears'; 7 l_names (3) := 'A Who'; 8 DBMS_OUTPUT.put_line (l_names.COUNT); 9 END; 10 / DECLARE l_names CONSTANT plch_pkg.names_t := plch_pkg.names_t () ; BEGIN l_names (1) := 'Horton'; l_names (2) := 'Hears'; l_names (3) := 'A Who'; DBMS_OUTPUT.put_line (l_names.COUNT); END; ORA-06550: 第 3 行, 第 29 列: PLS-00222: 在此范圍中不存在名為 'NAMES_T' 的函數(shù) ORA-06550: 第 2 行, 第 14 列: PL/SQL: Item ignored ORA-06550: 第 5 行, 第 4 列: PLS-00320: 此表達式的類型聲明不完整或格式不正確 ORA-06550: 第 5 行, 第 4 列: PL/SQL: Statement ignored ORA-06550: 第 6 行, 第 4 列: PLS-00320: 此表達式的類型聲明不完整或格式不正確 ORA-06550: 第 6 行, 第 4 列: PL/SQL: Statement ignored ORA-06550: 第 7 行, 第 4 列: PLS-00320: 此表達式的類型聲明不完整或格式不正確 ORA-06550: 第 7 行, 第 4 列: PL/SQL: Statement ignored ORA-06550: 第 8 行, 第 26 列: PLS-00320: 此表達式的類型聲明不完整或格式不正確 ORA-06550: 第 8 行, 第 4 列: PL/SQL: Statement ignored SQL>
(C)
CREATE OR REPLACE FUNCTION plch_dr_seuss_names RETURN plch_pkg.names_t IS l_return plch_pkg.names_t; BEGIN l_return (1) := 'Horton'; l_return (2) := 'Hears'; l_return (3) := 'A Who'; RETURN l_return; END plch_dr_seuss_names; / DECLARE l_names CONSTANT plch_pkg.names_t := plch_dr_seuss_names () ; BEGIN DBMS_OUTPUT.put_line (l_names.COUNT); END; /
SQL> CREATE OR REPLACE FUNCTION plch_dr_seuss_names 2 RETURN plch_pkg.names_t 3 IS 4 l_return plch_pkg.names_t; 5 BEGIN 6 l_return (1) := 'Horton'; 7 l_return (2) := 'Hears'; 8 l_return (3) := 'A Who'; 9 RETURN l_return; 10 END plch_dr_seuss_names; 11 / Function created SQL> DECLARE 2 l_names CONSTANT plch_pkg.names_t 3 := plch_dr_seuss_names () ; 4 BEGIN 5 DBMS_OUTPUT.put_line (l_names.COUNT); 6 END; 7 / 3 PL/SQL procedure successfully completed SQL>
(D)
CREATE OR REPLACE FUNCTION plch_dr_seuss_names ( name1_in IN VARCHAR2 , name2_in IN VARCHAR2 , name3_in IN VARCHAR2) RETURN plch_pkg.names_t IS l_return plch_pkg.names_t; BEGIN l_return (1) := name1_in; l_return (2) := name2_in; l_return (3) := name3_in; RETURN l_return; END plch_dr_seuss_names; / DECLARE l_names CONSTANT plch_pkg.names_t := plch_dr_seuss_names ('Horton', 'Hears', 'A Who') ; BEGIN DBMS_OUTPUT.put_line (l_names.COUNT); END; /
SQL> CREATE OR REPLACE FUNCTION plch_dr_seuss_names ( 2 name1_in IN VARCHAR2 3 , name2_in IN VARCHAR2 4 , name3_in IN VARCHAR2) 5 RETURN plch_pkg.names_t 6 IS 7 l_return plch_pkg.names_t; 8 BEGIN 9 l_return (1) := name1_in; 10 l_return (2) := name2_in; 11 l_return (3) := name3_in; 12 RETURN l_return; 13 END plch_dr_seuss_names; 14 / Function created SQL> DECLARE 2 l_names CONSTANT plch_pkg.names_t 3 := plch_dr_seuss_names ('Horton', 'Hears', 'A Who') ; 4 BEGIN 5 DBMS_OUTPUT.put_line (l_names.COUNT); 6 END; 7 / 3 PL/SQL procedure successfully completed SQL>
答案CD. ORACLE只對嵌套表(NESTED TABLE)和可變數(shù)組(VARRAY)提供構(gòu)造函數(shù)(constructor function), ASSOCIATED ARRAY (即INDEX BY表)則沒有這個構(gòu)造函數(shù),必須采用自定義函數(shù)。常量在聲明的部分必須賦值,不能夠在塊中賦值。
到此,關于“怎么使用CONSTANT變量與INDEX BY數(shù)組”的學習就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續(xù)學習更多相關知識,請繼續(xù)關注億速云網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。