亚洲国产日韩欧美在线a乱码,国产精品路线1路线2路线,亚洲视频一区,精品国产自,www狠狠,国产情侣激情在线视频免费看,亚洲成年网站在线观看

oracle筆試題及答案

時(shí)間:2022-08-16 22:11:22 面試筆試 我要投稿
  • 相關(guān)推薦

oracle筆試題及答案

  oracle筆試題及答案

oracle筆試題及答案

  1.創(chuàng)建表空間neuspace,數(shù)據(jù)文件命名為neudata.dbf,存放在d:\data目錄下,文件大小為200MB,設(shè)為自動(dòng)增長,增量5MB,文件最大為500MB。(8分)

  答:create tablespace neuspace datafile ‘d:\data\neudata.dbf’ size 200m auto extend on next 5m maxsize 500m;

  2. 假設(shè)表空間neuspace已用盡500MB空間,現(xiàn)要求增加一個(gè)數(shù)據(jù)文件,存放在e:\appdata目錄下,文件名為appneudata,大小為500MB,不自動(dòng)增長。(5分)

  答:alter tablespace neuspace add datafile ‘e:\appdata\appneudata.dbf’ size 500m;

  3. 以系統(tǒng)管理員身份登錄,創(chuàng)建賬號(hào)tom,設(shè)置tom的默認(rèn)表空間為neuspace。為tom分配connect和resource系統(tǒng)角色,獲取基本的系統(tǒng)權(quán)限。然后為tom分配對用戶scott的表emp的select權(quán)限和對SALARY, MGR屬性的update權(quán)限。(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分)

屬性

類型(長度)

默認(rèn)值

約束

含義

CLASSNO 數(shù)值 (2) 主鍵 班級(jí)編號(hào)
CNAME 變長字符 (10) 非空 班級(jí)名稱

屬性

類型(長度)

默認(rèn)值

約束

含義

STUNO 數(shù)值 (8) 主鍵 學(xué)號(hào)
SNAME 變長字符 (12) 非空 姓名
SEX 字符 (2) 性別
BIRTHDAY 日期 生日
EMAIL 變長字符 (20) 唯一 電子郵件
SCORE 數(shù)值 (5, 2) 檢查 成績
CLASSNO 數(shù)值 (2) 外鍵,關(guān)聯(lián)到表CLASS的CLASSNO主鍵 班級(jí)編號(hào)

  答: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 EMAIL SCORE CLASSNO
從stuseq取值 tom 1979-2-3 14:30:25 tom@163.net 89.50 1
從stuseq取值 jerry 默認(rèn)值 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的數(shù)據(jù),將所有一班的學(xué)生成績加10分。(4分)

  答:student set score=score+10 where classno=1;

  9. 刪除表student的數(shù)據(jù),將所有3班出生日期小于1981年5月12日的記錄刪除。(4分)

  答: from student where classno=3 and birthday > ’12-5月-81’;

  10. 完成以下SQL語句。(40分)

  (1) 按班級(jí)升序排序,成績降序排序,查詢student表的所有記錄。

  答:select * from student order by classno, score desc;

  (2) 查詢student表中所有二班的成績大于85.50分且出生日期大于1982-10-31日的男生的記錄。

  答:select * from student where classno=2 and score>85.50 and birthday < ’31-10月-82’ and sex=’男’;

  (3) 查詢student表中所有三班成績?yōu)榭盏膶W(xué)生記錄。

  答:select * from student where classno=3 and score is null;

  (4) 表student與class聯(lián)合查詢,要求查詢所有學(xué)生的學(xué)號(hào),姓名,成績,班級(jí)名稱。(使用oracle與SQL 99兩種格式)

  答:select s.stuno, s.sname, s.score, c.cname from student s, class c where s.classno=c.classno;

  (5) 按班級(jí)編號(hào)分組統(tǒng)計(jì)每個(gè)班的人數(shù),最高分,最低分,平均分,并按平均分降序排序。

  答:select classno, count(*), max(score), min(score), avg(score) from student group by classno order by avg(score) desc;

  (6) 查詢一班學(xué)生記錄中所有成績高于本班學(xué)生平均分的記錄。

  答:select * from student where classno=1 and score > (select avg(score) from student where classno=1);

  (7) 統(tǒng)計(jì)二班學(xué)生中所有成績大于所有班級(jí)平均分的人數(shù)。

  答:select count(*) from student where classno=2 and score > all (select avg(socre) from student group by classno);

  (8) 查詢平均分最高的班級(jí)編號(hào)與分?jǐn)?shù)。

  答:select classno, avg(score) from student group by classno having avg(score) = (select max(avg(score)) from student group by classno);

  (9) 查詢所有學(xué)生記錄中成績前十名的學(xué)生的學(xué)號(hào)、姓名、成績、班級(jí)編號(hào)。

  答: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;

[next]

  1、比較大小

  select decode(sign(變量1-變量2),-1,變量1,變量2) from dual; –取較小值

  sign()函數(shù)根據(jù)某個(gè)值是0、正數(shù)還是負(fù)數(shù),分別返回0、1、-1

  例如:

  變量1=10,變量2=20

  則sign(變量1-變量2)返回-1,decode解碼結(jié)果為“變量1”,達(dá)到了取較小值的目的。

  2、表、視圖結(jié)構(gòu)轉(zhuǎn)化

  現(xiàn)有一個(gè)商品銷售表sale,表結(jié)構(gòu)為:

  month    6)      –月份

  sell    number(10,2)   –月銷售金額

  現(xiàn)有數(shù)據(jù)為:

  200001  1000

  200002  1100

  200003  1200

  200004  1300

  200005  1400

  200006  1500

  200007  1600

  200101  1100

  200202  1200

  200301  1300

  想要轉(zhuǎn)化為以下結(jié)構(gòu)的數(shù)據(jù):

  year   4)      –年份

  month1  number(10,2)   –1月銷售金額

  month2  number(10,2)   –2月銷售金額

  month3  number(10,2)   –3月銷售金額

  month4  number(10,2)   –4月銷售金額

  month5  number(10,2)   –5月銷售金額

  month6  number(10,2)   –6月銷售金額

  month7  number(10,2)   –7月銷售金額

  month8  number(10,2)   –8月銷售金額

  month9  number(10,2)   –9月銷售金額

  month10  number(10,2)   –10月銷售金額

  month11  number(10,2)   –11月銷售金額

  month12  number(10,2)   –12月銷售金額

  結(jié)構(gòu)轉(zhuǎn)化的SQL語句為:

  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語句的用法?

  Oracle用法很簡單:

  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和的區(qū)別?

  1、TRUNCATE在各種表上無論是大的還是小的都非?臁H绻蠷OLLBACK命令DELETE將被撤銷,而TRUNCATE則不會(huì)被撤銷。

  2、TRUNCATE是一個(gè)DDL語言而DELETE是DML語句,向其他所有的DDL語言一樣,他將被隱式提交,不能對TRUNCATE使用ROLLBACK命令。

  3、TRUNCATE將重新設(shè)置高水平線和所有的索引。在對整個(gè)表和索引進(jìn)行完全瀏覽時(shí),經(jīng)過TRUNCATE操作后的表比DELETE操作后的表要快得多。

  4、TRUNCATE不能觸發(fā)觸發(fā)器,DELETE會(huì)觸發(fā)觸發(fā)器。

  5、不能授予任何人清空他人的表的權(quán)限。

  6、當(dāng)表被清空后表和表的索引講重新設(shè)置成初始大小,而則不能。

  7、不能清空父表。

  81、 表空間如何擴(kuò)展?并用語句寫出?

  兩種擴(kuò)展方式:

  a) 增加數(shù)據(jù)文件

  alter tablespace tablespace_name add datafile ‘’ xxMB

  b) 擴(kuò)展數(shù)據(jù)文件大小

  alter database datafile ‘’ resize newMB

  82、 表空間區(qū)管理方式?哪種方式現(xiàn)在是推薦使用的?

  a) 字典管理方式

  extent management dictionary;默認(rèn)方式

  b) 本地管理方式

  extent management local[autoallocate/uniform xxmb];

  83、 用什么函數(shù)獲得日期?和日期中的月,日,年

  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、 分區(qū)表的應(yīng)用?

  a) 一個(gè)分區(qū)表有一個(gè)或多個(gè)分區(qū),每個(gè)分區(qū)通過使用范圍分區(qū)、散列分區(qū)、或組合分區(qū)分區(qū)的行

  b) 分區(qū)表中的每一個(gè)分區(qū)為一個(gè)段,可各自位于不同的表空間中

  c) 對于同時(shí)能夠使用幾個(gè)進(jìn)程進(jìn)行查詢或操作的大型表分區(qū)非常有用

  85、 談?wù)勊饕挠梅霸?

  索引是若干數(shù)據(jù)行的關(guān)鍵字的列表,查詢數(shù)據(jù)時(shí),通過索引中的關(guān)鍵字可以快速定位到要訪問的記錄所在的數(shù)據(jù)塊,從而大大減少讀取數(shù)據(jù)塊的I/O次數(shù),因此可以顯著提高性能。

  86、 存儲(chǔ)過程的應(yīng)用,如何既有輸入又有輸出?

  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ā)生的異常有哪些?

  常用預(yù)定義例外

  CURSOR_ALREADY_OPEN — ORA-06511 SQLCODE = -6511 游標(biāo)已經(jīng)打開

  DUP_VAL_ON_INDEX — ORA-00001 SQLCODE = -1 違反唯一性約束

  INVALID_CURSOR — ORA-01001 SQLCODE = -1001 非法游標(biāo)操作

  INVALID_NUMBER — ORA-01722 SQLCODE = -1722 字符向數(shù)字轉(zhuǎn)換失敗

  LOGIN_DENIED — ORA-01017 SQLCODE = -1017

  NO_DATA_FOUND — ORA-01403 SQLCODE = +100 沒有找到數(shù)據(jù)

  NOT_LOGGED_ON — ORA-01012 SQLCODE = -1012 沒有連接到數(shù)據(jù)庫

  PROGRAM_ERROR — ORA-06501 SQLCODE = -6501 內(nèi)部錯(cuò)誤

  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 數(shù)值轉(zhuǎn)換錯(cuò)誤

  ACCESS_INTO_NULL試圖為NULL對象的屬性賦值

  ZERO_DIVIDE — ORA-01476 SQLCODE = -1476 被零除

  OTHERS — 其它任何錯(cuò)誤的處理

  88、 如何使用異常?

  在oracle中有三種類型的異常。預(yù)定義的異常 非預(yù)定義的異常 用戶定義的異常 第二種非預(yù)定義的異常是與特定的oracle錯(cuò)誤關(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(‘重復(fù)項(xiàng)編號(hào)-主鍵沖突’); end

  第一種的使用方法:exception

  when 異常名稱 then

  異常處理代碼;

  第三種的用法:if 條件 then

  raise_application_error(-20000“““`-20999,提示信息);

  end if;

  89、優(yōu)化的策略一般包括:

  • 內(nèi)存優(yōu)化

  • 操作系統(tǒng)優(yōu)化

  • 數(shù)據(jù)存儲(chǔ)的優(yōu)化

  • 網(wǎng)絡(luò)優(yōu)化等方法

  具體到不同的數(shù)據(jù)庫涉及到要調(diào)整不同的數(shù)據(jù)庫配置文件、不同的操作系統(tǒng)參數(shù)、網(wǎng)絡(luò)參數(shù)等等, 不同的數(shù)據(jù)庫不同

【oracle筆試題及答案】相關(guān)文章:

報(bào)社筆試題目及答案03-18

現(xiàn)代教育技術(shù)試題及答案03-02

史上最全軟件筆試題目及答案08-21

職業(yè)心理在線測試題及答案06-05

園林綠化面試題及答案03-03

民生銀行筆試題目及答案03-17

護(hù)士面試筆試?荚囶}及答案11-17

職業(yè)生涯規(guī)劃考試試題及答案03-08

2023常見醫(yī)院面試題目與參考答案08-10

2017中職職業(yè)生涯規(guī)劃試題及答案03-30