某運營商的oracle筆試題

    今年初本人去某運營商應聘BI開發一職,作了一份筆試題,是本人見過的最有水平的oracle試題,題目很簡單,任何人都知道怎麼作,但可否作出來就不知道了,見下(時間長了,試題記得不是很清楚了):sql

一.用plsql塊實如今一個表中插入100000條數據,要求每1000條提交一次,表名自定。數據庫

--很簡單,見下(存儲過程):
create or replace procedure p_circle_commit
as
begin
    for i in 1..100000 loop
     -- dbms_output.put_line(i);
      insert into test(testid) values(i);
      if mod(i,1000)=0 then
         commit;
         dbms_output.put_line('commit');
      end if;
    end loop;oracle

 end;
/app

---執行6.4秒ide

----若是採用批量提交,只要3.3秒:oop

create or replace procedure p_circle_commit
as
begin
    for i in 1..100000 loop
     -- dbms_output.put_line(i);
      insert into test(testid) values(i);
     end loop;
     commit;  --批量提交
 end;
/測試

 

二. 有3個表 A(userid(用戶ID),time(時間),fee(話費)),B(userid(用戶ID),time(時間)),  C(userid(用戶ID),fee(話費))各有1000萬的數據, 3個表的userid是相同的,要求用B表的time字段,  C表的fee字段更新A表的相應字段,用存儲過程實現。ci

--基本實現思路(沒有條件測試,估計很難實現,有條件也要謹慎,充分考慮效率、表空間、回滾段是否夠用等):
1.  要用B、 C的數據更新A,先取userid相同的數據,從A中取userid、B取time、C取fee字段的值,加到新臨時表表中
如:create table tempA-1 as select a.userid,b.time,c.fee
                            from A,B,C  where a.userid = b.userid and a.userid = c.userid;開發

2. 再取A表userid與B、C表userid不相同的數據,直接從A表中取(即B、C表中沒有的數據不用更新),再建臨時表
如:create table tempA-2 as select a.userid,a.time,a.fee
                            from A,B,C  where a.userid != b.userid and a.userid != c.userid;
3. 把小臨時表的數據加到大臨時表中:
   Insert into tempA-1(userid,time,fee)   select a.userid,a.time,a.fee tempA-2  a where a.time >= '時間值';it

4. 最後將A表與 tempA-1互換名稱。

三。有個上百萬的用戶信息表,裏面有部分重複號碼,請刪除重複的號碼,用存儲過程實現。
--本人簡單利用一個錄音表來實現沒有寫存儲過程,6萬數據很短期解決,100萬數據須要多長時間沒有測試。
1. 創建表:
create table RECORDFILE
(
  SERIALNO   VARCHAR2(200),
  FILEPATH   VARCHAR2(400),
  PARTID     VARCHAR2(40),
  STAFFNO    VARCHAR2(100),
  RECORDTIME DATE
);

--使用循環加入6萬數據
commit;

2.建立臨時表 ,在6萬多數據中查詢staffno 不重複的數據,不到1秒時間。
create table recordfile_temp as 
select * from recordfile t
where t.serialno in (select max(r.serialno) from recordfile r group by r.staffno);

--truncate掉原表:
truncate table recordfile;

--數據加到原表中,drop掉臨時表:
insert into /*+ append */ recordfile select * from recordfile_temp;
commit;

以上僅供參考,不足之處請諒解! 

        結果是本人沒有經過筆試,哪位能在40分鐘能作完(原筆試1小時,還有一些BI基本知識、plsql的內容),能夠去運營商那挑戰T數量級的應用開發(絕對比那些小數據庫開發刺激的多了)。

相關文章
相關標籤/搜索