Oracle面試題及答案整理

來源:互聯網
上載者:User

1、表:table1(FId,Fclass,Fscore),用最高效最簡單的SQL列出各班成績最高的列表,顯示班級,成績兩個欄位。

select fclass,max(fscore) from table1 group by fclass,fid

2、有一個表table1有兩個欄位FID,Fno,字都非空,寫一個SQL語句列出該表中一個FID對應多個不同的Fno的紀錄。
類如:
101a1001
101a1001
102a1002
102a1003
103a1004
104a1005
104a1006
105a1007
105a1007
105a1007
結果:
102a1002
102a1003
104a1005
104a1006

select t2.* from table1 t1, table1 t2 where t1.fid = t2.fid and t1.fno <> t2.fno;

3、有員工表empinfo
(
Fempno varchar2(10) not null pk,
Fempname varchar2(20) not null,
Fage number not null,
Fsalary number not null
);
假如資料量很大約1000萬條;寫一個你認為最高效的SQL,用一個SQL計算以下四種人:
fsalary>9999 and fage > 35
fsalary>9999 and fage < 35
fsalary <9999 and fage > 35
fsalary <9999 and fage < 35
每種員工的數量;
select sum(case when fsalary > 9999 and fage > 35
then 1
else 0end) as "fsalary>9999_fage>35",
sum(case when fsalary > 9999 and fage < 35
then 1
else 0
end) as "fsalary>9999_fage<35",
sum(case when fsalary < 9999 and fage > 35
then 1
else 0
end) as "fsalary<9999_fage>35",
sum(case when fsalary < 9999 and fage < 35
then 1
else 0
end) as "fsalary<9999_fage<35"
from empinfo;
4、表A欄位如下
month person income
月份 人員 收入
要求用一個SQL語句(注意是一個)的處所有人(不區分人員)每個月及上月和下月的總收入
要求列表輸出為
月份 當月收入 上月收入 下月收入
MONTHS PERSON INCOME
---------- ---------- ----------200807 mantisXF 5000200806 mantisXF2 3500200806 mantisXF3 3000200805 mantisXF1 2000200805 mantisXF6 2200200804 mantisXF7 1800200803 8mantisXF 4000200802 9mantisXF 4200200802 10mantisXF 3300200801 11mantisXF 4600200809 11mantisXF 6800
11 rows selected
select months, max(incomes), max(prev_months), max(next_months)
from (select months,
incomes,
decode(lag(months) over(order by months),
to_char(add_months(to_date(months, 'yyyymm'), -1), 'yyyymm'), lag(incomes) over(order by months), 0) as prev_months, decode(lead(months) over(order by months), to_char(add_months(to_date(months, 'yyyymm'), 1), 'yyyymm'), lead(incomes) over(order by months), 0) as next_months from (select months, sum(income) as incomes from a group by months) aa) aaagroup by months;

MONTHS MAX(INCOMES) MAX(PREV_MONTHS) MAX(NEXT_MONTHS)---------- ------------ ---------------- ----------------200801 4600 0 7500200802 7500 4600 4000200803 4000 7500 1800200804 1800 4000 4200200805 4200 1800 6500200806 6500 4200 5000200807 5000 6500 0200809 6800 0 0

5,表B
C1 c2
2005-01-01 1
2005-01-01 3
2005-01-02 5

要求的處資料
2005-01-01 4
2005-01-02 5
合計 9
試用一個Sql陳述式完成。

 

select nvl(to_char(t02,'yyyy-mm-dd'),'合計'),sum(t01)from test
group by rollup(t02)

6,資料庫1,2,3 範式的概念與理解。

7,簡述Oracle行觸發器的變化表限制表的概念和使用限制,行觸發器裡面對這兩個表有什麼限制。

8、oracle暫存資料表有幾種。
暫存資料表和普通表的主要區別有哪些,使用暫存資料表的主要原因是什嗎?

9,怎麼實現:使一個會話裡面執行的多個過程函數或觸發器裡面都可以訪問的全域變數的效果,並且要實現會話間隔離?

10,aa,bb表都有20個欄位,且記錄數量都很大,aa,bb表的X欄位(非空)上有索引,
請用SQL列出aa表裡面存在的X在bb表不存在的X的值,請寫出認為最快的語句,並解譯原因。

11,簡述SGA主要組成結構和用途?

  • 1
  • 2
  • 下一頁

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.