使用cx_Oracle 模塊鏈接python
# -*- coding: utf-8 -*- import cx_Oracle #引用模塊cx_Oracle conn= cx_Oracle.connect('root', 'root', 'localhost:1521/oracle')#鏈接數據庫 c=conn.cursor() #獲取cursor sql='select * from student' x=c.execute(sql) #使用cursor進行各類操做 y=x.fetchall() print y c.close() #關閉cursor conn.commit() #提交 conn.close()
2.1 字符類sql
varchar和varchar2 必須指定長度,否則會報錯數據庫
2.2 數字型oracle
2.3 日期類型函數
timestamp 這是oracle9i對date數據類型的擴展。能夠精確到毫秒。fetch
2.4 圖片日誌
blob 二進制數據code
create table employee( sex VARCHAR(20), name VARCHAR(30), id number(20), age NUMBER(40) );
insert into "employee" VALUES('male','Angle',34,65);
insert into "TEST" (sex,name,age) VALUES('female','Adfds',42);
select * from test where id is null
to_data(value,pattern),value是時間參數,pattern是時間的格式 函數圖片
select ename,hiredate from emp where hiredate>to_date('1982/1/1','yyyy/mm/dd')
insert into "TEST"(SEX, name, id, age) values ('a004', 'ewf', null, null);
UPDATE "TEST" set name='fgfd' where id=34
UPDATE "TEST" set name='342',sex='fdgsergytrsh' where id=34
alter table test add (classid number(2));
alter table test modify (classid varchar2(12));
drop table student;
delete from test
_:表示任意單個字符utf-8
問題:如何顯示首字符爲S的員工姓名和工資?
select ename,sal from emp where ename like 'S%';
如何顯示第三個字符爲O的全部員工的姓名和工資?
select ename,sal from emp where ename like '__O%';
select * from emp where empno in (7844, 7839, 123, 456);
sql語句若是有引號, 則sql字符串用雙引號,內部的引號用單的就能夠
sql="select * from emp where (sal > 500 or job = 'MANAGER') and ename like 'J%'"
select e.ename,e.sal,d.dname from emp e,dept d where e.DEPTNO=d.DEPTNO
求和
select sum(sal) from EMP
或者
select sum(r.sal) from EMP r