今天又是充滿希望的一天
oracle學(xué)習(xí)
oracle中常用Scott用戶中的幾張表
- emp 薪資表
- dept 部門(mén)表
- customer 客戶表
1. 查詢(xún)語(yǔ)句:
select *
from 表名;`
select 告訴人家我要查表。
" * " 默認(rèn)指的是查當(dāng)前表中的所有數(shù)據(jù)。
from告訴人家,我要查哪個(gè)表。
- 關(guān)鍵字顯示是綠色的,一般建議不要亂用關(guān)鍵字,會(huì)沖突的,因?yàn)橄到y(tǒng)已經(jīng)占用了的,用來(lái)實(shí)現(xiàn)某些特定的功能。
2. 使用運(yùn)算符:
-
最基本的:+ 、-、* 、/
(1)從emp表中查找年薪:select enpon,ename, sal * 12 from emp;(2)計(jì)算員工的年收入=工資+獎(jiǎng)金:
select empno, ename, sal * 12, comm, sal * 12+comm from emp;
如果列的值為null的話,計(jì)算出來(lái)的也是null解決方案:如果值為null,則返回一個(gè)默認(rèn)值
-
nvl(參數(shù)1,參數(shù)2):
如果參數(shù)1不為空則返回它自己,如果為空,則返回參數(shù)2select empno, ename, sal * 12, nvl(comm,0), sal * 12 +nvl(comm,0) from emp;
3. 別名
(1)第一種:直接寫(xiě)中文,別名
(2)第二種:使用 as 關(guān)鍵字,as 別名
(3)第三種:使用雙引號(hào),"別名"
select empno 編號(hào), ename as 員工名, sal * 12 年薪, comm "獎(jiǎng)金", sal * 12 + nvl(comm, 0) as "年收入"
from emp;`
合并查詢(xún)到的重復(fù)數(shù)據(jù)
select distinct deptno from emp;
創(chuàng)建表空間
create tablespace You
datafile'D:\tablespace\you .dbf'
size 20M
autoextend on;--自動(dòng)擴(kuò)展,如果容量不足,則會(huì)自動(dòng)加
千萬(wàn)要記住:不要手動(dòng)到路徑下把生成的xxx.dbf文件刪除
刪除表空間
drop tablespace you including contents and datafiles;
查詢(xún)所有的表空間
select * from DBA_tablespaces;
查詢(xún)所有的數(shù)據(jù)文件
select * from Dba_Data_Files;
創(chuàng)建用戶
create user yuan --用戶名
identified by 1234 --密碼
default tablespace you --對(duì)應(yīng)的表空間
temporary tablespace temp --臨時(shí)表空間
刪除用戶
drop user you;
查詢(xún)所有的用戶
select * from Dba_Users;
給用戶加鎖和解鎖
alter user you account lock;--加鎖
alter user you account unlock;--解鎖
操作權(quán)限、連接權(quán)限
grant connect to you;
如果you有連接權(quán)限,可以指定給fang賬戶
grant connect to you
with fang option;
如果想要放大權(quán)限的話,可以指定DBA權(quán)限給它
grant dba to you with fang option;
收回權(quán)限
revoke connect from you;--收回連接權(quán)限
revoke dba from you ;--收回dba權(quán)限