通过Python脚本批量生成插入数据的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()
通过脚本拼接出一条插入数据的SQL,然后通过For循环生成批量SQL语句
生成结果:
以上这篇利用Python脚本批量生成SQL语句就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持亿速云。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。