-
啟動SQL*Plus工具,用system用戶連接到orcl資料庫,
sqlplus system/12345678@orcl -
進行用戶切換,以SYSDBA身份連接資料庫orcl,
conn system/12345678@orcl as sysdba -
首先使用記事本撰寫一個腳本檔案(內容如下),然后分別在SQL*Plus中顯示、執行該檔案,
以下為檔案內容:Prompt 顯示工資高于XX的員工資訊 Prompt 按<Enter鍵>繼續 Pause Accept value number prompt '請輸入工資界限:' select empno,ename,sal from scott.emp where sal>&valuestart d:\1.sql -
查詢scott.emp表中的員工號(empno)與員工工資(sal),要求在員工工資數值前顯示本地貨幣符號(RMB或¥),
column sal format L99999.99 select empno,sal from scott.emp; -
查詢scott.emp表中員工資訊,要求為查詢頁生成標題與標注,標題名稱為“員工資訊:”,顯示居中;注腳為制作人:你的姓名,
ttitle center '員工資訊' btitle right '張三' select * from scott.emp; -
顯示環境變數autocommit的默認值,然后設定其值為on,
show autocommit set autocommit on -
為表空間USERS添加一個資料檔案,檔案名為userdata03.dbf,大小為50MB,
alter tablespace USERS add datafile 'd:\userdata03.dbf' size 50M; -
修改表空間USERS中的userdata03.dbf為自動擴展方式,每次擴展5MB,最大為100MB,
alter database datafile 'd:\userdata03.dbf' autoextend on next 5M maxsize 100M; -
修改表空間USERS中的userdata03.dbf更名為userdata04.dbf,
alter database rename datafile 'd:\userdata03.dbf' to 'd:\userdata04.dbf'; -
將資料庫的控制檔案以二進制檔案的形式備份,
alter database backup controlfile to 'd:\orcl_ctlfile.bak'; -
為資料庫添加一個重做日志檔案組,組內包含兩個成員檔案,分別為redo4a.log、redo4b.log,大小均為5MB,
alter database add logfile group 4('d:\redo4a.log','d:\redo4b.log') size 5M; -
為新建的重做日志檔案組添加一個成員檔案,名稱為redo4c.log,
alter database add logfile member 'd:\redo4c.log' to group 4; -
創建一個本地管理方式下的自動磁區管理的表空間USERTBS1,其包含的資料檔案20MB,
create tablespace USERTBS1 datafile 'd:\usertbs1_1.dbf' size 20M extent management local autoallocate segment space management auto; -
將表空間USERTBS1脫機然后進行聯機操作,
alter tablespace USERTBS1 offline; alter tablespace USERTBS1 online; -
查詢USERTBS1表空間及其包含的資料檔案資訊,
select tablespace_name,datafile_name from dba_data_files where tablespace_name='USERTBS1'; -
按下串列結構利用SQL陳述句創建表student,
Table name: student列名 資料型別 約束 SNO NUMBER(4) 主鍵 SNAME VARCHAR(10) 唯一 SAGE NUMBER SEX CHAR(2) CNO NUMBER(2) create table student (SNO NUMBER(4) PRIMARY KEY, SNAME VARCHAR(10) UNIQUE, SAGE NUMBER, SEX CHAR(2), CNO NUMBER(2) ); -
為student表的SAGE列添加一個檢查約束,保證該列取值在0~100之間,
alter table student add constraint ck_sage check(sage between 0 and 100); -
利用子查詢分別創建一個事務級別的臨時表,其結構與student表的結構相同,
create global temporary table student_temp on commit delete rows as select * from student; -
創建一個student_range表(列、型別與student表的列、型別相同),按學生年齡分為三個區,低于20歲的學生資訊放入part1區,存盤在EXAMPLE表空間;20歲到30歲的學生資訊放在part2區;存放在ORCLTBS1表空間中;其他資料放在part3區,存放在ORCLTBS2中,
create tablespace ORCLTBS1 datafile 'd:\orcltbs1_1.dbf'; create tablespace ORCLTBS2 datafile 'd:\orcltbs2_1.dbf'; create table student_range partition by range(sage) (partition part1 values less than(20) tablespace EXAMPLE, partition part2 values less than(30) tablespace ORCLTBS1, partition part3 values less than(maxvalue) tablespace ORCLTBS2 ) as select * from student; -
創建一個起始值為10000的序列,步長為2,最大值為100000,不可回圈,
create sequence example_seq increment by 2 start with 10000 maxvalue 100000 nocycle; -
為SCOTT模式下的emp表創建一個公共同義詞,名稱為employee,
create public synonym employee for SCOTT.emp; -
創建一個口令認證的資料庫用戶usera,口令為usera,默認表空間為USERS,配額為10MB,
create user usera identified by usera default tablespace USERS quota 10M on USERS; -
為usera用戶授予Create session、scott.dept的select權限和update權限,同時允許該用戶將獲得的權限授予其他用戶,
grant create session to usera with admin option; grant select,update on scott.dept to usera with grant option; -
禁止用戶usera 將獲得的scott.dept的select權限和update權限再授予其他用戶,
revoke select,update on scott.dept from usera; grant select,update on scott.dept to usera; -
創建角色rolea和roleb,將create table、scott.dept的insert和delete權限授予rolea;將connect角色授予roleb,并將rolea、roleb授予用戶usera,
create role rolea; create role roleb; grant create table to rolea; grant insert,delete on scott.dept to rolea; grant connect to userb; grant rolea,roleb to usera; -
回收用戶usera的rolea角色,并驗證有效性,
revoke rolea from usera; -
為用戶usera創建一個概要檔案,限定該用戶的最長會話時間為30分鐘,如果連續10分鐘空閑,則結束會話,同時,限定其口令有效期為20天,連續登陸4次失敗后將鎖定賬戶,10天后自動解鎖,
create profile example_profile limit connect_time 30 idle_time 10 password_life_time 20 failed_login_attempts 4 password_lock_time 10; alter user usera profile example_profile;
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/242445.html
標籤:其他
