inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

묻고 답해요

173만명의 커뮤니티!! 함께 토론해봐요.

Oracle 11g에서의 association 활용

해결됨

Oracle PL/SQL 딱 이만큼.. [개념+실전]

Collections 1. 개념 (Associative , Varrays , Nested Tables ) 강의의 17분쯤에 association으로 활용을 해주십니다. 근데 Oracle 11g에서는 패키지 헤더(Specification인데 편하게 헤더라고 할게요)에서 association을 값을 주며 초기화할 수 없습니다. 그래서 GPT에게 물어보며 얻어낸 결과물을 공유드립니다. 프로시저와 펑션을 활용했습니다. 패키지 헤더 create or replace PACKAGE PKG_COMMON AS ... /* Associative array */ type Capital is table of varchar2(50) -- Associative array type index by varchar2(50); -- char type indexed by string -- index by pls_integer; -- only number type key PROCEDURE set_city_capital(cities Capital); FUNCTION get_city_capital RETURN Capital; END PKG_COMMON; 패키지 바디 getter, setter 개념을 프로시저와 펑션에 접목했습니다. create or replace PACKAGE BODY PKG_COMMON AS city_capital Capital; PROCEDURE set_city_capital(cities Capital) IS BEGIN city_capital := cities; END set_city_capital; FUNCTION get_city_capital RETURN Capital IS BEGIN RETURN city_capital; END get_city_capital; END PKG_COMMON; 호출 블럭 DECLARE temp_city_capital PKG_COMMON.Capital; v_index varchar2(50); -- Scalar variable BEGIN temp_city_capital('한국') := '서울'; temp_city_capital('프랑스') := '파리'; temp_city_capital('영국') := '런던'; PKG_COMMON.set_city_capital(temp_city_capital); -- print associative array: v_index := temp_city_capital.first; -- get first element of array while v_index is not null loop dbms_output.put_line('population of ' || v_index || ' is ' || temp_city_capital(v_index)); v_index := temp_city_capital.next(v_index); -- get next element of array end loop; END; 이렇게 하면 /* population of 영국 is 런던 population of 프랑스 is 파리 population of 한국 is 서울 */ 결과가 잘 나오는 것을 확인할 수 있습니다. 다만, 강사님의 의도와 다르지 않을까 싶기도 하네요. 어쨋든 11g에서도 활용할 수 있어 다행입니다 ㅎㅎ

  • oracle
  • PL/SQL
Bruce Han 댓글 1 좋아요 1 조회수 198

인기 태그

인프런 TOP Writers

주간 인기글