无法在python中使用cx_oracle合并表

ruyhziif  于 2023-10-16  发布在  Oracle
关注(0)|答案(2)|浏览(122)

我正在尝试使用cx_oracle合并两个表。以下SQL语言适用于SQL开发人员工具:

MERGE INTO ASBODS_SDDM_SCHEMA.EULA_DATA E
    USING (SELECT * FROM ASBODS_SDDM_SCHEMA.EULA_STG_DATA) ES
    ON (E.MASTER_METER_NBR = ES.MASTER_METER_NBR AND E.MASTER_ACCOUNT_NBR = ES.MASTER_ACCOUNT_NBR AND 
    E.METER_NBR = ES.METER_NBR AND E.ACCOUNT_NBR = ES.ACCOUNT_NBR AND E.EULA_DATA_TYPE_CD = ES.EULA_STG_DATA_TYPE_CD)
    WHEN MATCHED THEN
    UPDATE SET
    E.ACCEPTED_DT = ES.ACCEPTED_DT ,
    E.DECLN_OF_CONSENT_FLG = ES.DECLN_OF_CONSENT_FLG ,
    E.EULA_VERSION_NBR = ES.EULA_VERSION_NBR,
    E.SOFTWARE_VERSION_NBR = ES.SOFTWARE_VERSION_NBR,
    E.COMPANY_NM = ES.COMPANY_NM ,
    E.MACH_ID = ES.MACH_ID ,
    E.LOAD_DT = ES.LOAD_DT
    WHERE 
    E.MASTER_METER_NBR = ES.MASTER_METER_NBR AND E.MASTER_ACCOUNT_NBR = ES.MASTER_ACCOUNT_NBR AND 
    E.METER_NBR = ES.METER_NBR AND E.ACCOUNT_NBR = ES.ACCOUNT_NBR AND E.EULA_DATA_TYPE_CD = ES.EULA_STG_DATA_TYPE_CD

但是当我将这个sql插入cx_Orcale时:

import cx_Oracle

try:
    con = cx_Oracle.connect('username/pwd@server')
    cursor = con.cursor()
    cursor.execute(''' MERGE INTO ASBODS_SDDM_SCHEMA.EULA_DATA E
    USING (SELECT * FROM ASBODS_SDDM_SCHEMA.EULA_STG_DATA) ES
    ON (E.MASTER_METER_NBR = ES.MASTER_METER_NBR AND E.MASTER_ACCOUNT_NBR = ES.MASTER_ACCOUNT_NBR AND 
    E.METER_NBR = ES.METER_NBR AND E.ACCOUNT_NBR = ES.ACCOUNT_NBR AND E.EULA_DATA_TYPE_CD = ES.EULA_STG_DATA_TYPE_CD)
    WHEN MATCHED THEN
    UPDATE SET
    E.ACCEPTED_DT = ES.ACCEPTED_DT ,
    E.DECLN_OF_CONSENT_FLG = ES.DECLN_OF_CONSENT_FLG ,
    E.EULA_VERSION_NBR = ES.EULA_VERSION_NBR,
    E.SOFTWARE_VERSION_NBR = ES.SOFTWARE_VERSION_NBR,
    E.COMPANY_NM = ES.COMPANY_NM ,
    E.MACH_ID = ES.MACH_ID ,
    E.LOAD_DT = ES.LOAD_DT
    WHERE 
    E.MASTER_METER_NBR = ES.MASTER_METER_NBR AND E.MASTER_ACCOUNT_NBR = ES.MASTER_ACCOUNT_NBR AND 
    E.METER_NBR = ES.METER_NBR AND E.ACCOUNT_NBR = ES.ACCOUNT_NBR AND E.EULA_DATA_TYPE_CD = ES.EULA_STG_DATA_TYPE_CD
     ''') 
    con.commit()
    
    except cx_Oracle.DatabaseError as e:
    print('There is problem with sql', e)

finally:
    if cursor:
        con.commit()
        cursor.close()
    if con:
        con.close()

它在Linux中很长时间没有反馈,似乎它一直在运行,而不工作。
有朋友可以帮忙吗?

zrfyljdw

zrfyljdw1#

您在工具会话中提交了吗?可能table都锁上了。

nkkqxpd9

nkkqxpd92#

而不是多行合并语句将其转换为单行并尝试,我已经面临同样问题。对我很有效

相关问题