- 相關(guān)推薦
oracle筆試題及答案
oracle筆試題及答案
1.創(chuàng )建表空間neuspace,數據文件命名為neudata.dbf,存放在d:\data目錄下,文件大小為200MB,設為自動(dòng)增長(cháng),增量5MB,文件最大為500MB。(8分)
答:create tablespace neuspace datafile ‘d:\data\neudata.dbf’ size 200m auto extend on next 5m maxsize 500m;
2. 假設表空間neuspace已用盡500MB空間,現要求增加一個(gè)數據文件,存放在e:\appdata目錄下,文件名為appneudata,大小為500MB,不自動(dòng)增長(cháng)。(5分)
答:alter tablespace neuspace add datafile ‘e:\appdata\appneudata.dbf’ size 500m;
3. 以系統管理員身份登錄,創(chuàng )建賬號tom,設置tom的默認表空間為neuspace。為tom分配connect和resource系統角色,獲取基本的系統權限。然后為tom分配對用戶(hù)scott的表emp的select權限和對SALARY, MGR屬性的update權限。(8分)
答:create user tom identified by jack default tablespace neuspace;
Grant connect, resource to tom;
Grant select, update(salary, mgr) on scott.emp to tom;
4. 按如下要求創(chuàng )建表class和student。(15分)
屬性 | 類(lèi)型(長(cháng)度) | 默認值 | 約束 | 含義 |
CLASSNO | 數值 (2) | 無(wú) | 主鍵 | 班級編號 |
CNAME | 變長(cháng)字符 (10) | 無(wú) | 非空 | 班級名稱(chēng) |
屬性 | 類(lèi)型(長(cháng)度) | 默認值 | 約束 | 含義 |
STUNO | 數值 (8) | 無(wú) | 主鍵 | 學(xué)號 |
SNAME | 變長(cháng)字符 (12) | 無(wú) | 非空 | 姓名 |
SEX | 字符 (2) | 男 | 無(wú) | 性別 |
BIRTHDAY | 日期 | 無(wú) | 無(wú) | 生日 |
變長(cháng)字符 (20) | 無(wú) | 唯一 | 電子郵件 | |
SCORE | 數值 (5, 2) | 無(wú) | 檢查 | 成績(jì) |
CLASSNO | 數值 (2) | 無(wú) | 外鍵,關(guān)聯(lián)到表CLASS的CLASSNO主鍵 | 班級編號 |
答:create table class
(classno number(2) constraint class_classno_pk primary key,
cname varchar2(10) not null);
create table student
(stuno number(8) constraint student_stuno_pk primary key,
sname varchar2(12) not null,
sex 2) default ‘男’,
birthday date,
email varchar2(20) constraint student_email_uk unique,
score number(5,2) constraint student_score_ck check(score>=0 and score<=100),
classno number(2) constraint student_classno_fk references class(classno)
);
5. 在表student的SNAME屬性上創(chuàng )建索引student_sname_idx(5分)
答:create index student_sname_idx on student(sname);
6. 創(chuàng )建序列stuseq,要求初值為20050001,增量為1,最大值為20059999。(6分)
答:create sequence stuseq increment by 1 start with 20050001 maxvalue 20059999 nocache nocycle;
7. 向表student中插入如下2行。(5分)
STUNO | SNAME | SEX | BIRTHDAY | SCORE | CLASSNO | |
從stuseq取值 | tom | 男 | 1979-2-3 14:30:25 | tom@163.net | 89.50 | 1 |
從stuseq取值 | jerry | 默認值 | 空 | 空 | 空 | 2 |
答: into student values(stuseq.nextval, ’tom’, ’男’, to_date(‘1979-2-3
14:30:25’, ’yyyy-mm-dd fmhh24:mi:ss’), ’tom@163.net’, 89.50, 1);
into student (stuno, sname, classno) values(stuseq.nextval, ’jerry’, 2);
8. 修改表student的數據,將所有一班的學(xué)生成績(jì)加10分。(4分)
答:student set score=score+10 where classno=1;
9. 刪除表student的數據,將所有3班出生日期小于1981年5月12日的記錄刪除。(4分)
答: from student where classno=3 and birthday > ’12-5月-81’;
10. 完成以下SQL語(yǔ)句。(40分)
(1) 按班級升序排序,成績(jì)降序排序,查詢(xún)student表的所有記錄。
答:select * from student order by classno, score desc;
(2) 查詢(xún)student表中所有二班的成績(jì)大于85.50分且出生日期大于1982-10-31日的男生的記錄。
答:select * from student where classno=2 and score>85.50 and birthday < ’31-10月-82’ and sex=’男’;
(3) 查詢(xún)student表中所有三班成績(jì)?yōu)榭盏膶W(xué)生記錄。
答:select * from student where classno=3 and score is null;
(4) 表student與class聯(lián)合查詢(xún),要求查詢(xún)所有學(xué)生的學(xué)號,姓名,成績(jì),班級名稱(chēng)。(使用oracle與SQL 99兩種格式)
答:select s.stuno, s.sname, s.score, c.cname from student s, class c where s.classno=c.classno;
(5) 按班級編號分組統計每個(gè)班的人數,最高分,最低分,平均分,并按平均分降序排序。
答:select classno, count(*), max(score), min(score), avg(score) from student group by classno order by avg(score) desc;
(6) 查詢(xún)一班學(xué)生記錄中所有成績(jì)高于本班學(xué)生平均分的記錄。
答:select * from student where classno=1 and score > (select avg(score) from student where classno=1);
(7) 統計二班學(xué)生中所有成績(jì)大于所有班級平均分的人數。
答:select count(*) from student where classno=2 and score > all (select avg(socre) from student group by classno);
(8) 查詢(xún)平均分最高的班級編號與分數。
答:select classno, avg(score) from student group by classno having avg(score) = (select max(avg(score)) from student group by classno);
(9) 查詢(xún)所有學(xué)生記錄中成績(jì)前十名的學(xué)生的學(xué)號、姓名、成績(jì)、班級編號。
答:select stuno, sname, score, classno from (select * from student order by score desc) where rownum<=10;
(10) 創(chuàng )建視圖stuvu,要求視圖中包含student表中所有一班學(xué)生的stuno, sname, score, classno四個(gè)屬性,并具有with check option限制。
答:create view stuvu
as
select stuno, sname,score,classno from student where classno=1 with check option;
1、比較大小
select decode(sign(變量1-變量2),-1,變量1,變量2) from dual; –取較小值
sign()函數根據某個(gè)值是0、正數還是負數,分別返回0、1、-1
例如:
變量1=10,變量2=20
則sign(變量1-變量2)返回-1,decode解碼結果為“變量1”,達到了取較小值的目的。
2、表、視圖結構轉化
現有一個(gè)商品銷(xiāo)售表sale,表結構為:
month 6) –月份
sell number(10,2) –月銷(xiāo)售金額
現有數據為:
200001 1000
200002 1100
200003 1200
200004 1300
200005 1400
200006 1500
200007 1600
200101 1100
200202 1200
200301 1300
想要轉化為以下結構的數據:
year 4) –年份
month1 number(10,2) –1月銷(xiāo)售金額
month2 number(10,2) –2月銷(xiāo)售金額
month3 number(10,2) –3月銷(xiāo)售金額
month4 number(10,2) –4月銷(xiāo)售金額
month5 number(10,2) –5月銷(xiāo)售金額
month6 number(10,2) –6月銷(xiāo)售金額
month7 number(10,2) –7月銷(xiāo)售金額
month8 number(10,2) –8月銷(xiāo)售金額
month9 number(10,2) –9月銷(xiāo)售金額
month10 number(10,2) –10月銷(xiāo)售金額
month11 number(10,2) –11月銷(xiāo)售金額
month12 number(10,2) –12月銷(xiāo)售金額
結構轉化的SQL語(yǔ)句為:
create or replace view
v_sale(year,month1,month2,month3,month4,month5,month6,month7,month8,month9,month10,month11,month12)
as
select
substrb(month,1,4),
sum(decode(substrb(month,5,2),’01′,sell,0)),
sum(decode(substrb(month,5,2),’02′,sell,0)),
sum(decode(substrb(month,5,2),’03′,sell,0)),
sum(decode(substrb(month,5,2),’04′,sell,0)),
sum(decode(substrb(month,5,2),’05′,sell,0)),
sum(decode(substrb(month,5,2),’06′,sell,0)),
sum(decode(substrb(month,5,2),’07′,sell,0)),
sum(decode(substrb(month,5,2),’08′,sell,0)),
sum(decode(substrb(month,5,2),’09′,sell,0)),
sum(decode(substrb(month,5,2),’10′,sell,0)),
sum(decode(substrb(month,5,2),’11′,sell,0)),
sum(decode(substrb(month,5,2),’12′,sell,0))
from sale
group by substrb(month,1,4);
79、CASE語(yǔ)句的用法?
Oracle用法很簡(jiǎn)單:
SELECT last_name, job_id, salary
CASE job_id
WHEN ‘IT_PROG’ THEN 1.10*salary
WHEN ‘ST_CLERK’ THEN 1.15*salary
WHEN ‘SA_REP’ THEN 1.20*salary
ELSE salary END “REVISED_SALARY”
FROM employees
80、 truncate和的區別?
1、TRUNCATE在各種表上無(wú)論是大的還是小的都非?。如果有ROLLBACK命令DELETE將被撤銷(xiāo),而TRUNCATE則不會(huì )被撤銷(xiāo)。
2、TRUNCATE是一個(gè)DDL語(yǔ)言而DELETE是DML語(yǔ)句,向其他所有的DDL語(yǔ)言一樣,他將被隱式提交,不能對TRUNCATE使用ROLLBACK命令。
3、TRUNCATE將重新設置高水平線(xiàn)和所有的索引。在對整個(gè)表和索引進(jìn)行完全瀏覽時(shí),經(jīng)過(guò)TRUNCATE操作后的表比DELETE操作后的表要快得多。
4、TRUNCATE不能觸發(fā)觸發(fā)器,DELETE會(huì )觸發(fā)觸發(fā)器。
5、不能授予任何人清空他人的表的權限。
6、當表被清空后表和表的索引講重新設置成初始大小,而則不能。
7、不能清空父表。
81、 表空間如何擴展?并用語(yǔ)句寫(xiě)出?
兩種擴展方式:
a) 增加數據文件
alter tablespace tablespace_name add datafile ‘’ xxMB
b) 擴展數據文件大小
alter database datafile ‘’ resize newMB
82、 表空間區管理方式?哪種方式現在是推薦使用的?
a) 字典管理方式
extent management dictionary;默認方式
b) 本地管理方式
extent management local[autoallocate/uniform xxmb];
83、 用什么函數獲得日期?和日期中的月,日,年
to_sysdate,’year’):tow thsound six to_sysdate,’yyyy’) :2006
to_sysdate,’month’):8月 to_sysdate,’mm’):08
to_sysdate,’day’):星期4 to_sysdate,’dd’):22
84、 分區表的應用?
a) 一個(gè)分區表有一個(gè)或多個(gè)分區,每個(gè)分區通過(guò)使用范圍分區、散列分區、或組合分區分區的行
b) 分區表中的每一個(gè)分區為一個(gè)段,可各自位于不同的表空間中
c) 對于同時(shí)能夠使用幾個(gè)進(jìn)程進(jìn)行查詢(xún)或操作的大型表分區非常有用
85、 談?wù)勊饕挠梅霸?
索引是若干數據行的關(guān)鍵字的列表,查詢(xún)數據時(shí),通過(guò)索引中的關(guān)鍵字可以快速定位到要訪(fǎng)問(wèn)的記錄所在的數據塊,從而大大減少讀取數據塊的I/O次數,因此可以顯著(zhù)提高性能。
86、 存儲過(guò)程的應用,如何既有輸入又有輸出?
Create procedure pro_name
(xxxx in/out type;
yyyy in/out/inout type;
) is/as
zzzz type;
begin
sqlpro;
exception
exceptionxxxxx;
commit;
end;
87、 常發(fā)生的異常有哪些?
常用預定義例外
CURSOR_ALREADY_OPEN — ORA-06511 SQLCODE = -6511 游標已經(jīng)打開(kāi)
DUP_VAL_ON_INDEX — ORA-00001 SQLCODE = -1 違反唯一性約束
INVALID_CURSOR — ORA-01001 SQLCODE = -1001 非法游標操作
INVALID_NUMBER — ORA-01722 SQLCODE = -1722 字符向數字轉換失敗
LOGIN_DENIED — ORA-01017 SQLCODE = -1017
NO_DATA_FOUND — ORA-01403 SQLCODE = +100 沒(méi)有找到數據
NOT_LOGGED_ON — ORA-01012 SQLCODE = -1012 沒(méi)有連接到數據庫
PROGRAM_ERROR — ORA-06501 SQLCODE = -6501 內部錯誤
STORAGE_ERROR — ORA-06500 SQLCODE = -6500
TIMEOUT_ON_RESOURCE — ORA-00051 SQLCODE = -51
TOO_MANY_ROWS — ORA-01422 SQLCODE = -1422 返回多行
TRANSACTION_BACKED_OUT — ORA-00061 SQLCODE = -61
VALUE_ERROR — ORA-06502 SQLCODE = -6502 數值轉換錯誤
ACCESS_INTO_NULL試圖為NULL對象的屬性賦值
ZERO_DIVIDE — ORA-01476 SQLCODE = -1476 被零除
OTHERS — 其它任何錯誤的處理
88、 如何使用異常?
在oracle中有三種類(lèi)型的異常。預定義的異常 非預定義的異常 用戶(hù)定義的異常 第二種非預定義的異常是與特定的oracle錯誤關(guān)聯(lián)。并且用PRAGM EXCEPTION_INIT(EXCEPTION_NAME,ERROR_NUMBER)關(guān)聯(lián)一起的。但是到底有什么用啊? 例如:declare dup_primary_key exception; pragma exception_init(dup_primary_key,-1); begin into itemfile values(‘i201′,’washer’,spares’,100,50,250,12,30); exception when dup_primary_key then dbms_output.put_line(‘重復項編號-主鍵沖突’); end
第一種的使用方法:exception
when 異常名稱(chēng) then
異常處理代碼;
第三種的用法:if 條件 then
raise_application_error(-20000“““`-20999,提示信息);
end if;
89、優(yōu)化的策略一般包括:
• 內存優(yōu)化
• 操作系統優(yōu)化
• 數據存儲的優(yōu)化
• 網(wǎng)絡(luò )優(yōu)化等方法
具體到不同的數據庫涉及到要調整不同的數據庫配置文件、不同的操作系統參數、網(wǎng)絡(luò )參數等等, 不同的數據庫不同
【oracle筆試題及答案】相關(guān)文章:
oracle 技術(shù)筆試題02-18
益和電力Oracle筆試題分享11-21
Oracle認證11-14
java筆試題及答案08-20
英語(yǔ)面試試題及答案02-18
外企面試的經(jīng)典試題及答案02-18
經(jīng)典java筆試題及答案分享02-25
報社筆試題目及答案03-23
2017華為筆試題及答案02-23
醫院面試試題及答案02-18