表名和列的命名和規範
1、必須以字母開頭
2、長度不能超過30字元
3、不能使用Oracle的保留字
4、只能使用A-Z,a-z,0-9,¥,#等
資料類型
字元型:
char 定長 最大2000字元 查詢速度快。
varchar2(20) 變長 最大4000字元
clob(character large object) 字元型大對象 最大4G
數字型:
number 範圍-10的38次方到10的38次方,既可以是整數也可以是小數
number(5,2) 表示一個小數有五位有效數字,2位小數
number(5) 表示一個五位整數
日期類型:
date 包含年月日時分秒
timestamp 時間戳記
圖片:
blob 位元據,可以存放圖片/聲音 4G
建立表:
SQL> create table student(
2 xh number(4),--學號
3 xm varchar2(20),--姓名
4 sex char(2),--性別
5 birthday date,--生日
6 sal number(7,2)--獎學金金額
7 );
添加一個欄位:
alter table student add(classId number(2));
修改欄位的長度:
alter table student modify (xm varchar2(30));
修改欄位的類型/或是名字(不能有資料):
alter table student modify (xm char(30));
刪除一個欄位:
alter table student drop column sal;
修改表的名字:
rename student to stu;
刪除表:
drop table student;
插入資料:
insert into student values(1,'小明','男','20-10月-88','25000.25',12);
into必須有
日期:日-月-年
alter session set nls_date_format='yyyy-mm-dd';
插入部分欄位:
插入空值:null
select * from student where birthday is null;
刪除資料:
delete from student;寫日誌、可恢複、速度慢。
truncate table student;刪除表中所有記錄,表結構還在,不寫日誌,無法找回刪除的記錄,速度快。
savepoint a;//savepoint b;預設覆蓋a
rollback to a;