您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python Oracle SQL

bubuko 2022/1/25 19:30:28 python 字数 2361 阅读 841 来源 http://www.bubuko.com/infolist-5-1.html

pyhton 读写 Oracle 程序示例。
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


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶