实现目的是数据进行区间划分(<_0_>)
#Code:
library(DBI)
library(ROracle)
drv=dbDriver('Oracle')
conn=dbConnect(drv,'test','test','192.100.10.10:1521/ZNJT')
# get the flux of the current time (hour)
rs=dbSendQuery(conn,"select * from dw_fact_flux where gcsj=to_char(sysdate,'yyyymmdd')-30000+900+8
and sd=to_char(sysdate,'hh24')")
data=fetch(rs)
data=as.matrix(data)
#get the count,mean,min,max,threshold,rank
rownum=nrow(data)
minval=min( as.numeric(data[,12]))
meanval= mean(as.numeric(data[,12]))
maxval=max( as.numeric(data[,12]))
threshold1=(minval+meanval)/2
threshold2=meanval
threshold3=(meanval+maxval)/2
# According to the scope of grouping
rankval=cut(as.numeric(data[,12]),c(minval-1,threshold1,meanval,threshold3,maxval),labels = c("1","2","3","4"))
datae=as.data.frame(cbind(data,rankval))
dbWriteTable(conn,'DW_ACD_HDZT',datae, row.names = F, append = TRUE)
dbDisconnect(conn)
注意:1、datae=as.data.frame(cbind(data,rankval)) 如何换成datae=as.data.frame(cbind(data,RANKVAL))则会出现顺序混乱
2、表名要使用大写,datae转换as.data.frame