1

I am new to python. Could someone help me to figure out how to execute following commands using cx_Oracle in python?

  1. Spool C:\drop_tables.sql
  2. SELECT 'DROP TABLE ' || table_name || ' CASCADE CONSTRAINTS;' FROM user_tables;
  3. Spool off
  4. @C:\drop_tables.sql

I know I can use cursor.execute() for 2nd command but for other non sql commands specially 1 & 3 I am not getting any clue.

Appreciate if someone can help.

Thanks, Aravi

1
  • Why do you need to use SPOOL at all? Can't you just read the table names from the cursor into a list and then run a DROP TABLE statement for each table in the list? Commented Apr 8, 2014 at 19:23

1 Answer 1

1

So I achieved what I need by following way

cur.execute("SELECT table_name FROM user_tables")

result = cur.fetchall()

for row in result:

cur.execute('DROP TABLE ' + row[0] + ' CASCADE CONSTRAINTS')*

Thanks much Luke for your idea.

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.