日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python编写脚本,删除固定用户下的所有表

發布時間:2023/11/29 python 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python编写脚本,删除固定用户下的所有表 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
腳本如下:

[oracle@ycr python]$ more t_del.py?
#/usr/bin/python
#coding:utf8

import sys
import cx_Oracle

i=0
conn=cx_Oracle.connect('%s/%s@%s' % (sys.argv[1],sys.argv[2],sys.argv[3]))
cursor=conn.cursor()
cursor.execute('select table_name from user_tables')
rows=cursor.fetchall()
for row in rows:
? ? cursor.execute('drop table %s cascade constraints purge' % row)?
? ? i+=1

cursor.close()
conn.close()
print 'Drop table complete! %d tables droped' % i

測試
創建測試表,使用test用戶執行如下腳本:
create table t1 as select * from user_tables;
create table t2 as select * from user_tablespaces;
create table t3 as select * from user_objects;

執行程序:
python t_del.py test oracle YCR2
此小程序有三個參數,test為要刪除表的用戶名,oracle為密碼,YCR2為連接字符串。

執行結果如下:
python t_del.py test oracle YCR2
Drop table complete! 3 tables droped


------------------------------------------------------------------------------
本腳本寫來練習用,實際意義不是很大,昨天開發同時讓幫忙spool出來一個刪除表的腳本,自動化要求較高,所以寫了個小程序。
不過執行此程序需要安裝cx_Oracle模塊,相對繁瑣。

Clark
2016.08.03

轉載于:https://www.cnblogs.com/Clark-cloud-database/p/7813563.html

總結

以上是生活随笔為你收集整理的python编写脚本,删除固定用户下的所有表的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。