支持的數據類型: 字元型char 定長 最大2000varchar2() 變長 最大4000clob 字元型大對象 最大4G 數字型number範圍 -10的38次方到10的+38次方;number(5,2) 一個小數,有效位5個,小數點後2個數字number(5) 表示一個5位的整數 日期類型da ...
支持的數據類型:
字元型
char 定長 最大2000
varchar2() 變長 最大4000
clob 字元型大對象 最大4G
數字型
number範圍 -10的38次方到10的+38次方;
number(5,2) 一個小數,有效位5個,小數點後2個數字
number(5) 表示一個5位的整數
日期類型
date
timestamp
二進位數據
blob 保密性較高,存入資料庫/其他情況,保持在文件伺服器,資料庫只存文件路徑
建表:
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 created
delete from student;
rollback to firstPoint;
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;