Groovy Code To Export Oracle Procedures

It's really a pleasure to code in groovy.

My first try:

import groovy.sql.Sql

sql = Sql.newInstance("jdbc:oracle:thin:@ip:port:db","usr","pwd","oracle.jdbc.driver.OracleDriver")

def base  = "/usr/"
def names = []
def today = new java.text.SimpleDateFormat("yyyyMMddHH").format(new Date())

sql.eachRow("select * from user_procedures",{
 names << it.object_name
 })

def cnt = names.size()
names.eachWithIndex({ prc, i ->
 def d = new File(base, "${today}")
 d.mkdir()

 println "${i+1}/$cnt exporting ${prc}.prc...."
 def f = new File(d, "${prc}.prc")
 f << "CREATE OR REPLACE "
 sql.eachRow("select text from user_source where name=? order by line", [prc], {
  f<< it.text 
  })
 })

println "done"

 

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页