Skip to content

Instantly share code, notes, and snippets.

@otwm
Last active December 23, 2015 06:24
Show Gist options
  • Save otwm/fdfd99e76504d819f750 to your computer and use it in GitHub Desktop.
Save otwm/fdfd99e76504d819f750 to your computer and use it in GitHub Desktop.
sql 파일 생성
import codecs
sql = ""
sql += "merge into tn_year_cust t1 using (select '{year}' year,'{custId}' cust_Id from dual) t2"
sql += " on (t1.year = t2.year and t1.cust_id= t2.cust_id)"
sql += " WHEN MATCHED THEN"
sql += " UPDATE SET"
sql += " SITE_TARGET_YN = '{siteTargetYn}'"
sql += " ,SITE_TARGET_DT = '{siteTargetDt}'"
sql += " ,SITE_COMPLETE_YN = '{siteCompleteYn}'"
sql += " ,SITE_COMPLETE_DT = '{siteCompleteDt}'"
sql += " ,SITE_VERIFY_STE = '{siteVerifySte}'"
sql += " ,SITE_RESULT_STE = '{siteResultSte}'"
sql += " ,SITE_TOT_OPINION = '{siteTotOpinion}'"
sql += " ,MOD_ID = '{modId}'"
sql += " ,MOD_DTT = '{modDtt}'"
sql += "WHEN NOT MATCHED THEN"
sql += " INSERT ("
sql += " YEAR"
sql += " ,CUST_ID"
sql += " ,SITE_TARGET_YN"
sql += " ,SITE_TARGET_DT"
sql += " ,SITE_COMPLETE_YN"
sql += " ,SITE_COMPLETE_DT"
sql += " ,SITE_VERIFY_STE"
sql += " ,SITE_RESULT_STE"
sql += " ,SITE_TOT_OPINION"
sql += " ,MOD_ID"
sql += " ,MOD_DTT"
sql += " ,comp_div"
sql += " ) VALUES ("
sql += " '{year}'"
sql += " ,'{custId}'"
sql += " ,'{siteTargetYn}'"
sql += " ,'{siteTargetDt}'"
sql += " ,'{siteCompleteYn}'"
sql += " ,'{siteCompleteDt}'"
sql += " ,'{siteVerifySte}'"
sql += " ,'{siteResultSte}'"
sql += " ,'{siteTotOpinion}'"
sql += " ,'{modId}'"
sql += " ,'{modDtt}'"
sql += " ,(select comp_div from tn_company where comp_id = '00000000000000095424')"
sql += " )"
sql += ";"
data = [
{'year' : '2012' ,'custId' :'xxxx' , 'siteTargetYn' :'Y','siteTargetDt': '2012.11.23' , 'siteCompleteYn':'Y','siteCompleteDt': '2012.11.23','siteVerifySte' :'COMPLATE' ,'siteResultSte':'MODIFY', 'siteTotOpinion':'검증의견','modId':'admin' , 'modDtt':'2015.12.15 15:08:07' }
]
def getSqlString(sql,data):
result = ''
for row in data:
result += sql.format(**row) + "\n"
return result
def fileWrite(name='merge.sql'):
file = codecs.open(name,'w','utf-8')
file.write(getSqlString.getSqlString(getSqlString.sql,getSqlString.data))
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment