zoukankan      html  css  js  c++  java
  • cx_Oracle模块学习之绑定变量



    有些时候我们需要和程序交互,此时需要绑定量
    下面两个例子简介在SELECT 和 DML 里面绑定变量的用法


    SELECT 里面的绑定变量

    [root@Ora10G py]# cat SelectBinding.py
    #!/bin/env python
    #coding=utf-8
    #filename:execise binding in select
    #Author:DBA_WaterBin
    
    import cx_Oracle
    
    conn=cx_Oracle.connect('hr/hr@orcl')
    cur=conn.cursor()
    
    dept_id=raw_input('
     please input department ID you want to search:')
    dept_name=raw_input(' please input department name you want to seaarch:')
    
    cur.execute('''select * from departments
                    where department_id=:id and
                          department_name=:name
                ''',id=dept_id,name=dept_name
                )
    
    rows=cur.fetchall()
    print '
    information are as following:'
    for row in rows:
      print row
    
    cur.close()
    conn.close()


    DML 里面的绑定变量

    [root@Ora10G py]# cat DmlBinding.py
    #!/bin/env python
    #coding=utf-8
    #filename:execise binding in dml
    #Author:DBA_WaterBin
    
    import cx_Oracle
    
    conn=cx_Oracle.connect('hr/hr@orcl')
    cur=conn.cursor()
    
    
    cur.execute('''insert into departments (department_id,department_name,manager_id,location_id) 
                   values(:ID,:NAME,:MGR_ID,:LOC_ID)
                  ''', {'ID':555,'NAME':'WaterBin','MGR_ID':110,'LOC_ID':7788}
               )
    cur.close()
    conn.commit()
    conn.close()
    

    By DBA_WaterBin

    2013-09-09

    good luck

  • 相关阅读:
    火星A+B
    分西瓜(DFS)
    H.数7(模拟)
    镜像树(dfs)
    锐雯上单不给就送(矩阵快速幂)
    STL容器
    优先队列(和fence repair完全一样)
    x位全排列(next_permutation)
    fence repair(队列水过)
    线段相交
  • 原文地址:https://www.cnblogs.com/riskyer/p/3310676.html
Copyright © 2011-2022 走看看