日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

Oracle数据库常用的脚本命令(一)

發(fā)布時間:2025/7/25 数据库 88 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Oracle数据库常用的脚本命令(一) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

--連接數(shù)據(jù)庫的命令connect,用于切換連接用戶,簡寫形式conn
--語法格式:conn 用戶名/密碼
conn yanln/yanln

--顯示當前登錄的用戶
show user

--執(zhí)行操作系統(tǒng)的命令
host mkdir d:\testOracle

--導出記錄到文本
spool d:\testOracle\test.txt

select * from book;

spool off

--清屏
clear screen

--執(zhí)行文件系統(tǒng)中的sql語句
start d:\test.sql

--顯示表結(jié)構(gòu),命令describe,簡寫形式desc
desc student

--顯示錯誤信息
show error

--退出
exit

cmd-->sqlplus-->提示輸入用戶名、密碼的登錄方式

sqlplus /nolog : 進入sqlplus界面但不登錄

--sys用戶以sysdba的身份連接數(shù)據(jù)庫,連接時指定數(shù)據(jù)庫連接標識符@orcl
conn sys/oracle @orcl as sysdba

--sys用戶以sysdba的身份連接數(shù)據(jù)庫,連接時沒有指定數(shù)據(jù)庫連接標識符,此時將連接默認的數(shù)據(jù)庫
conn sys/oracle as sysdba
show user

--system用戶直接登錄數(shù)據(jù)庫
conn system/oracle
show user

--system用戶以sysdba的身份登錄數(shù)據(jù)庫
conn system/oracle as sysdba
show user

--創(chuàng)建默認表空間
create tablespace test1_tablespace datafile 'test1file.dbf' size 10m;

--創(chuàng)建臨時表空間
create temporary tablespace temptest1_tablespace tempfile 'tempfile1.dbf' size 10m;

--查看表空間數(shù)據(jù)文件的位置
select file_name from dba_data_files where tablespace_name = 'TEST1_TABLESPACE';

--查看臨時表空間數(shù)據(jù)文件的位置
select file_name from dba_temp_files where tablespace_name = 'TEMPTEST1_TABLESPACE';

--創(chuàng)建用戶
create user yan identified by test default tablespace test1_tablespace temporary tablespace temptest1_tablespace;

--查看創(chuàng)建的用戶
select username from dba_users;

--給剛創(chuàng)建的用戶授權(quán)
grant connect to yan;

--如果想更改用戶的密碼,我們可以通過
alter user yan identified by t123;

--如果管理員不希望某用戶登錄, 但又不打算刪除某用戶,可以將此用戶鎖定
alter user yan account lock;

--如果這個用戶不用了,想刪除這個用戶,可以用drop
drop user yan cascade;

--創(chuàng)建用戶user02
create user user02 identified by pass02;

--創(chuàng)建角色
create role manager;

--給角色賦予創(chuàng)建表、創(chuàng)建視圖的權(quán)限
grant create table, create view to manager;

--給角色manager授權(quán)給用戶
grant manager to user02;

--回收權(quán)限
revoke manager from user02;

--刪除權(quán)限
drop role manager;

--查看所有系統(tǒng)權(quán)限
select * from system_privilege_map;

--創(chuàng)建用戶
create user user02 identified by pass02;

--給用戶賦予一個創(chuàng)建會話的權(quán)限
grant create session to user01;

--通過角色給用戶賦予一個系統(tǒng)權(quán)限
create role manager;

grant create table, create sequence to manager;

grant manager to user01;

--查看所有對象權(quán)限
select * from table_privilege_map;

--通過角色給用戶賦予一個對象權(quán)限
create role manager01;

grant select,update,insert on scott.emp to manager01;

grant manager01 to user01;

--測試對象權(quán)限
conn user01/pass01

select * from scott.emp;(成功)

select * from scott.dept;(失敗)

--回收對象權(quán)限
revoke select,update,insert on scott.emp from manager01;

--查看管理員級別的表空間描述信息
select tablespace_name from dba_tablespaces;

--查看普通用戶級別的表空間描述信息
select tablespace_name from user_tablespaces;

--dba_users針對管理員級別的數(shù)據(jù)字典,用于查看數(shù)據(jù)庫所有用戶的用戶信息
select username,default_tablespace,temporary_tablespace from dba_users;

--user_users針對普通用戶級別的數(shù)據(jù)字典,用于查看當前登錄用戶的用戶信息
select username,default_tablespace,temporary_tablespace from user_users;

--設(shè)置用戶默認和臨時表空間
alter user user01
default tablespace TEST1_TABLESPACE
temporary tablespace TEMPTEST1_TABLESPACE;

-更改表空間的狀態(tài)為脫機狀態(tài)
alter tablespace test1_tablespace offline;

--更改表空間的狀態(tài)為聯(lián)機狀態(tài)
alter tablespace test1_tablespace online;

--更改表空間的狀態(tài)為只讀狀態(tài)
alter tablespace test1_tablespace read only;

--更改表空間的狀態(tài)為可讀寫狀態(tài)
alter tablespace test1_tablespace read write;

--查看表空間的狀態(tài)
select status from dba_tablespaces where tablespace_name = 'TEST1_TABLESPACE';

--增加數(shù)據(jù)文件
alter tablespace test1_tablespace add datafile 'test2_file.dbf' size 10m;

--查看表空間的數(shù)據(jù)文件
select file_name from dba_data_files where tablespace_name='TEST1_TABLESPACE';

--刪除數(shù)據(jù)文件
alter tablespace test1_tablespace drop datafile 'test2_file.dbf';

--刪除表空間
drop tablespace test1_tablespace including contents;

?

轉(zhuǎn)載于:https://www.cnblogs.com/xiaomifeng1010/p/11110913.html

總結(jié)

以上是生活随笔為你收集整理的Oracle数据库常用的脚本命令(一)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。