找出sql脚本中需要创建的表空间名称和数据库用户名
2024-10-19 02:20:42
测试的工作中,经常会遇到项目交接或者搭建一个新的测试环境,而创建oracle数据库用户及表空间时,需要提前找出脚本中的
数据库用户名和表空间名,所以自己写了一个python脚本,自动找出sql脚本中的数据库用户名和表空间名以及对应出现的次数。
脚本如下: #encoding=utf-8
import re
def FindUsernameOrTableplace(*dir_part):
username_num={}
tablespace_num={}
try:
for i in dir_part:
print(i)
with open(i,"r",encoding="utf-8") as ft:
while 1:
line=ft.readline()
if line=="":
break
else:
line=line.split()
#使用正则匹配出该行中以table开头,并且table后面连接空格的行,或table前后都是连接空格的行
if re.search(r"(?<= )(table)(?= )"," ".join(line)) or \
re.search(r"(table)(?= )"," ".join(line)):
if line.index("table")+1<len(line): #判断table不在末尾的行
if "." in line[line.index("table")+1]:
username=line[line.index("table")+1].split(".")[0]
if username not in username_num.keys():
username_num[username]=1
elif username in username_num.keys():
username_num[username]+=1
elif re.search(r"(?<= )(tablespace)(?= )"," ".join(line)) or \
re.search(r"(tablespace)(?= )"," ".join(line)):
if line.index("tablespace")+1<len(line):
if line[line.index("tablespace")+1] not in tablespace_num.keys():
tablespace_num[line[line.index("tablespace")+1]] = 1
elif line[line.index("tablespace")+1] in tablespace_num.keys():
tablespace_num[line[line.index("tablespace") + 1]]+=1
elif re.search(r"(?<= )(view)(?= )"," ".join(line)) or \
re.search(r"(view)(?= )"," ".join(line)):
if line.index("view")+1<len(line):
if "." in line[line.index("view")+1]:
username=line[line.index("view")+1].split(".")[0]
if username not in username_num.keys():
username_num[username]=1
elif username in username_num.keys():
username_num[username]+=1
print("数据库(用户)角色及出现数量:",username_num)
print("表空间及出现数量::",tablespace_num)
except Exception as err:
print(err) if __name__=="__main__":
FindUsernameOrTableplace(r"E:\SVN\表脚本\table.sql",r"E:\SVN\视图脚本\view.sql")
最新文章
- Codeforces Round #348(VK Cup 2016 - Round 2)
- arcgis union 0x80040218
- 在IIS上创建FTP服务
- SSH框架中spring的原理
- DIV+CSS命名规范-转载1
- 获取SqlDataReader的列名
- yii2.0的gii生成代码bug
- LinkedBlockingQueue
- 【UVA 1151】 Buy or Build (有某些特别的东东的最小生成树)
- 火狐浏览器对border-radius的渲染问题
- Delphi - SEH研究
- 多线程——实现Callable接口
- spring boot / cloud (十二) 异常统一处理进阶
- Hibernate学习---用Session实现CURD
- Struts2笔记_拦截器
- HDU 1006 Tick and Tick 时钟指针问题
- Linux下weblogic10.3.6(jar)版本安装详解
- [SoapUI] 检查测试步骤的类型或者或者某种特定类型的步骤列表
- 12、多线程:Threading、守护线程
- MyBatis Generator使用com.mysql.cj.jdbc.Driver遇到的问题
热门文章
- Docker安装MySQL数据库
- 【原创】大数据基础之CM5(Cloudera Manager)+CDH5离线安装
- 五种ip proxy的设置方法
- 八.nginx网站服务实践应用
- Python学习笔记三
- cmd下,regsvr32不是内部或外部命令
- angular 2+ 变化检测系列三(Zone.js在Angular中的应用)
- Codeforces 755F PolandBall and Gifts bitset + 二进制优化多重背包
- java中的try-catch-finally异常处理(学习笔记)
- 关于getchar-scanf函数的相关坑!