溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

oracle數(shù)據(jù)庫

發(fā)布時(shí)間:2020-09-26 01:51:02 來源:網(wǎng)絡(luò) 閱讀:171 作者:媱媱媽咪 欄目:關(guān)系型數(shù)據(jù)庫

用戶(user)是定義在數(shù)據(jù)庫中的一個(gè)名稱,訪問數(shù)據(jù)庫時(shí),要提供合適的用戶名和口令。
模式(Schema)是用戶所擁有對(duì)象的集合。用戶與模式是一一對(duì)應(yīng)的關(guān)系,并且二者名稱相同。
在Oracle 數(shù)據(jù)庫中建立用戶是使用命令create user 由dba用戶來完成;如果要以其他用戶身份創(chuàng)建用戶,必須需要create user 系統(tǒng)權(quán)限。

一、創(chuàng)建用戶語法定義:
CREATE USER test IDENTIFIED BY test
DERAULT TABKESPACE users_ts
TEMPORARY TABLESPACE temp_ts
QUOTA 3m ON users_ts;
如上示例:
建立一個(gè)數(shù)據(jù)庫用戶;
賬戶:test
口令:test
使用的默認(rèn)表空間:users_ts
使用的臨時(shí)表空間:temp_ts
在表空間users_ts 的配額:3m

二、鏈接到數(shù)據(jù)庫
為了鏈接到數(shù)據(jù)庫必須給予授權(quán)(create session)

1,示例:給初始用戶授予會(huì)話權(quán)限
connect system/manager
grant create session to test
connect test/test
可通過使用test賬戶連接上Oracle數(shù)據(jù)庫

2 示例:給數(shù)據(jù)庫賬戶授予create table 的權(quán)限對(duì)數(shù)據(jù)庫進(jìn)行初步操作
connect system/manager
grant creat table to test
connect test/test
create table ....
可通過使用test賬戶連接上Oracle數(shù)據(jù)庫,然后創(chuàng)建數(shù)據(jù)庫表。

3 示例:修改用戶口令
alter user test(用戶名) identified by test(用戶密碼)

4 示例:解鎖用戶
alter user test(要解鎖的用戶名) account unlock ;

5 示例:修改用戶空間配額
alter user test QUOTA 10m on users_ts;

6 示例:刪除數(shù)據(jù)庫用戶的語法
DROP USER username(用戶名)
注意:如果模式中包含有數(shù)據(jù)庫對(duì)象,則必須帶有CASCADE,否則會(huì)顯示錯(cuò)誤信息
drop user 用戶名 cascade;

授予系統(tǒng)權(quán)限
7 示例:授予系統(tǒng)權(quán)限語法
grant 系統(tǒng)權(quán)限列表(多個(gè)系統(tǒng)權(quán)限之間用“,”分隔)to 用戶
grant create session,create table to test;
即:授予創(chuàng)建會(huì)話和創(chuàng)建表的權(quán)限給test用戶。

回收系統(tǒng)權(quán)限
8 示例:回收系統(tǒng)權(quán)限語法
Revoke 系統(tǒng)權(quán)限列表(多個(gè)系統(tǒng)權(quán)限之間用“,”分隔)from 用戶
revoke create session,create table from test
即:從test 賬戶收回創(chuàng)建會(huì)話和創(chuàng)建表的權(quán)限。

9 顯示當(dāng)前用戶所具有的系統(tǒng)權(quán)限
select * from user_sys_privs where grantee='test'

10 顯示當(dāng)前角色所具有的權(quán)限
select * from session_privs;

授予對(duì)象權(quán)限
1 示例:
grant 權(quán)限列表(權(quán)限之間用逗號(hào)隔開) on 對(duì)象 to 賬戶

connect b/b 鏈接B賬戶
grant select ,insert on tx to A
把B.TX的查詢和添加的權(quán)限給A

2 示例:回收對(duì)象權(quán)限的基本語法
connect b/b 鏈接B賬戶
revoke select ,insert on TX from A

3 示例:顯示當(dāng)前用戶所具有的對(duì)象權(quán)限

select * from user_tab_privs
通過USER_TAB_PRIVS 可以查看當(dāng)前用戶所具有的對(duì)象權(quán)限。

創(chuàng)建角色

示例:創(chuàng)建的角色
CREATE ROLE test_role

給角色授權(quán)

示例: 給角色授權(quán)
grant create session, create table to test_role;

使用角色給用戶授權(quán)

示例:使用角色給用戶授權(quán)

GRANT test_role(角色名) TO user_name(用戶名)

示例:刪除角色
DROP ROLE test_role

使用user_role_privs 顯示當(dāng)前用戶具有的角色
示例:
SELECT USERNAME, GRANTED_ROLE FROM USER_ROLE_PRIVS;

三 SQL語句

SQL語句不區(qū)分大小寫,即可大寫,也可小寫,或混寫

DEPT表:公司部門表,字段(deptno,dname,loc)
EMP表:公司員工表,字段(empno, ename, job ,mgr, hiredate, sal, comm ,deptno)
DEPT為主表,EMP為從表

1 示例:顯示表結(jié)構(gòu)
desc emp;

2 示例:查詢所有列
selcet * from dept;

3 示例:查詢特定列
select deptno,dname from dept ;

使用算術(shù)表達(dá)式
示例:查詢年工資
select sal*12 from emp

取消重復(fù)的行,用關(guān)鍵字distinct
示例:
select distinct deptno ,job from emp

where 條件句

select ename, hiredate from emp where to_char(hiredate,'yyyymmdd')<'19810101';
注意:to_char(hiredate,'yyyymmdd')<'19810101'年月日的一種比較

select enma ,sal from emp where sal between 0 and 1000;
注意:在between 后頭指定較小的值,在and 后頭指定較大的值

select ename ,sal from emp where ename like '%s%'

select ename, sal from emp where ename like 'M%';
注意:通配符%和

%是指多個(gè)字符通配
_是單個(gè)字符匹配

在where 字句中使用邏輯操作符(AND ,NOT, OR)
select ename ,sal from emp where comm is not null;

select ename, sal from emp where comm>100 and sal >1000;

ORDER BY 字句

ASC用于升序排序(默認(rèn)),DESC用于降序,當(dāng)有多個(gè)字句時(shí)ORDER BY 字句必須放在最后
示例:
select ename, sal from emp order by sal desc ;

insert 增加數(shù)據(jù)

insert into emp

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI