[转]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. ...
随机推荐
- nmap -sS
SYN 扫描,半连接,受到syn/ack响应后意味着端口开放,收到rst包意味着端口关闭.
- Windows Azure 配置Active Directory 主机(3)
步骤 4:在 CloudSite 中安装附加域控制器 1.登录到 YourVMachine,单击“开始”,键入“dcpromo”,然后按 Enter. 2.在“欢迎使用”页上,单击“下一步”. 3.在 ...
- 两个div并列居中显示——当display:inline-block;时,两个div无法对齐即一高一矮
解决办法: 给div添加样式vertical-align: top;
- jsp另外五大内置对象之response-操作重定向
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...
- Hybrid App开发之Html基本标签使用
前言: 前面简单学习了html简单标签的使用,今天学习一下其他的标签的使用. HTML的超链接 1.)创建一个超链接 <div> <p> <a href="ht ...
- 2018.3.11 Java DEBUG 调试的方法
F5:Step Into:跳进当前执行的方法中 F6:Step Over:跳过该行继续执行 F7:Step Return:从方法中跳出继续执行 F8:Resume:全部运行通过,从调试状态恢复 Ctr ...
- Java中的Static修饰符
static(静态.修饰符):static修饰成员变量时:static修饰成员变量时,那么该成员变量的数据就是一个共享的数据. 静态成员变量的访问方式:方式一: 使用对象进行访问. 对象.属性名 方式 ...
- Java中this关键字的用法
this关键字作用: 1. 如果存在同名成员变量与局部变量时,在方法内部默认是访问局部变量的数据,可以通过this关键字指定访问成员变量的数据. 2. 在一个构造函数中可以调用另外一个构造函数初始化对 ...
- Java基础 匿名内部类 异常 多线程 集合面试题
匿名内部类:没有名字的内部类.就是内部类的简化形式.一般只用一次就可以用这种形式.匿名内部类其实就是一个匿名子类对象.想要定义匿名内部类:需要前提,内部类必须继承一个类或者实现接口. 匿名内部类的格式 ...
- 计算机应用第三次作业:自动开机自动关机 常用DOS命令 关于文件文件夹
一.自动开机 台式机启动时按住DEL键 进入一个蓝色的界面,界面上是英文提示 这个界面是BIOS ,是在机器的ROM中存储 二.自动关机 自动重启 方法一在120秒钟后自动关机 win+r (RUN ...