利用Python腳本批量生成SQL語句
通過Python腳本批量生成插入數(shù)據(jù)的SQL語句
原始SQL語句:
INSERT INTO system_user (id, login_name, name, password, salt, code, createtime, email, main_org, positions, status, used, url, invalid, millis, id_card, phone_no, past, end_date, start_date) VALUES (’6’, ’db’, ’db’, ’53dd4e491d16f21b19606e8fb0619522e6d5f307’, ’a211f9dd3120178a’, NULL, sysdate, ’1@springside.org.cn’, NULL, ’’, ’enabled’, ’Used’, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
CreateSQL.py
f = open('/Users/apple/Downloads/sql/insertUser.sql',’w’)for i in range(6,57): str_i = str(i) login_name = 'test'+str_i name = 'test'+str_i sql = ’INSERT INTO system_user (id, login_name, name, password, salt, code, createtime, email, main_org, positions, status, used, url, invalid, millis, id_card, phone_no, past, end_date, start_date) ’ ’VALUES ('’+str_i+’','’+login_name+’','’+name+’','53dd4e491d16f21b19606e8fb0619522e6d5f307', 'a211f9dd3120178a', NULL, sysdate, '1@springside.org.cn', NULL, '’’', 'enabled', 'Used', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);’ f.write(sql) f.write('n')print(’50 success!’)f.close()
通過腳本拼接出一條插入數(shù)據(jù)的SQL,然后通過For循環(huán)生成批量SQL語句
生成結(jié)果:
以上這篇利用Python腳本批量生成SQL語句就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 以PHP代碼為實(shí)例詳解RabbitMQ消息隊(duì)列中間件的6種模式2. Python 如何將integer轉(zhuǎn)化為羅馬數(shù)(3999以內(nèi))3. python web框架的總結(jié)4. 詳解Python模塊化編程與裝飾器5. Python通過format函數(shù)格式化顯示值6. html小技巧之td,div標(biāo)簽里內(nèi)容不換行7. python裝飾器三種裝飾模式的簡單分析8. Python如何進(jìn)行時間處理9. Python實(shí)現(xiàn)迪杰斯特拉算法過程解析10. python使用ctypes庫調(diào)用DLL動態(tài)鏈接庫
