oracle系列(三)表操做基礎

支持的數據類型:

字符型
char 定長 最大2000
varchar2() 變長 最大4000
clob 字符型大對象 最大4G數據庫

數字型
number範圍 -10的38次方到10的+38次方;
number(5,2) 一個小數,有效位5個,小數點後2個數字
number(5) 表示一個5位的整數服務器

日期類型
date
timestamp函數

二進制數據
blob 保密性較高,存入數據庫/其餘狀況,保持在文件服務器,數據庫只存文件路徑spa

建表:

create table student(
stuId varchar2(10),
age number(2),
birthday date
)日誌

--添加一個字段
alter table student add(name varchar2(10));
--修改字段長度
alter table student modify (name varchar2(20));對象

null值:is null , is not null
select * from student t where t.name is not null;字符串

savepoint 保存點的使用

SQL> savepoint firstPoint;
Savepoint createdio

delete from student;table

rollback to firstPoint;date

drop from student;
delete from student where age>10;
truncate table student;--刪除全部記錄,表結構還在,不寫日誌,速度極快

簡單查詢:

列別名,函數nvl
select t.age "年齡" ,nvl( t.age,0) "年齡爲null顯示0",t.rowid from STUDENT t;
字符串鏈接:||
select t.name||'-'|| t.age from student t;

like操做符:
%:任意0到多個字符
_:單個任意字符 

多列子查詢:
select * from emp where (deptNo,job)=(select deptNo,job from emp where emp='jack');

用查詢結果建立新表:
create table mytable (id,name,sal,job,deptNo) as
select empNo,ename,sal,job,deptNo from emp;

union 取消重複行
union all 不取消重複行
intersect 取交集
minus 取差集

--分頁查詢select * from (select stu.*,rownum rn from (select * from student) stu where rownum <=5) where rn>=2;

相關文章
相關標籤/搜索