oracle數據庫基本操作(一)
一、數據基本類型
1、oracle的偽列
Oracle 中偽列就像一個表列,但是它並沒有存儲在表中偽列可以從表中查詢,但不能插入、更新和刪除它們的值常用的偽列有ROWID和ROWNUM;
ROWID 是表中行的存儲地址,該地址可以唯一地標識數據庫中的一行,可以使用 ROWID 偽列快速地定位表中的一行
ROWNUM 是查詢返回的結果集中行的序號,可以使用它來限制查詢返回的行數;
select rowid,rownum,id,name,price from goods;
2、數據定義語言(DDL)
create----alter----drop----truncate
3、數據操縱語言(DML)
insert---select---delete---update
4、事務控制語言(TCL)
commit---savepoint---rollback
5、數據控制語言(DCL)
grant---revoke
二、oracle數據庫基本簡介
1、表名的長度最大為30個字符;
2、同一用戶模式下,不同的表不能有相同的名稱;
3、oracle數據庫中的表名、列名、用戶名和其他對象名,不區分大小寫,系統會自動轉成大寫;
三、數據庫基本操作
1、選擇無重復的行
DISTINCT字句篩除結果集中內容全部相同的行,僅保留一行;
2、帶條件和排序的select命令(與mysql類似)
select stuNo,stuName,stuAge from student where stuAge>16 order by studentName asc,stuAge desc;
3、oracle數據庫列別名的添加與mysql類似
create table newStudent as select * from student
4、也可以只復制表結構,不復制數據
create table newStudent as select * from student where 1=2
三、DML語言操作
1、查看表中行數
----效率低 select count(*) from student ----效率高 select count(1) from student
2、取出表中對應列不存在重復數據的記錄
select stuName,stuAge from student group by stuName,stuAge having(count(stuName||stuAge)<2)
四、事物控制語言(TCL)
1、commit:提交事物;
2、rollback:回滾事物;
3、savepoint:在事物中創建存儲點
五、數據控制語言
1、創建表
--oracle沒有自增 因此創建一個序列,在插入數據的時候,將序列插入到定義的主鍵當中 create sequence stu_id; create table student( id number primary key, name varchar2(20), age number ); insert into student(stu_id.nextval,‘張三‘,10);
2、添加約束(與mysql相同)
3、向表中添加列
alter table student add(address varchar2(20),email varchar2(20));
4、刪除列
alter table test1 drop column name;
5、修改一個字段
alter table test1 modify (name varchar2(16) default ‘unknown’);
6、分頁
select * from( select a.*,rownum x from( select * from goods )a ) where x>2 and x<=4
oracle數據庫基本操作(一)