--유틸함수---
// Resultset >> Vector
public static void fillVector(Vector vector, ResultSet rs) throws Exception {
while (rs.next()) {
Parameters params = new Parameters();
ResultSetMetaData rsmd = rs.getMetaData();
for (int i = 0; i < rsmd.getColumnCount(); i++) {
params.setParameter(rsmd.getColumnName(i + 1).toLowerCase(),
rs.getObject(rsmd.getColumnName(i + 1)));
}
vector.addElement(params);
}
}
-------사용하는 방법------------
public Vector getSubOrg(String org_cd) throws Exception {
Vector vector = new Vector();
String sql = "";
try{
sql = " EXEC sp_sub_org ? ";
logger.debug("sql:" + sql);
// 스테이트먼트 객체에 쿼리를 설정
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, org_cd);
rs = pstmt.executeQuery();
Convert.fillVector(vector, rs);
} catch(Exception e){
e.printStackTrace();
throw e;
} finally{
if(pstmt != null){
try{
logger.info("close DB");
rs.close();
pstmt.close();
pstmt = null;
} catch(Exception e1){}
}
}
return vector;
}//select_org
----------------프로시져-----------------
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
/***********************************************************
************************************************************/
ALTER PROCEDURE [dbo].[sp_sub_org]
@ORG_CD NVARCHAR(20) /* 조직코드 */
AS
DECLARE @XLEVEL AS INT
DECLARE @XPATH AS NVARCHAR(500)
IF EXISTS (SELECT * FROM SYSOBJECTS WHERE XTYPE = 'u' AND NAME LIKE '%#MAKE_TREE_TEMP%')
DROP TABLE #MAKE_TREE_TEMP
CREATE TABLE #MAKE_TREE_TEMP
(
CHILD_YN VARCHAR(1),
ORG_LEVEL NVARCHAR(20),
ORG_NAME NVARCHAR(100),
ORG_CD NVARCHAR(20),
UP_ORG_CD NVARCHAR(20),
XLEVEL INT,
XPATH NVARCHAR(500)
)
SET @XLEVEL = 0
SET @XPATH = '.'
IF @ORG_CD IS NULL OR @ORG_CD = ''
SET @ORG_CD = ( SELECT MIN(ORG_CD) FROM VW_ORG
WHERE 1=1
--@YEAR BETWEEN LEFT(ORG_START_YMD, 4) AND LEFT(ORG_END_YMD, 4)
)
INSERT INTO #MAKE_TREE_TEMP
SELECT
CHILD_YN,
ORG_LEVEL,
ORG_NAME,
ORG_CD,
UP_ORG_CD,
@XLEVEL,
'.' + CAST(ORG_CD AS NVARCHAR(100)) + '.'
FROM VW_ORG WHERE ORG_CD = @ORG_CD
--AND @YEAR BETWEEN LEFT(ORG_START_YMD, 4) AND LEFT(ORG_END_YMD, 4)
WHILE @@ROWCOUNT > 0
BEGIN
SET @XLEVEL = @XLEVEL + 1
INSERT INTO #MAKE_TREE_TEMP
SELECT
A.CHILD_YN,
A.ORG_LEVEL,
A.ORG_NAME,
A.ORG_CD,
A.UP_ORG_CD,
@XLEVEL,
B.XPATH + CAST (A.ORG_CD AS NVARCHAR(20)) + '.'
FROM
(SELECT * FROM VW_ORG
WHERE ORG_CD <> UP_ORG_CD
AND USE_YN = 'Y'
--AND @YEAR BETWEEN LEFT(ORG_START_YMD, 4) AND LEFT(ORG_END_YMD, 4)
) AS A
JOIN #MAKE_TREE_TEMP AS B
ON
A.UP_ORG_CD = B.ORG_CD AND B.XLEVEL = @XLEVEL - 1
--PRINT CAST(@XLEVEL AS NVARCHAR(10)) + '<<<<<<'
END
select child_yn, org_level, org_name,
replicate('->', xlevel) + org_name as org_name_path,
xlevel, xpath, org_cd, up_org_cd
from #make_tree_temp
order by xpath
SET ANSI_NULLS OFF
// Resultset >> Vector
public static void fillVector(Vector vector, ResultSet rs) throws Exception {
while (rs.next()) {
Parameters params = new Parameters();
ResultSetMetaData rsmd = rs.getMetaData();
for (int i = 0; i < rsmd.getColumnCount(); i++) {
params.setParameter(rsmd.getColumnName(i + 1).toLowerCase(),
rs.getObject(rsmd.getColumnName(i + 1)));
}
vector.addElement(params);
}
}
-------사용하는 방법------------
public Vector getSubOrg(String org_cd) throws Exception {
Vector vector = new Vector();
String sql = "";
try{
sql = " EXEC sp_sub_org ? ";
logger.debug("sql:" + sql);
// 스테이트먼트 객체에 쿼리를 설정
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, org_cd);
rs = pstmt.executeQuery();
Convert.fillVector(vector, rs);
} catch(Exception e){
e.printStackTrace();
throw e;
} finally{
if(pstmt != null){
try{
logger.info("close DB");
rs.close();
pstmt.close();
pstmt = null;
} catch(Exception e1){}
}
}
return vector;
}//select_org
----------------프로시져-----------------
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
/***********************************************************
************************************************************/
ALTER PROCEDURE [dbo].[sp_sub_org]
@ORG_CD NVARCHAR(20) /* 조직코드 */
AS
DECLARE @XLEVEL AS INT
DECLARE @XPATH AS NVARCHAR(500)
IF EXISTS (SELECT * FROM SYSOBJECTS WHERE XTYPE = 'u' AND NAME LIKE '%#MAKE_TREE_TEMP%')
DROP TABLE #MAKE_TREE_TEMP
CREATE TABLE #MAKE_TREE_TEMP
(
CHILD_YN VARCHAR(1),
ORG_LEVEL NVARCHAR(20),
ORG_NAME NVARCHAR(100),
ORG_CD NVARCHAR(20),
UP_ORG_CD NVARCHAR(20),
XLEVEL INT,
XPATH NVARCHAR(500)
)
SET @XLEVEL = 0
SET @XPATH = '.'
IF @ORG_CD IS NULL OR @ORG_CD = ''
SET @ORG_CD = ( SELECT MIN(ORG_CD) FROM VW_ORG
WHERE 1=1
--@YEAR BETWEEN LEFT(ORG_START_YMD, 4) AND LEFT(ORG_END_YMD, 4)
)
INSERT INTO #MAKE_TREE_TEMP
SELECT
CHILD_YN,
ORG_LEVEL,
ORG_NAME,
ORG_CD,
UP_ORG_CD,
@XLEVEL,
'.' + CAST(ORG_CD AS NVARCHAR(100)) + '.'
FROM VW_ORG WHERE ORG_CD = @ORG_CD
--AND @YEAR BETWEEN LEFT(ORG_START_YMD, 4) AND LEFT(ORG_END_YMD, 4)
WHILE @@ROWCOUNT > 0
BEGIN
SET @XLEVEL = @XLEVEL + 1
INSERT INTO #MAKE_TREE_TEMP
SELECT
A.CHILD_YN,
A.ORG_LEVEL,
A.ORG_NAME,
A.ORG_CD,
A.UP_ORG_CD,
@XLEVEL,
B.XPATH + CAST (A.ORG_CD AS NVARCHAR(20)) + '.'
FROM
(SELECT * FROM VW_ORG
WHERE ORG_CD <> UP_ORG_CD
AND USE_YN = 'Y'
--AND @YEAR BETWEEN LEFT(ORG_START_YMD, 4) AND LEFT(ORG_END_YMD, 4)
) AS A
JOIN #MAKE_TREE_TEMP AS B
ON
A.UP_ORG_CD = B.ORG_CD AND B.XLEVEL = @XLEVEL - 1
--PRINT CAST(@XLEVEL AS NVARCHAR(10)) + '<<<<<<'
END
select child_yn, org_level, org_name,
replicate('->', xlevel) + org_name as org_name_path,
xlevel, xpath, org_cd, up_org_cd
from #make_tree_temp
order by xpath
SET ANSI_NULLS OFF
댓글 0
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
126 | test''' ' '' '' ''''""" '''''''' | 구퍼 | 2011.03.07 | 4495 |
125 | 테이블 열항목을 행항목으로 변경하는 팁 | 구퍼 | 2011.01.11 | 8840 |
124 | 오라클 DB 링크 만들기 | 구퍼 | 2011.01.06 | 6829 |
123 | select -> update 구문 샘플 | 구퍼 | 2010.01.21 | 5945 |
122 | Instant Client 사용법 | 구퍼 | 2009.12.30 | 6056 |
121 | row데이터 연결하여 조회 | 구퍼 | 2009.03.31 | 3889 |
120 | 데이타에 한글로 공백이 있는 경우 값을 가져오지 못하고 오류가 발생하는 경우 처리 | 구퍼 | 2009.03.23 | 5883 |
119 | mssql update예제(select ~ update) | 구퍼 | 2008.10.31 | 6319 |
118 | Update ~ Select 구문 예제 | 구퍼 | 2008.10.31 | 4701 |
117 | oracle 10g tnsnames.ora, listener.ora위치 | 구퍼 | 2008.09.29 | 4405 |
116 | Conditions | 구퍼 | 2008.09.17 | 5844 |
115 | Basic Delete Statements | 구퍼 | 2008.09.17 | 4674 |
114 | Basic Update Statements | 구퍼 | 2008.09.17 | 4665 |
113 | 문자열 연결, 날짜 변환, 오늘 구하기 | 구퍼 | 2008.09.10 | 4433 |
112 | 현재의 년월일시분초 구하기 | 구퍼 | 2008.09.10 | 5766 |
111 | Unix, Oracle, Pro*C작성 입찰공고 | 운영자 | 2003.06.05 | 4459 |
110 | Unix, Oracle, Pro*C작성 구인구직게시판 | 운영자 | 2003.06.05 | 4887 |
109 | Unix, Oracle, Pro*C작성 자유게시판 | 운영자 | 2003.06.05 | 4751 |
108 | 분산트랜젝션 가능여부 확인 방법 | 하늘과컴 | 2008.05.29 | 5126 |
» | 순환구조에서 임시테이블에 하위 조직을 엮어서 넣는 프로시져 | 하늘과컴 | 2007.10.01 | 5311 |