oracle / python-cx_Oracle

Python interface to Oracle Database now superseded by python-oracledb
https://oracle.github.io/python-cx_Oracle
Other
890 stars 361 forks source link

ProgrammingError: positional and named binds cannot be intermixed #667

Closed AlineGobbi closed 8 months ago

AlineGobbi commented 8 months ago

cx_Oracle.version: 8.3.0 cx_Oracle.clientversion: (11, 2, 0, 1, 0) platform.platform: Windows-10-10.0.22631-SP0 sys.maxsize > 2**32: True platform.python_version: 3.11.5

import numpy as np import cx_Oracle import pandas as pd

Captura de tela 2024-03-18 090948

but, I need to create a table in the DW and use these results. I have already make this on another projects, and it worked, but for this, don't work.

I create the table ( check on pl/sql and is there) but when i insert gives error

# Criar tabela DM_IC_NPS no banco de dados Oracle
create_table_query = '''
CREATE TABLE DM_IC_NPS (
    Ano NUMBER,
    Janeiro VARCHAR2(30),
    Fevereiro VARCHAR2(30),
    Março VARCHAR2(30),
    Abril VARCHAR2(30),
    Maio VARCHAR2(30),
    Junho VARCHAR2(30),
    Julho VARCHAR2(30),
    Agosto VARCHAR2(30),
    Setembro VARCHAR2(30),
    Outubro VARCHAR2(30),
    Novembro VARCHAR2(30),
    Dezembro VARCHAR2(30),
    Empresa VARCHAR2(30)
)
'''

cursor.execute(create_table_query)

# Inserir dados na tabela DM_IC_NPS
# cursor e commit devem ficar dentro da função!!!!!
for index, row in DM_IC_NPS.iterrows():
    insert_query = '''
    INSERT INTO DM_IC_NPS VALUES (
        :1, :2, :3, :4, :5, :6, :7, :8, :9, :10,
        :11, :12, :13, :14, :15
    )
    '''
    cursor.execute(insert_query, tuple(row))
    # Commit para salvar as alterações
    conn.commit()

THE ERROR:


ProgrammingError Traceback (most recent call last) Cell In[47], line 10 3 for index, row in DM_IC_NPS.iterrows(): 4 insert_query = ''' 5 INSERT INTO DM_IC_NPS VALUES ( 6 :1, :2, :3, :4, :5, :6, :7, :8, :9, :10, 7 :11, :12, :13, :14 8 ) 9 ''' ---> 10 cursor.execute(insert_query, tuple(row)) 11 # Commit para salvar as alterações 12 conn.commit()

ProgrammingError: positional and named binds cannot be intermixed

AlineGobbi commented 8 months ago

i make fillna(0) and it worked out

anthony-tuininga commented 8 months ago

Not sure what you did but glad you figured it out! :-)