zoukankan      html  css  js  c++  java
  • 吴裕雄 python oracle检索数据(2)

    import cx_Oracle

    conn = cx_Oracle.connect("scott/admin@localhost:1521/orcl")
    cursor = conn.cursor()

    sql = "select ascii('Z'),ascii('H'),ascii('D'),ascii(' ') from dual"
    cursor.execute(sql)
    result = cursor.fetchall()
    for i in result:
    print(i)

    sql = "select chr(90),chr(72),chr(32) from dual"
    cursor.execute(sql)
    result = cursor.fetchall()
    for i in result:
    print(i)

    sql = "select concat('Hello','World') from dual"
    cursor.execute(sql)
    result = cursor.fetchall()
    for i in result:
    print(i)

    sql = "select initcap('oh my god!') from dual"
    cursor.execute(sql)
    result = cursor.fetchall()
    for i in result:
    print(i)

    sql = "select instr('oracle 11g','1',3,2) from dual"
    cursor.execute(sql)
    result = cursor.fetchall()
    for i in result:
    print(i)

    sql = "select e.empno,e.ename,d.dname from emp e inner join dept d on e.deptno=d.deptno where length(e.ename)>5"
    cursor.execute(sql)
    result = cursor.fetchall()
    for i in result:
    print(i)

    import cx_Oracle

    conn = cx_Oracle.connect("hr/admin@localhost:1521/orcl")
    cursor = conn.cursor()

    sql = "select employee_id,lower(first_name),upper(last_name) from employees where lower(first_name) like 'a%'"
    cursor.execute(sql)
    result = cursor.fetchall()
    for i in result:
    print(i)

    sql = "select ltrim('##########Eas###########','#'),rtrim('East ') from dual"
    cursor.execute(sql)
    result = cursor.fetchall()
    for i in result:
    print(i)

    sql = "select replace('Bad Luck Bad Gril','Bad','Good') from dual"
    cursor.execute(sql)
    result = cursor.fetchall()
    for i in result:
    print(i)

    sql = "select substr('MessageBox',8,3) from dual"
    cursor.execute(sql)
    result = cursor.fetchall()
    for i in result:
    print(i)

    sql = "select ceil(7.3),ceil(7),ceil(-7.3) from dual"
    cursor.execute(sql)
    result = cursor.fetchall()
    for i in result:
    print(i)

    sql = "select round(3.1415926,2) from dual"
    cursor.execute(sql)
    result = cursor.fetchall()
    for i in result:
    print(i)

    sql = "select power(2,3) from dual"
    cursor.execute(sql)
    result = cursor.fetchall()
    for i in result:
    print(i)

    sql = "select sysdate from dual"
    cursor.execute(sql)
    result = cursor.fetchall()
    for i in result:
    print(i)

    sql = "select ADD_MONTHS(sysdate,6) from dual"
    cursor.execute(sql)
    result = cursor.fetchall()
    for i in result:
    print(i)

    sql = "select sysdate,to_char(sysdate,'YYYY-MM-DD') from dual"
    cursor.execute(sql)
    result = cursor.fetchall()
    for i in result:
    print(i)
    print(result[0][1])

    sql = "select to_number('18f','xxx') from dual"
    cursor.execute(sql)
    result = cursor.fetchall()
    for i in result:
    print(i)

    import cx_Oracle

    conn = cx_Oracle.connect("scott/admin@localhost:1521/orcl")
    cursor = conn.cursor()

    sql = "select count(empno),round(avg(sal),2) from emp"
    cursor.execute(sql)
    result = cursor.fetchall()
    for i in result:
    print(i)

  • 相关阅读:
    Less学习笔记
    如何在网页启动Windows服务
    让VS2010记住TFS的登陆用户名和密码
    调式WP程序报0x80131500错误的解决办法
    FizzBuzzWhizz是算法题吗?我从设计的角度去解决的。
    基于Roslyn的远程任务平台
    优雅就一个字——设计模式之数据上传接口
    关于反射优化的疑问,单次调用时直接反射要快于委托调用反射?
    用VC++11中编译libthrift项目
    grunt初体验
  • 原文地址:https://www.cnblogs.com/tszr/p/10124633.html
Copyright © 2011-2022 走看看