Created
January 25, 2010 18:49
-
-
Save rynmrtn/286114 to your computer and use it in GitHub Desktop.
Update Statement Generator
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 script will take a csv file (specified using the fileName variable) and | |
generate updates statements. The first row in the CSV file is assumed to be | |
the column names and all other rows are assumed to be data. | |
*/ | |
// Setup basic information | |
tableName = "TABLE_NAME" | |
fileName = "C:\\file.csv" | |
i = 0 | |
new File(fileName).splitEachLine(',') { fields -> | |
if(i++ == 0) { | |
columns = fields.collect { it } | |
} else { | |
values = fields.collect { it.equals("sysdate") ? it : ("'" + it + "'") } | |
len = fields.size()-1 | |
print "UPDATE ${tableName} SET " | |
for(x in 1..len) { | |
if(x != 1) print ", " | |
print "${columns[x]}=${values[x]}" | |
} | |
print " WHERE ${columns[0]} = ${values[0]};" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment