zoukankan      html  css  js  c++  java
  • 吴裕雄 python oracle子查询的用法(3)

    import cx_Oracle

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

    sql = "select * from emp where deptno=(select deptno from dept where dname='%s')" % ('RESEARCH')
    cursor.execute(sql)
    result = cursor.fetchall()
    for row in result:
    print(row)

    sql = "select * from emp join dept on emp.deptno=dept.deptno where dept.dname='%s'" % ('RESEARCH')
    cursor.execute(sql)
    result = cursor.fetchall()
    for row in result:
    print(row)

    sql = "select * from emp where sal>(select min(sal) from emp) and sal<(select max(sal) from emp)"
    cursor.execute(sql)
    result = cursor.fetchall()
    for row in result:
    print(row)

    sql = "select * from emp where deptno in (select deptno from dept where dname<>'%s')" % ('SALES')
    cursor.execute(sql)
    result = cursor.fetchall()
    for row in result:
    print(row)

    sql = "select * from emp where sal>any(select sal from emp where deptno=10)and deptno<>10"
    cursor.execute(sql)
    result = cursor.fetchall()
    for row in result:
    print(row)

    sql = "select * from emp where sal>all(select sal from emp where deptno=30)"
    cursor.execute(sql)
    result = cursor.fetchall()
    for row in result:
    print(row)

    sql = "select * from emp f where sal>(select avg(sal) from emp where job=f.job)"
    cursor.execute(sql)
    result = cursor.fetchall()
    for row in result:
    print(row)

  • 相关阅读:
    Oracle 表空间使用率
    sqlserver 查询主外键索引常用语句
    sqlserver查版本信息
    sqlserver事务日志已满原因分析
    sqlserver创建dblink链接Oracle
    Oracle的DBMS_METADATA.GET_DDL()函数
    Mysql 基于GTID的主从复制(实操)
    Mysql 基于日志点的主从复制(实操)
    修改Linux命令提示符
    MYSQL 二进制安装
  • 原文地址:https://www.cnblogs.com/tszr/p/10124655.html
Copyright © 2011-2022 走看看