search

Home  >  Q&A  >  body text

python - How to execute multiple SQL statements at once

Suppose there are multiple statements like this:

select T_JGDM_20160811.JJLX from T_JGDM_20160811 where rownum < 30;
select T_JGDM.JJLX from T_JGDM where rownum < 30;
...

We can summarize it into the format of select xxx from yyy, how to execute multiple such statements at one time in Python, where xxx and yyy are variable.

習慣沉默習慣沉默2779 days ago2077

reply all(1)I'll reply

  • 给我你的怀抱

    给我你的怀抱2017-05-25 15:10:08

    You can extract xxx and yyy as variables

    pram = [
        (1111, 2222),
        (2222, 3333)
        ...(自己补充)
    ]
    for table, db in pram:
        sql = 'select %s from %s' % (table, db)
        print sql # 此处自行替换具体代码

    reply
    0
  • Cancelreply