안녕하세요.
sybase 입문자입니다.
질문하나만 드리겠습니다.
반복쿼리 방법이 궁금한데요(사실 제가 원하는게 반복쿼리로 불러도 되는지는 모르겠습니다).
예를들어, 데이터베이스에 5년치의 특정 자료가 있습니다.
여기서 동일조건으로 한달치씩 자료를 추출하려고 하는데요.
매크로문 처럼 반복해서 한달씩 자동적으로 추출하게 할수는 없나요?
읽어주셔서 감사합니다~^^;
질문 내용을 간략하게 답변드리면...
1. 한달 짜리 추출 쿼리를 만듬.
2. 기간에 대해 bind 변수를 사용.
3. 자동 추출? cron에 등록하거나 SYBASEjob-scheduler에 등록해서 자동화.
==============================================================
1. select * from TBL where DTCOL >= "2014-01-01" and DTCOL <"2014-02-01"
2.declare @startday date
select @startday = "2014-01-01"
select * from TBL where DTCOL >=@startday and DTCOL <dateadd(mm,1,@startday)
[대안:프로시져생성.]
create proc onemonth_proc
@startday date
as
begin
select * from TBL where DTCOL >@startday and DTCOL < dateadd(mm,1,@startday)
end
3.cron 등록할 스크립트 생성
#several month
## ranges 변수에 대한 자동 생성 부분은 직접 만들어야 할 듯....
ranges="2013-01-01 2013-02-01 2014-03-01 .......2013-12-01"
for workday in ranges
do
isql -Uuser -Ppassword -w1000 >output.txt
exec onemonth_proc "${workday}"
go
EOF
done
### end of sh script ###
crontab 등록..