python可删除用户程序_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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值