1、增加字段脚本
添加单个字段
Alter table tableName add column columnName decimal(12,3) ;
//添加多个字段
Alter table tableName add column (
A string COMMENT 'A',
B decimal(16, 6) COMMENT 'B',
C decimal(16, 6) COMMENT 'C',
D decimal(16, 6) COMMENT 'D',
F decimal(16, 6) COMMENT 'F ');
2、修改字段类型
//字段A类型修改成长度16位,6小数数值类型
Alter table tableName change column A A decimal(16,6) ;
3、时间函数
unix_timestamp() : 返回单位:秒
4、输入格式函数
select from_unixtime(1534839814);
5、其他日期函数
select from_unixtime(unix_timestamp(),'yyyy-MM-dd') today -- 今天
select trunc(from_unixtime(unix_timestamp(),'yyyy-MM-dd') ,'MM') firstday -- 当月第一天
select last_day(from_unixtime(unix_timestamp(),'yyyy-MM-dd')) lastday -- 当月最后一天
select add_months(trunc(from_unixtime(unix_timestamp(),'yyyy-MM-dd') ,'MM') ,1) next_month_firstday --下个月第一天
6、任务中时间
# 任务中使用 变量
substr($(new("org.joda.time.DateTime", ${schedule.exec.time}).withMillisOfDay(0).plusMonths(-1).dayOfMonth().withMinimumValue().getMillis()),1,10)
# 当前月第一天0点0分0秒
substr($(new("org.joda.time.DateTime", ${schedule.exec.time}).withMillisOfDay(0).dayOfMonth().withMinimumValue().getMillis()),1,10)
# schedule.exec.time
定义:计划执行时间的unix时间戳
数据格式demo: 1534839814392 (单位:毫秒)
# 备注:下述 substr 获取到的是 秒,索引位从1开始
# 最后 endTime 等是 1970到现在的秒
# 当前月第一天0点0分0秒
curMonFirstDay substr($(new("org.joda.time.DateTime", ${schedule.exec.time}).withMillisOfDay(0).dayOfMonth().withMinimumValue().getMillis()),1,10)
# 当前月最后一天0点0分0秒
curMonLastDay substr($(new("org.joda.time.DateTime", ${schedule.exec.time}).withMillisOfDay(0).dayOfMonth().withMaximumValue().getMillis()),1,10)
# 上个月第一天0点0分0秒
preMonFirstDay substr($(new("org.joda.time.DateTime", ${schedule.exec.time}).withMillisOfDay(0).plusMonths(-1).dayOfMonth().withMinimumValue().getMillis()),1,10)
# 上个月最后一天0点0分0秒
preMonLastDay substr($(new("org.joda.time.DateTime", ${schedule.exec.time}).withMillisOfDay(0).plusMonths(-1).dayOfMonth().withMaximumValue().getMillis()),1,10)
# 下个月第一天0点0分0秒
nextMonFirstDay substr($(new("org.joda.time.DateTime", ${schedule.exec.time}).withMillisOfDay(0).plusMonths(1).dayOfMonth().withMinimumValue().getMillis()),1,10)
# 下个月最后一天0点0分0秒
nextMonLastDay substr($(new("org.joda.time.DateTime", ${schedule.exec.time}).withMillisOfDay(0).plusMonths(1).dayOfMonth().withMaximumValue().getMillis()),1,10)
# 当前时间:距离1970的秒数
endTime substr($(new("org.joda.time.DateTime", ${schedule.exec.time}).getMillis()),1,10)
# 当前时间:距离1970的秒数:往前推2分钟
endTime_before2min substr($(new("org.joda.time.DateTime", ${schedule.exec.time}).minusMinutes(2).getMillis()),1,10)
# 当前时间:距离1970的秒数:往前推10分钟
endTime_before10min substr($(new("org.joda.time.DateTime", ${schedule.exec.time}).minusMinutes(10).getMillis()),1,10)
# 当前时间:距离1970的秒数:往前推1小时
endTime_before1hour substr($(new("org.joda.time.DateTime", ${schedule.exec.time}).minusHours(1).getMillis()),1,10)
# 当前时间:距离1970的秒数:往前推5天
endTime_before5day substr($(new("org.joda.time.DateTime", ${schedule.exec.time}).minusDays(120).getMillis()),1,10)