[转]how to inserting multiple rows in one step
To insert multiple rows in the table use executemany() method of cursor object.
Syntax:
cursor_object.executemany(statement, arguments)
- statement: string containing the query to execute.
- arguments: a sequence containing values to use within insert statement.
Let’s take an example.
from __future__ import print_function
import MySQLdb as my
db = my.connect(host="127.0.0.1",
user="root",
passwd="",
db="world"
)
cursor = db.cursor()
name = "Some new city"
country_code = 'SNC'
district = 'Someyork'
population = 10008
data = [
('city 1', 'MAC', 'distrct 1', 16822),
('city 2', 'PSE', 'distrct 2', 15642),
('city 3', 'ZWE', 'distrct 3', 11642),
('city 4', 'USA', 'distrct 4', 14612),
('city 5', 'USA', 'distrct 5', 17672),
]
sql = "insert into city(name, countrycode, district, population)
VALUES(%s, %s, %s, %s)"
number_of_rows = cursor.executemany(sql, data)
db.commit()
db.close()
[转]how to inserting multiple rows in one step的更多相关文章
- Oracle 拆分列为多行 Splitting string into multiple rows in Oracle
=========================== The table is as follows: Name | Project | Error 108 test Err1, Err2, Err ...
- MySQL Crash Course #10# Chapter 19. Inserting Data
INDEX BAD EXAMPLE Improving Overall Performance Inserting Multiple Rows INSTEAD OF Inserting a Singl ...
- Oracle Applications Multiple Organizations Access Control for Custom Code
档 ID 420787.1 White Paper Oracle Applications Multiple Organizations Access Control for Custom Code ...
- MyBatis(3.2.3) - Multiple results as a map
If we have a mapped statement that returns multiple rows and we want the results in a HashMap with s ...
- MySQL Information Functions
Table 12.18 Information Functions Name Description BENCHMARK() Repeatedly execute an expression CHAR ...
- Java性能提示(全)
http://www.onjava.com/pub/a/onjava/2001/05/30/optimization.htmlComparing the performance of LinkedLi ...
- ContentProvider官方教程(9)定义一个provider完整示例:实现方法,定义权限等
Creating a Content Provider In this document Designing Data Storage Designing Content URIs Implement ...
- Oracle Database 11g express edition
commands : show sys connect sys as sysdba or connect system as sysdba logout or disc clear screen or ...
- windows 下使用 zip安装包安装MySQL 5.7
以下内容参考官方文档:http://dev.mysql.com/doc/refman/5.7/en/windows-start-command-line.html 解压缩zip到D:\mysql-5. ...
随机推荐
- CMSG_COMPAT_ALIGN函数
CMSG_COMPAT_ALIGN函数是什么的使用方法?
- Selenium3+webdriver学习笔记2(常用元素定位方式,定位单个元素共8种,总共有23种)
#!/usr/bin/env python# -*- coding:utf-8 -*- from selenium import webdriver import time,os # about:ad ...
- UVALive 3523 Knights of the Round Table 圆桌骑士 (无向图点双连通分量)
由于互相憎恨的骑士不能相邻,把可以相邻的骑士连上无向边,会议要求是奇数,问题就是求不在任意一个简单奇圈上的结点个数. 如果不是二分图,一定存在一个奇圈,同一个双连通分量中其它点一定可以加入奇圈.很明显 ...
- Android(java)学习笔记127:生成 4种不同权限的文件
1. 首先我们编写一个生成 4种 不同权限的文件的程序案例: (1)首先是activity_main.xml文件: <RelativeLayout xmlns:android="htt ...
- 斐讯k2p 月光银 硬件版本A2-软件版本22.7.8.5 刷官改系统
Mark https://huabuyu.net/斐讯k2p%20月光银%20硬件版本A2-软件版本22.7.8.5%20刷官改系统.html 详细资源推荐:恩山论坛 https://www.righ ...
- 2018.4.17 java多线程练习二模拟开场仪式进场
2.某公司组织年会,会议入场时有两个入口,在入场时每位员工都能获取一张双色球彩票,假设公司有100个员工,利用多线程模拟年会入场过程, 并分别统计每个入口入场的人数,以及每个员工拿到的彩票的号码.线程 ...
- SC || Chapter 3
┉┉∞ ∞┉┉┉┉∞ ∞┉┉┉∞ ∞┉┉ 基本数据类型 && 对象数据类型 基本数据类型(int char long) 在栈中分配内存,不可变 对象数据类型(String BigInt ...
- Feign-手动创建FeignClient
前言 在<Feign-请求不同注册中心的服务>中,提到,如果需要请求不同注册中心的服务,可以设置@FeignClient的url属性. 这种做法有个缺点,需要服务消费者,配置各个环境的ur ...
- QT5:介绍
一.简介 QT是一个跨平台的C++开发库,主要用来开发图形用户界面(Graphical User Interface,GUI) QT除了可以绘制漂亮的界面(包括控件/布局/交互),还可以多线程/访问数 ...
- python-下拉框处理
在自动化中python对下拉框的处理网上相对实例比较少,其它前辈写的教程中对下拉也仅仅是相对与教程来说的,比如下面: m=driver.find_element_by_id("Shippin ...