1、
儲存過程和函式的區別。
(1)、儲存過程是作為pl/sql語句執行,而函式是作為表示式的一部分呼叫;
(2)、儲存過程在規格說明中不包含return語句,而在函式的規格說明這包含return子句;
(3)、儲存過程不返回值,而函式必須返回值;
(4)、在儲存過程中可以包含return語句,但不返回任何值,他只表示退出儲存過程,而函式中必須包含乙個return語句;
2、觸發器分為事前觸發和事後觸發,這兩種觸發有
何區別。語句級觸發和行級觸發有何區別。
事前觸發是在資料沒有寫入資料庫時就觸發,而事後觸發是在把資料寫入資料庫後再觸發
語句級觸發值所有的相同的語句只觸發一次,而行級觸發是每執行一條語句就觸發一次。
3、根據students表(stuid,stuname,stu***,stuage,stutel)編寫乙個儲存過程,將students表中的學生id號傳遞給這一過程,並向呼叫應用程式返回學生的姓名和**號碼。再編寫乙個具有過程呼叫的匿名塊。
儲存過程
create or replace procedure pro_stu(id in number,stuname out varchar2,
stutel out varchar2) as
begin
select a.stuname,a.stutel into stuname,stutel from students a
where a.stuid=id;
end pro_stu;
匿名塊:
declare
stuid number(3);
stuname varchar2(12);
stutel varchar2(15);
begin
stuid:=&stuid;
pro_stu(stuid,stuname,stutel);
dbms_output.put_line('姓名:' || stuname);
exception
when no_data_found then
dbms_output.put_line('未找到符合條件的資料!!');
end;
4、在顯示游標上可以執行哪些操作?舉例說明每一種語句的作用。
*宣告游標
*開啟游標
*提取游標
*關閉游標
5、集合運算子intersect的用途是什麼?
可以用來查詢兩個查詢結果中相同的部分
6、找出與john smith在相同的部門工作的雇員資訊。
select a.* from employee a where deptid =(
select b.deptid from employee b where b.fname='john' and b.lname='smith') and
a.fname<>'john' and a.lname<>'smith'
7、通過乙個外部連線,顯示雇員名和部門資訊。
select a.fname||'--'||a.lname as 雇員名,b.* from employee a,dept b
where a.deptid(+)=b.deptid;
8、抽取employee表中按fname的字母順序的第2條記錄開始的3條記錄的sql語句。
select a.lname from (select rownum as rn, b.* from employee b order by
b.fname) a where rn>=2 and rn<5
9、insert all和insert first語句的用途是什麼?
insert all 是向所以符合條件的表中插入資料;
insert first 當有多個符合條件的時只向第乙個中插入資料
10、使用多層子查詢顯示finance部門的雇員的親屬資訊。
select a.* from dependent a where a.employeeid in(
select b.employeeid from employee b where b.deptid in(
select c.deptid from dept c where c.detpname='finance'))
11、編寫乙個pl/sql 程式,包括兩個變數,分別用於姓和名,顯示完整的姓名,姓和名之間用逗號和空格分隔開。
declare
familyname employee.fname%type;
name employee.lname%type;
cursor cur_emp is
select a.fname,a.lname from employee a where 1 = 1;
begin
open cur_emp;
fetch cur_emp into familyname,name;
while cur_emp%found
loop
dbms_output.put_line('員工的姓名為:'||familyname||', '||name);
fetch cur_emp into familyname,name;
end loop;
end;
12、使用for迴圈,以相反的順序顯示10~1。
declare
begin
for num in reverse 1 .. 10
loop
dbms_output.put_line(num);
end loop;
end;
13、編寫乙個pl/sql塊,要求使用者輸入第乙個數字、第二個數字和算術運算子(+、-、*、/)。如果運算子無效,則丟擲並處理乙個使用者定義的異常。如果第二個數字是零,而且運算子是/,則處理zero_divide預定義的伺服器異常。
declare
fnum number(4);
snum number(4);
oper varchar2(4);
result number(6);
nooper exception;
begin
fnum:=&fnum;
snum:=&snum;
oper:='&oper';
result:=
case
when '+' then fnum+snum;
when '_' then fnum-snum;
when '*' then fnum*snum;
when '/' then fnum/snum;
else raise nooper;
dbsm_output.put_line(fnum || oper|| snum||'='||result);
exception
when nooper then
dbsm_output.put_line('你輸入了非法操作符!!');
when
zero_divide then
dbms_output.put_line('除數不能為零!!');
end;
14、表結構以及資料如下:
create table 表
(id int, 日期 varchar
2(11), 單據 char(3))
insert into 表 (id , 日期 , 單據 ) values ( 1 , '2004-08-02' , '001' );
insert into 表 (id , 日期 , 單據 ) values ( 2 , '2004-09-02' , '001' );
insert into 表 (id , 日期 , 單據 ) values ( 3 , '2004-10-02' , '002' );
insert into 表 (id , 日期 , 單據 ) values ( 4 , '2004-09-02' , '002' );
要求:設計乙個查詢,返回結果如下:
id 日期 單據
---------- ----------- ---
1 2004-08-02 001
4 2004-09-02 002
即對於每個單據號,返回日期最小的行。
15、表內容:
2005-05-09
勝2005-05-09
勝2005-05-09
負2005-05-09
負2005-05-10
勝2005-05-10
負2005-05-10
負如果要生成下列結果
, 該如何寫
sql語句?勝
負2005-05-09 2 2
2005-05-10 1 2sql
指令碼:------------------------------------------
create table #tmp(rq varchar
2(10),shengfu char(2))
insert into tmp values('2005-05-09','勝')
insert into tmp values('2005-05-09','勝')
insert into tmp values('2005-05-09','負')
insert into tmp values('2005-05-09','負')
insert into tmp values('2005-05-10','勝')
insert into tmp values('2005-05-10','負')
insert into tmp values('2005-05-10','負')
select a.rq,a.負,b.勝 from (select rq, count(*) as 負 from tmp where shengfu='負' group by rq) a
join
(select rq, count(*) as 勝 from tmp where shengfu='勝' group by rq) b
ona.rq=b.rq
基礎面試題
答 物件導向的特徵主要有以下幾個方面 1.抽象 抽象就是忽略乙個主題中與當前目標無關的那些方面,以便更充分地注意與當前目標有關的方面。抽象並不打算了解全部問題,而只是選擇其中一部分,暫時不用部分細節。抽象包括兩個方面,一是過程抽象 二是資料抽象。2.繼承 繼承是一種聯結類的層次模型,並且允許和鼓勵類...
基礎面試題
公有方法。整個程式都可以訪問 私有方法。只有這個類可以訪問 受保護級別。這個包中的類及子類都可訪問 無修飾符時只向同乙個包中的類訪問 許可權限制 private default protected public 被public修飾的變數 public string s 被private修飾的變數 p...
面試題(十)Oracle
oracle面試問題 技術篇 1.解釋冷備份和熱備份的不同點以及各自的優點 解答 熱備份針對歸檔模式的資料庫,在資料庫仍舊處於工作狀態時進行備份。而冷備份指在資料庫關閉後,進行備份,適用於所有模式的資料庫。熱備份的優點在於當備份時,資料庫仍舊可以被使用並且可以將資料庫恢復到任意乙個時間點。冷備份的優...