import cx_Oracle

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

sql = "select * from emp"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

job = 'SALESMAN'
sql = "select * from emp where job='%s'" % job
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

job = 'SALESMAN'
sql = "select * from emp where job='%s' order by empno" % job
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = "select * from dept"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = "select rowid,job,ename from emp"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = "select sal*(1+0.1),sal from emp"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = """select empno as "%s", ename as "%s", job as "%s" from emp""" % ('员工编号','员工姓名','职务')
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = """select empno "%s", ename "%s", job "%s" from emp""" % ('员工编号','员工姓名','职务')
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = "select distinct job from emp"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = "select * from emp where sal<>all(3000,950,800)"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = "select * from emp where ename like 'S%'"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = "select * from emp where job in ('%s','MANAGER','%s')" % ('PRESIDENT','ANALYST')
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = "select * from emp where job not in ('%s','MANAGER','%s')" % ('PRESIDENT','ANALYST')
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = "select * from emp where sal not between 2000 and 3000"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = "select * from emp where sal between 2000 and 3000"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

import cx_Oracle

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

sql = "select * from locations where state_province is null"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

import cx_Oracle

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

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

sql = "select * from emp where sal<2000 or sal>3000"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = "select deptno,job from emp group by deptno,job order by deptno"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = "select deptno as 员工编号,avg(sal) as 平均工资 from emp group by deptno"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = "select deptno as 员工编号,avg(sal) as 平均工资 from emp group by deptno having avg(sal)>2000"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = "select deptno,empno,ename from emp order by deptno,empno"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = "select e.empno,e.ename,d.deptno from emp e, dept d where e.deptno=d.deptno and e.job='%s'" % ('MANAGER')
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

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

sql = "insert into emp(empno,ename,job) values(9527,'%s','%s')" % ('EAST','SALESMAN')
cursor.execute(sql)
conn.commit()
print("添加成功...")

sql = "select e.empno,e.ename,e.job,d.deptno,d.dname from emp e left join dept d on e.deptno=d.deptno"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = "select e.empno,e.ename,e.job,d.deptno,d.dname from emp e right join dept d on e.deptno=d.deptno"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = "select empno,ename,job,deptno,dname from emp natural join dept where sal>2000"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = "select em2.ename,em1.ename from emp em1 left join emp em2 on em1.mgr=em2.empno order by em1.mgr"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

sql = "select count(*) from dept cross join emp"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row)

吴裕雄 python oracle检索数据(1)的更多相关文章

  1. 吴裕雄 python oracle检索数据(2)

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

  2. 吴裕雄 python oracle操作数据库(4)

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

  3. 吴裕雄 python oracle子查询的用法(3)

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

  4. Oracle 检索数据(查询数据、select语句)

    用户对表或视图最常进行的操作就是检索数据,检索数据可以通过 select 语句来实现,该语句由多个子句组成,通过这些子句完成筛选.投影和连接等各种数据操作,最终得到想要的结果. 语法: select ...

  5. 吴裕雄 python 机器学习——数据预处理过滤式特征选取SelectPercentile模型

    from sklearn.feature_selection import SelectPercentile,f_classif #数据预处理过滤式特征选取SelectPercentile模型 def ...

  6. 吴裕雄 python 机器学习——数据预处理过滤式特征选取VarianceThreshold模型

    from sklearn.feature_selection import VarianceThreshold #数据预处理过滤式特征选取VarianceThreshold模型 def test_Va ...

  7. 吴裕雄 python 机器学习——数据预处理正则化Normalizer模型

    from sklearn.preprocessing import Normalizer #数据预处理正则化Normalizer模型 def test_Normalizer(): X=[[1,2,3, ...

  8. 吴裕雄 python 机器学习——数据预处理标准化MaxAbsScaler模型

    from sklearn.preprocessing import MaxAbsScaler #数据预处理标准化MaxAbsScaler模型 def test_MaxAbsScaler(): X=[[ ...

  9. 吴裕雄 python 机器学习——数据预处理标准化StandardScaler模型

    from sklearn.preprocessing import StandardScaler #数据预处理标准化StandardScaler模型 def test_StandardScaler() ...

随机推荐

  1. .NET Core和.NET Standard

    作为.NET家族的最新成员,有很多关于.NET Core和.NET Standard的误解,以及它们于.NET Framework之间的区别.在这篇文章,我会准确的解释他们究竟是什么,并看看何时应选择 ...

  2. python访问hive

    #!/usr/bin/env python # -*- coding: utf-8 -*- # hive util with hive server2 """ @auth ...

  3. 使用Git将项目上传到GitHub管理

    首先你需要一个github账号.https://github.com/ 我们使用git需要先安装git工具. 1.进入Github首页,点击New repository新建一个项目 2.填写相应信息后 ...

  4. ubuntu高版本如何设置开机启动脚本

    ubuntu-18.04不能像ubuntu14一样通过编辑rc.local来设置开机启动脚本 可以通过下列简单设置后,可以使rc.local重新发挥作用. 1.建立rc-local.service文件 ...

  5. 背景图片的移动----background-attach-----background-repeat

    background-repeat:默认是平铺的,也即是还有空间的话将一张接着一张显示 设置为 no-repeat  就最多显示一张 background-attachment:设置是否固定图片,在有 ...

  6. QNetworkAccessManager post()和get()方法

    GET方式提交的数据最多只能有1024字节,而POST则没有此限制. 大文件传输用post(),小文件用get(), 第一次接触Qt的Http项目,今天看了一下Post和Get的基本使用方法,就开始尝 ...

  7. activiti explorer5.22.0源代码解读

    请求通过ExplorerApplicationServlet(AbstractApplicationServlet.service()方法)进入web系统中. Activiti Explorer的应用 ...

  8. 重新配置dbconsole的步骤

    重新配置dbconsole的步骤emca -repos dropemca -repos createemca -config dbcontrol dbemctl start dbconsole

  9. 正则表达式-使用说明Regular Expression How To (Perl, Python, etc)

    notepad++ wiki about regular expression 正则表达式-使用说明Regular Expression How To (Perl, Python, etc) http ...

  10. 2.python知识点总结

    1.什么是对象?什么是类? 对象是对类的具体表达,类是对象的抽象表达. 类只是为所有的对象定义了抽象的属性与行为. —————————————————————————————————————————— ...