Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use CONSTANT variables and INDEX BY arrays

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to use CONSTANT variables and INDEX BY arrays". In daily operations, I believe many people have doubts about how to use CONSTANT variables and INDEX BY arrays. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "how to use CONSTANT variables and INDEX BY arrays". Next, please follow the editor to study!

I created the following header:

CREATE OR REPLACE PACKAGE plch_pkg AUTHID DEFINERIS TYPE names_t IS TABLE OF VARCHAR2 (20) INDEX BY PLS_INTEGER;END plch_pkg;/

Which options display "3" after execution?

(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: line 3, column 10: PLS-00222: there is no function named 'NAMES_T'' in this range ORA-06550: line 2, column 14: PL/SQL: Item ignoredORA-06550: line 5, column 26: PLS-00320: the type declaration of this expression is incomplete or incorrect ORA-06550: line 5, column 4: PL/SQL: Statement ignoredSQL >

(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: line 3, column 29: PLS-00222: there is no function named 'NAMES_T'' in this range ORA-06550: line 2, column 14: PL/SQL: Item ignoredORA-06550: line 5, column 4: PLS-00320: the type declaration of this expression is incomplete or incorrect ORA-06550: line 5, column 4: PL/SQL: Statement ignoredORA-06550: line 6 Column 4: PLS-00320: the type declaration of this expression is incomplete or incorrect ORA-06550: line 6, column 4: PL/SQL: Statement ignoredORA-06550: line 7, column 4: PLS-00320: the type declaration of this expression is incomplete or incorrect ORA-06550: line 7, column 4: PL/SQL: Statement ignoredORA-06550: line 8 Column 26: PLS-00320: the type declaration of this expression is incomplete or malformed ORA-06550: line 8, column 4: PL/SQL: Statement ignoredSQL >

(C)

CREATE OR REPLACE FUNCTION plch_dr_seuss_names RETURN plch_pkg.names_tIS l_return plch_pkg.names_t;BEGIN l_return (1): = 'Horton'; l_return (2): =' Hears'; l_return (3): ='A Who'; RETURN lumbago 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 createdSQL > 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 / 3PL/SQL procedure successfully completedSQL >

(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_tIS l_return plch_pkg.names_t;BEGIN l_return (1): = name1_in; l_return (2): = name2_in; l_return (3): = name3_in; 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 lumbago, 13 END plch_dr_seuss_names; 14 / Function createdSQL > 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 / 3PL/SQL procedure successfully completedSQL > answer CD. ORACLE only provides a constructor (constructor function) for nested tables (NESTED TABLE) and variable arrays (VARRAY). ASSOCIATED ARRAY (that is, the INDEX BY table) does not have this constructor and must use a custom function. Constants must be assigned in the declared part, not in the block. At this point, the study on "how to use CONSTANT variables and INDEX BY arrays" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report