-
-
Save atonse/284147 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
This groovy script will take a CSV file that represents the data | |
in a database. The first row should be the name of the columns and | |
all other rows should represent the data you wish to insert. | |
*/ | |
// Setup basic information | |
numColumns = 6 | |
tableName = "TABLE_NAME" | |
fileName = "C:\\file\\path" | |
i = 0 | |
new File(fileName).splitEachLine(',') { fields -> | |
if(i++ == 0) { | |
columns = "(${fields.join(',')})" | |
} else { | |
values = fields.collect { it.equals("sysdate") ? it : ("'" + it + "'") } | |
println "INSERT INTO ${tableName}${columns} VALUES (${values.join(',')});" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment