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的更多相关文章

  1. Python 2.7.9 Demo - 003.01.只允许相同缩进

    Right #!/usr/bin/python if True: print ("True"); print('Again'); else: print ("False& ...

  2. appium+Python真机运行测试demo的方法

    appium+Python真机运行测试demo的方法 一,    打开手机的USB调试模式 二,    连接手机到电脑 将手机用数据线连接到电脑,并授权USB调试模式.查看连接的效果,在cmd下运行命 ...

  3. 019 01 Android 零基础入门 01 Java基础语法 02 Java常量与变量 13 数据类型转换的代码示例

    019 01 Android 零基础入门 01 Java基础语法 02 Java常量与变量 13 数据类型转换的代码示例 本文知识点:Java中的数据类型转换案例 学习视频有误,导致没法写文,文章内容 ...

  4. Python 2.7.9 Demo - 获取调用的参数

    #coding=utf-8 #!/usr/bin/python import sys; print("The command line parameters are : "); f ...

  5. 第一个 Python 程序 - Email Manager Demo

    看了一些基础的 Python 新手教程后,深深感觉到 Python 的简洁与强大,这是我的第一个 Python Demo.下面是完整代码与执行截图. 代码: # encoding: utf-8 ''' ...

  6. python 词云小demo

    词云小demo jiebawordcloud 一 什么是词云? 由词汇组成类似云的彩色图形.“词云”就是对网络文本中出现频率较高的“关键词”予以视觉上的突出,形成“关键词云层”或“关键词渲染”,从而过 ...

  7. Python自动化运维之路-01

    python的主要应用 python的擅长领域 学python有没有前途?python的语言排名 语言选择 运维会了开发后可以干什么? python的最大优势就是什么都能做. 课程概述 毕业目标 周五 ...

  8. Python实例---简单购物车Demo

    简单购物车Demo # version: python3.2.5 # author: 'FTL1012' # time: 2017/12/7 09:16 product_list = ( ['Java ...

  9. Python caffe.TEST Example(Demo)

    下面提供了caffe python的六个测试demo,大家可以根据自己的需求进行修改. Example 1 From project FaceDetection_CNN-master, under d ...

随机推荐

  1. acm2024

    /**  * C语言合法标识符  */ import java.util.*; public class acm2024 { public static void main(String[] args ...

  2. js es6 map 与 原生对象区别

    区别 object和Map存储的都是键值对组合.但是: object的键的类型是 字符串: map的键的类型是 可以是任意类型: 另外注意,object获取键值使用Object.keys(返回数组): ...

  3. eclipse Failed to load the JNIshared library

      eclipse Failed to load the JNIshared library CreateTime--2018年4月22日22:08:35 Author:Marydon 1.情景再现 ...

  4. 搭建前端vue环境,安装vue-cli遇到Please try running this command again as root/Administrator的解决方案

    最近在搭前端环境,装完node.js之后,准备安装vue工程的初始化工具时(npm install -g vue-cli),遇到这个坑: 大体的意思就是权限问题,导致/usr/local/lib/no ...

  5. Pandas中DataFrame修改列名

    Pandas中DataFrame修改列名:使用 rename df = pd.read_csv('I:/Papers/consumer/codeandpaper/TmallData/result01- ...

  6. ASP.NET MVC下的异步Action的定义和执行原理[转]

    http://www.cnblogs.com/artech/archive/2012/06/20/async-action-in-mvc.html Visual Studio提供的Controller ...

  7. JSP开发中对jstl的引用方式(标签库引用)

    创建标签库引用文件taglibs.inc 一 采用本地标签库的taglibs.inc文件 <%--struts库标签 --%> <%@ taglib uri="/WEB-I ...

  8. if you are not making someone else's life better, then you are wasting your time.– Will Smith如果你不能给别人的生活带来改善,那么你就是在浪费你的宝贵时间。 --威尔 史密斯(程序员,你做的东西...)

    if you are not making someone else's life better, then you are wasting your time. – Will Smith 如果你不能 ...

  9. python学习笔记——正则表达式regex

    1 概述 1.1 定义 本质是由一系列字符和特殊符号组成的字串,用来表示一定规则的某一类字符串. 1.2 特点 正则表达式是一个独立的技术,其在多种编程语言中使用. 在python语言中的正则表达式模 ...

  10. python学习笔记——multiprocessing 多进程组件-队列Queue

    1 消息队列 1.1 基本语法 消息队列:multiprocessing.Queue,Queue是对进程安全的队列,可以使用Queue实现对进程之间的数据传输:还有一个重要作用是作为缓存使用. Que ...