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
운영게시판
최근게시물
Sybase Q&A 1118 게시물 읽기
No. 1118
cursor ....error
작성자
궁금이
작성일
2005-03-23 13:37
조회수
4,809

declare cur4 cursor for
select account_code
from acode
where account_code between @from_acct and @to_acct
and input_gbn = 'Y'
for read only
at isolation read uncommitted

select @yyyymm = max(yyyymm) from monthly_item_amt
where area_code in (select area_code from saso_code where up_area = @area_code)
and sum_gbn = '1'
and yyyymm<substring(@from_yymm,1,6)

select @acct_date = convert(datetime,substring(@yyyymm,1,4)+'/'+substring(@yyyymm,5,2) + '/01')

open cur4
fetch cur1 into @acct_code
while @@sqlstatus!=2 begin
select @acct_name=account_name, @first_acct_code=first_account_code,
@acode_dc_code=dc_code
from acode
where account_code=@acct_code
at isolation read uncommitted

select @first_acct_name=account_name from acode
where account_code=@first_acct_code
at isolation read uncommitted

select @option_gbn=option_gbn from acode_mgt
where account_code=@acct_code and mgt_code='101'
at isolation read uncommitted

if @option_gbn = 'A'
declare cur2 cursor for
select mgt_item_code1, won_by_dr_amt+won_cy_dr_amt, won_by_cr_amt+won_cy_cr_amt
from monthly_item_amt
where area_code in (select area_code from saso_code where up_area=@area_code)
and account_code=@acct_code and sum_gbn='1'
and substring(mgt_item_code1,1,4) between substring(@from_cust,1,4) and substring(@to_cust,1,4)
and yyyymm = @yyyymm
for read only
at isolation read uncommitted
if @option_gbn = 'B'
declare cur2 cursor for
select mgt_item_code2, won_by_dr_amt+won_cy_dr_amt, won_by_cr_amt+won_cy_cr_amt
from monthly_item_amt
where area_code in (select area_code from saso_code where up_area=@area_code)
and account_code=@acct_code and sum_gbn='1'
and substring(mgt_item_code2,1,4) between substring(@from_cust,1,4) and substring(@to_cust,1,4)
and yyyymm = @yyyymm
for read only
at isolation read uncommitted
if @option_gbn = 'C'
declare cur2 cursor for
select mgt_item_code3, won_by_dr_amt+won_cy_dr_amt, won_by_cr_amt+won_cy_cr_amt
from monthly_item_amt
where area_code in (select area_code from saso_code where up_area=@area_code)
and account_code=@acct_code and sum_gbn='1'
and substring(mgt_item_code3,1,4) between substring(@from_cust,1,4) and substring(@to_cust,1,4)
and yyyymm = @yyyymm
for read only
at isolation read uncommitted
open cur2
fetch cur2 into @cust_code, @debit_amt, @credit_amt
while @@sqlstatus!=2 begin
select @cust_code =max(custom_code)
from acustom
where substring(custom_code,1,4) = substring(@cust_code,1,4)

select @cust_name=custom_fname from acustom
where custom_code= @cust_code
at isolation read uncommitted
if @acode_dc_code = '1' begin
select @debit_amt = @debit_amt - @credit_amt
select @credit_amt = 0
select @remain_amt = @debit_amt - @credit_amt
end else begin
select @credit_amt = @credit_amt - @debit_amt
select @debit_amt = 0
select @remain_amt = @credit_amt - @debit_amt
end

if exists ( select * from #temp_cust_bojo
where slip_no = @jun
and acct_code = @acct_code
and substring(cust_code,1,4) = substring(@cust_code,1,4))
update #temp_cust_bojo
set debit_amt = debit_amt + @debit_amt,
credit_amt = credit_amt + @credit_amt,
remain_amt = remain_amt + @remain_amt
where slip_no = @jun
and acct_code = @acct_code
and substring(cust_code,1,4) = substring(@cust_code,1,4)
else
insert into #temp_cust_bojo(slip_no, acct_code,
acct_name, first_acct_code, first_acct_name,
acct_date, cust_code, cust_name,
dc_code, debit_amt, credit_amt, remain_amt, status)
values(@jun, @acct_code,
@acct_name, @first_acct_code, @first_acct_name,
@acct_date, @cust_code, @cust_name,
@acode_dc_code, @debit_amt, @credit_amt, @remain_amt, 'C')
fetch cur2 into @cust_code, @debit_amt, @credit_amt
end
close cur2
deallocate cursor cur2
fetch cur4 into @acct_code
end
close cur4
deallocate cursor cur4

 

-cur2를 open할 수 없다고 나오는군요

고수님들 댓글 감사합니다...

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

참 환경은

dbms: ase12.5.0.3

os: win2000 server 이고

위 프로시져를 요약하자면..

 

declare cur1 cursor for

select .......

for read only
at isolation read uncommitted

opne cur1

fetch cur1 into @aaa

while @@sqlstatus!=2 begin

     if @aaa = 'A'

         declare cur2 cursor for

         select .......

         at isolation read uncommitted

     if @aaa = 'B'

         declare cur2 cursor for

         select .......

         at isolation read uncommitted

     if @aaa = 'C'

         declare cur2 cursor for

         select .......

         at isolation read uncommitted

     opne cur2

     fetch cus2 into @bbb

     while @@sqlstatus!=2 begin

     .

     .

     .

     fetch cur2 into @bbb

     end

     deallocate cursor cur2

fetch cur1 into @aaa

end

close cur1
deallocate cursor cur1

궁금이님이 2005-03-23 13:50에 작성한 댓글입니다.
이 댓글은 2005-03-23 14:07에 마지막으로 수정되었습니다. Edit

if 문 뒤에 있는 cursor 명을 다르게 주어 보세요..

 

if @aaa = 'A'

 declare cur21

 

if @aaa = 'B'

 declare cur22

 

if @aaa = 'C'

 declare cur23

 

의 형태로 해보시고요..

 

실제로 cursor 내에서 중첩으로 cursor 를 쓰시면,  Perfomance 에 이상이 있을 수 있어.. 권장하지 않는 방법입니다..

 

cursor 내에 cursor 의 경우 대부분 join 에 의해 해결이 되며 이쪽으로 고려해 보심이 좋을거 같습니다..

coolrock님이 2005-03-25 09:46에 작성한 댓글입니다. Edit

네..감사합니다..조인을 해보지요..

궁금이님이 2005-03-26 14:25에 작성한 댓글입니다. Edit
[Top]
No.
제목
작성자
작성일
조회
1121ASA 9.0도 커서 지원하나요? [1]
왕초보
2005-03-26
4118
1120errorlog 좀 봐주십시오 [1]
에러난
2005-03-26
4034
1119칼럼을 추가하고싶어요 [3]
왕초보
2005-03-24
4514
1118cursor ....error [3]
궁금이
2005-03-23
4809
1117sam 파일 읽어서 저장하기.. [2]
강명성
2005-03-22
4091
1116다른 디스크에 있는 디비 전체복구 [2]
굿타임
2005-03-22
3842
1115convert 도와주세요 [2]
이상허네
2005-03-21
5280
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.018초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다