1

Below is the code giving the following error:

TypeError: parameters should be a list of sequences/dictionaries or an integer specifying the number of times to execute the statement

sql=("SELECT * FROM ABCD WHERE SA in ('111111111')")
cur_src_qa = conn_src_qa.cursor()
cur_src_qa.execute(sql)
df_s = cur_src_qa.fetchall()
cur_src_qa.close()   
cur_src_dev = conn_src_dev.cursor()
cur_src_dev.execute("delete ABCD where SA in ('111111111')")
conn_src_dev.commit()
cur_src_dev.executemany("insert into ABCD (A, B, C, D, E, F, F, G, H, I, J) values(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", df_s[0])
# cur_src_dev.executemany("insert into ABCD values ({​​​​​}​​​​​)", df_s)
conn_src_dev.commit()
cur_src_dev.close()

1 Answer 1

1

Start by replacing the %s with bind variable syntax. Then get your data in the right input format - in your example just use the query return variable directly.

Given this table:

SQL> create table test (k number, v varchar2(20));

Table created.

SQL> insert into test (k,v) values (1, 'abc');

1 row created.

SQL> insert into test (k,v) values (2, 'def');

1 row created.

SQL> insert into test (k,v) values (3, 'ghk');

1 row created.

SQL> commit;

Commit complete.

And the Python code:

    cursor.execute("select k,v from test")
    rows = cursor.fetchall()
    print(rows);

    cursor.execute("delete from test")

    cursor.executemany("insert into test (k,v) values (:1, :2)", rows)
    
    cursor.execute("select k,v from test")
    rows = cursor.fetchall()
    print(rows);

The output is:

$ python so12.py 
[(1, 'abc'), (2, 'def'), (3, 'ghk')]
[(1, 'abc'), (2, 'def'), (3, 'ghk')]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.