首页 > 数据库技术 > 详细

python Oracle SQL

时间:2020-08-06 20:11:30      阅读:140      评论:0      收藏:0      [点我收藏+]
pyhton Oracle 程序示例
import cx_Oracle

def real_save_to_oracle( lst_file_name, stpf_result_data_dir, dict_area_no ):
    conn = cx_Oracle.connect( "SYSDBA/123456@192.168.1.210/orcl" )
    cursor = conn.cursor()

    for file_name in lst_file_name:
        str_suffix = file_name[-4:]
        if str_suffix != ".csv":
            continue
        file_path = os.path.join( stpf_result_data_dir, file_name )
        df_data = pd.read_csv( file_path )

        file_name = file_name.split("_")[1]
        for _, row_data in df_data.iterrows():
            area_no = dict_area_no[ file_name ]
            print( area_no, file_name )
            str_time = row_data["Time"]
            d_P_real = row_data["P_use"]
            d_Q_real = row_data["Q_use"]

            str_sql = """select * from WF_STAT_PERIOD_DATA where WINDPLANT_NO=%d and
                        DATA_TIME=to_date( ‘%s‘, ‘yyyy-MM-dd HH24:mi:ss‘)""" % ( area_no, str_time )
            cursor.execute( str_sql )
            lst_result = cursor.fetchall()
            print( type( lst_result ), lst_result )
            if len( lst_result ) > 0:
                str_sql = """update WF_STAT_PERIOD_DATA set AVG_TEMP=%f, AVG_WIND_SPEED=%f where WINDPLANT_NO=%d and
                        DATA_TIME=to_date( ‘%s‘, ‘yyyy-MM-dd HH24:mi:ss‘)""" % ( d_P_real, d_Q_real, area_no, str_time )
                cursor.execute( str_sql )
            else:
                str_sql = """insert into WF_STAT_PERIOD_DATA values
                            ( %d, to_date( ‘%s‘, ‘yyyy-MM-dd HH24:mi:ss‘), 0, 0, 0, 0, 0, %f,
                            %f, 0, 1 )""" % ( area_no, str_time, d_Q_real, d_P_real )
                cursor.execute( str_sql )
            cursor.execute( "COMMIT" )
            time.sleep( 0.01 )
    # select * from PV_AREA_PF_PERIOD_DATA where AREA_NO=37 and MODEL_NO = 0 and TIME_SCALE=-1;
    cursor.close()
    conn.close()
    return None

python Oracle SQL

原文:https://blog.51cto.com/weiyuqingcheng/2517341

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!