zoukankan      html  css  js  c++  java
  • python 生成分区SQL

    
    # !/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
  • 相关阅读:
    hadoop balance
    随笔
    ubuntu server 使用parted分区
    程序员内功续
    hadoop——hdfs多硬盘挂载
    hdfs老数据压缩备份的一些问题20120521
    hadoop balance failed
    hoj 2524 Allocate Dormitories 二分图的最大匹配
    HDOJ 分类(转)
    hoj 3008 Matryoshka Dolls Again 最大独立子集
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349103.html
Copyright © 2011-2022 走看看