database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
PostgreSQL
Firebird
Oracle
Informix
Sybase
MS-SQL
ㆍDB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
DB2 Q&A 1528 게시물 읽기
No. 1528
오라클에 있는 varray형
작성자
이도희
작성일
2008-02-20 15:10ⓒ
2008-02-20 15:33ⓜ
조회수
10,607

오라클의 varray형과 같은 것이 DB2에도 있나요??


알려주시면 대단히 감사드리겠습니다.

이 글에 대한 댓글이 총 1건 있습니다.


V9.5부터는 관련 함수를 지원하네요.  

Global session variable support

DB2 Viper 2 extends SQL with a new data object called global session variable. Global session variables have a schema qualified, persistent definitions in the catalog, but their content is private to any given session. Global session variables facilitate porting of package variables when mapping a package to a DB2 schema


아래참조해보세요.

http://www.ibm.com/developerworks/db2/library/techarticle/dm-0707rielau/


이전 버전이면 temporary table을 사용해보세요.


-------------------------
Nested tables and varrays

To understand how nested tables and varrays can be converted to DB2, first let
us address the difference between Oracle nested tables and varrays.
Items of type TABLE are called nested tables. Within the database, they can be
viewed as one-column database tables. Oracle stores the rows of a nested table
in no particular order. But, when you retrieve the nested table into a PL/SQL
variable, the rows are given consecutive subscripts starting at 1. Nested table
has no upper bound, while the size of variable arrays is fixed. The second
important difference, the variable arrays must be dense (have consecutive
subscripts). So, you cannot delete individual elements from an array. Initially,
nested tables are dense, but they can be sparse (have nonconsecutive
subscripts).
As DB2 does not support collections, the most generic way to convert a nested
table is by using DB2 Global Declared Temporary Table (DGTT), where first
column stores the value of the subscript, and the second column stores the value
of Oracle nested table.
Let us clarify this with an example (Example 5-15) that filling nested table
EmpList with names of the Employees for the given department from table
emp_table.

Note: DB2 temporary tables are not similar to Oracle temporary tables. DB2
temporary tables are memory bound (provided sufficient memory is available),
visible only to the connection that declares it, and exist only for as long as a
connection is maintained (or dropped). If you disconnect, the table is
automatically cleaned up.

Tip: To use DGTTs, you must create a user temporary table space (none
exists by default). In the simplest case, you can use:
create user temporary tablespace usertemp1 managed by system using
('usertemp1')
The size of the buffer pool associated with this tablespace will affect how
memory-bound DGTTs are at runtime.

Example 5-15 Oracle code using nested table
DECLARE
TYPE EmpList IS TABLE OF emp_table.ename%TYPE ;
CURSOR c1 IS
SELECT emp_name
FROM emp_table
WHERE dept = v_dept;
EmpName emp_table.ename%TYPE;
empNum NUMBER;
BEGIN
LOOP
FETCH c1 INTO EmpName;
WHEN c1%NOTFOUND EXIT;
empNum := empNum + 1;
EmpList(empNum):= EmpName;
END LOOP;
CLOSE c1;
END;

The same can be implemented in DB2 using DGTT as shown in Example 5-16.

Example 5-16 DB2 UDB code using DGTT
DECLARE SQLCODE INT DEFAULT 0;
DECLARE v_empname varchar(30);
DECLARE v_num INT DEFAULT 0;
DECLARE c1 CURSOR FOR
SELECT emp_name
FROM emp_table
WHERE dept = v_dept;
DECLARE GLOBAL TEMPORARY TABLE SESSION.temp_emp_list
(num integer, EmpName varchar(30))
WITH REPLACE
ON COMMIT PRESERVE ROWS
NOT LOGGED;
OPEN c1;
WHILE (SQLCODE = 0) DO
FETCH c1 INTO v_empname;
SET v_num = v_num +1;
INSERT INTO SESSION.temp_emp_list
VALUES (v_num,v_empname);
END WHILE;
CLOSE c1;

Or better yet, the code is more efficient if converted as follows (Example 5-17).

Example 5-17 Efficient DB2 UDB code using DGTT
DECLARE GLOBAL TEMPORARY TABLE SESSION.temp_emp_list
(num integer,EmpName varchar(30))
WITH REPLACE
ON COMMIT PRESERVE ROWS
NOT LOGGED;
INSERT INTO session.temp_emp_list
SELECT row_number() over(), emp_name
FROM emp_table
WHERE dept = v_dept;

To convert Oracle varrays, you can also use DGTT, or sometimes the redesign
can help achieve the

벽타는 냥이님이 2008-02-20 16:36에 작성한 댓글입니다.
이 댓글은 2008-02-21 11:06에 마지막으로 수정되었습니다. Edit
[Top]
No.
제목
작성자
작성일
조회
1531db2 쿼리로 누계내기 [1]
지창용
2008-02-25
9275
1530다른 데이타베이스에 테이블 조회 [1]
조댕이
2008-02-22
9217
1529데이타에 엔터문자가 있을때 제거하는 방법..? [1]
궁금
2008-02-20
11817
1528오라클에 있는 varray형 [1]
이도희
2008-02-20
10607
1527테이블스페이스관련 [1]
초짜
2008-02-19
9352
1526DB2 관련 질문 [1]
초짜
2008-02-19
9102
1524DB2 기본에 관한 블로그 소개
이찬우
2008-02-18
9058
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.024초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다