# !/usr/bin/env python
# -*- coding: utf-8 -*-
import MySQLdb
from datetime import datetime
import cx_Oracle
import os
import sys
import re
import time
reload(sys)
sys.setdefaultencoding('utf-8')
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'
import datetime # 导入日期时间模块
# if len(sys.argv) != 4:
# print sys.argv[0] + ' ' + 'table_name' + ' ' + 'start_date' + ' ' + 'stop_date'
# else:
# table_name = sys.argv[1]
# start_date = sys.argv[2]
# stop_date = sys.argv[3]
table_name = 'T_PM_ACCT_DTL_AF'
start_date = '20180101'
stop_date = '20181231'
print table_name
print start_date
print stop_date
conn = cx_Oracle.connect('tlcbuser/tlcbuser@1.1.1.1/tlyy')
tips = '+1'
def get_date(v_date):
cur = conn.cursor()
msql = "select to_char((to_date(%s,'YYYYMMDD')%s),'YYYY-MM-DD') from dual where rownum=1" % (v_date, tips)
# print msql
cur.execute(msql)
row = cur.fetchone()
# print row
return row[0]
print '-----------------'
sdate = start_date
stop_date = get_date(stop_date)
stop_date = stop_date.replace('-', '')
while True:
xdate = get_date(sdate)
ydate = xdate.replace('-', '')
print xdate
print ydate
ndate = xdate
psql = "alter table %s add partition %s_%s values less than (to_date('%s','yyyy-mm-dd'));" % (
table_name, table_name, sdate, ndate)
sdate = ydate
if ydate == stop_date:
break;
print psql