Python 2.7.9 Demo - 019.01.CRUD oracle by cx_Oracle
select
#coding=utf-8
#!/usr/bin/python
import cx_Oracle; conn = None;
cursor = None;
try:
conn = cx_Oracle.connect('username/password@xxx.xxx.xxx.xxx/sid');
cursor = conn.cursor();
cursor.execute('select t.empno, t.ename from scott.emp t');
# 取回的是列表,列表中包含元组
list = cursor.fetchall();
print list; for record in list:
print "Record %d is %s!" % (record[0], record[1]); except Exception as e:
print ('Error : {}'.format(e));
finally:
cursor.close;
print 'cursor closed.';
conn.close;
print 'connection closed.';
insert
#coding=utf-8
#!/usr/bin/python
import cx_Oracle;
import time; conn = None;
cursor = None;
try:
conn = cx_Oracle.connect('username/password@xxx.xxx.xxx.xxx/sid');
cursor = conn.cursor();
tuple = ('', 'Nick Huang');
cursor.execute("insert into scott.emp (empno, ename) values (:1, :2)", tuple);
conn.commit();
print 'Insert successfully.'; except Exception as e:
print ('Error : {}'.format(e));
finally:
cursor.close;
print 'cursor closed';
conn.close;
print 'connection closed';
update
#coding=utf-8
#!/usr/bin/python
import cx_Oracle;
import time; conn = None;
cursor = None;
try:
conn = cx_Oracle.connect('username/password@xxx.xxx.xxx.xxx/sid');
cursor = conn.cursor();
tuple = ('Robin Chen', '');
cursor.execute("update scott.emp t set t.ename = :1 where t.empno = :2", tuple);
conn.commit();
print 'Update successfully.'; except Exception as e:
print ('Error : {}'.format(e));
finally:
cursor.close;
print 'cursor closed';
conn.close;
print 'connection closed';
delete
#coding=utf-8
#!/usr/bin/python
import cx_Oracle;
import time; conn = None;
cursor = None;
try:
conn = cx_Oracle.connect('username/password@xxx.xxx.xxx.xxx/sid');
cursor = conn.cursor();
param_map = {'id' : ''};
cursor.execute("delete from scott.emp t where t.empno = :id", param_map);
conn.commit();
print 'Delete successfully.'; except Exception as e:
print ('Error : {}'.format(e));
finally:
cursor.close;
print 'cursor closed';
conn.close;
print 'connection closed';
Python 2.7.9 Demo - 019.01.CRUD oracle by cx_Oracle的更多相关文章
- Python 2.7.9 Demo - 003.01.只允许相同缩进
Right #!/usr/bin/python if True: print ("True"); print('Again'); else: print ("False& ...
- appium+Python真机运行测试demo的方法
appium+Python真机运行测试demo的方法 一, 打开手机的USB调试模式 二, 连接手机到电脑 将手机用数据线连接到电脑,并授权USB调试模式.查看连接的效果,在cmd下运行命 ...
- 019 01 Android 零基础入门 01 Java基础语法 02 Java常量与变量 13 数据类型转换的代码示例
019 01 Android 零基础入门 01 Java基础语法 02 Java常量与变量 13 数据类型转换的代码示例 本文知识点:Java中的数据类型转换案例 学习视频有误,导致没法写文,文章内容 ...
- Python 2.7.9 Demo - 获取调用的参数
#coding=utf-8 #!/usr/bin/python import sys; print("The command line parameters are : "); f ...
- 第一个 Python 程序 - Email Manager Demo
看了一些基础的 Python 新手教程后,深深感觉到 Python 的简洁与强大,这是我的第一个 Python Demo.下面是完整代码与执行截图. 代码: # encoding: utf-8 ''' ...
- python 词云小demo
词云小demo jiebawordcloud 一 什么是词云? 由词汇组成类似云的彩色图形.“词云”就是对网络文本中出现频率较高的“关键词”予以视觉上的突出,形成“关键词云层”或“关键词渲染”,从而过 ...
- Python自动化运维之路-01
python的主要应用 python的擅长领域 学python有没有前途?python的语言排名 语言选择 运维会了开发后可以干什么? python的最大优势就是什么都能做. 课程概述 毕业目标 周五 ...
- Python实例---简单购物车Demo
简单购物车Demo # version: python3.2.5 # author: 'FTL1012' # time: 2017/12/7 09:16 product_list = ( ['Java ...
- Python caffe.TEST Example(Demo)
下面提供了caffe python的六个测试demo,大家可以根据自己的需求进行修改. Example 1 From project FaceDetection_CNN-master, under d ...
随机推荐
- OpenERP 的XML-RPC的轻度体验+many2many,one2many,many2one创建方式
来自:http://cn.openerp.cn/openerp_import_image_by_xmlrpc/ 每当夏秋之交,我们都有展会,展会完后,都有很多的新的潜在客户要添加,我们收了一大堆名片, ...
- C#时间戳转换[转发]
http://www.cnblogs.com/qingliuyu/p/3835858.html 以下是C#下的日期与unix时间戳的相互转换: /// <summary> /// 日期转换 ...
- jsp页面获取集合的长度
createTime--2016年10月12日16:20:02Author:Marydonjsp页面获取集合的长度 在jsp页面与js中不能通过${list.size}取列表长度,而是引入jstl ...
- win10下Visual Studio 2015,C++ x64编译zlib
前提安装了visual studio 2015 PS.几乎所有方式,x64的编译都会有点坑,鉴于网上的x86编译方式非常的多,所以不再累赘x86的编译方式 zlib下载源: 官网:http: ...
- java 实现文本格式转换
代码如下,不太规范,仅作学习用 import java.io.*; public class CharSetTest { public static void main(String[] args) ...
- 速度挑战 - 2小时完成HTML5拼图小游戏
概述 我用lufylegend.js开发了第一个HTML5小游戏——拼图游戏,还写了篇博文来炫耀一下:HTML5小游戏<智力大拼图>发布,挑战你的思维风暴. 详细 代码下载:http:// ...
- A. Dreamoon and Stairs(Codeforces Round #272)
A. Dreamoon and Stairs time limit per test 1 second memory limit per test 256 megabytes input standa ...
- 动态计算UITableViewCell高度详解
本文将介绍四种情况下UITableViewCell的计算方式,分别是: Auto Layout with UILabel in UITableViewCell Auto Layout with UIT ...
- MVC中JSON字符长度超出限制
本文导读:在MVC中通过JsonResult返回JSON字符串时,如果字符串长度过长,会抛出使用 JSON JavaScriptSerializer 进行序列化或反序列化时出错,字符串的长度超过了为 ...
- MVC公司架构介绍-事件机制