반응형
PL/SQL 함수에서 패스 배열을 사용하는 방법
저는 Oracle PL/SQL에 대한 지식이 부족한 Java 개발자입니다. 아래 예제에서 PL/SQL 함수에 배열을 전달하는 방법과 호출 방법을 알려주시기 바랍니다.
CREATE OR REPLACE FUNCTION get_employees (pUserId NUMBER)
RETURN VARCHAR2
IS
l_text VARCHAR2(32767) := NULL;
BEGIN
FOR cur_rec IN (SELECT grp.NAME GROUP_NAME FROM UserGroupRole ugr, Group_ grp WHERE ugr.groupid=grp.groupid and USERID = pUserId) LOOP
l_text := l_text || ',' || cur_rec.GROUP_NAME;
END LOOP;
RETURN LTRIM(l_text, ',');
END;
/
SELECT get_employees(414091) FROM DUAL;
수집 유형을 만들고 매개 변수를 해당 유형의 인스턴스로 전달할 수 있습니다.
SQL> create type num_array as table of number;
2 /
Type created.
SQL> create or replace function myfun ( arr_in num_array ) return varchar2 is
2 txt varchar2(1000);
3 begin
4 for i in 1..arr_in.count loop
5 txt := txt || to_char( arr_in(i) ) || ',';
6 end loop;
7 return txt;
8 end;
9 /
Function created.
SQL> declare
2 myarray num_array;
3 mytext varchar2(1000);
4 begin
5 myarray := num_array();
6 myarray.extend(3);
7 myarray(1) := 1;
8 myarray(2) := 5;
9 myarray(3) := 9;
10 dbms_output.put_line( myfun( myarray ));
11 end;
12 /
1,5,9,
PL/SQL procedure successfully completed.
언급URL : https://stackoverflow.com/questions/6338721/how-to-use-pass-an-array-in-pl-sql-function
반응형
'sourcecode' 카테고리의 다른 글
오픈레이어스 vs 구글맵? (0) | 2023.10.11 |
---|---|
오라클 데이터베이스가 서블릿에 요청을 보낼 수 있습니까? (0) | 2023.10.11 |
헤더 없이 SSRS에서 Excel로 내보내기 (0) | 2023.10.11 |
PowerShell 변수를 명령 매개 변수로 사용하는 방법은 무엇입니까? (0) | 2023.10.11 |
SQL 오류: ORA-02291: 무결성 제약 조건 (0) | 2023.10.11 |