ݷʱ : 2025/1/24 14:01:27һ µȫĶ
end;
3))FORʽ
for in ֵ..ֵ loop ִ䣻 end loop; eg:
--1ӵ100 declare
v_I int := 1; v_Sum int := 0; begin
for v_I in 1..100 loop v_Sum := v_Sum + v_I; end loop;
dbms_output.put_line(v_Sum); exception
when others then
dbms_output.put_line('error!'); end;
4))caseʽ 1)))һ
CASE search_expression
WHEN expression1 THEN result1 WHEN expression2 THEN result2 ...
WHEN expressionN THEN resultN ELSE default_result END eg:
select scott.emp.empno, scott.emp.ename, case scott.emp.empno when 7369 then 'aa' when 7499 then 'bb' when 7521 then 'cc' when 7566 then 'dd' when 7654 then 'ee' else 'ff'
end A --ֶ from scott.emp
41
2))) CASE
WHEN condition1 THEN result1 WHEN condition2 THEN result2 ...
WHEN conditionN THEN resultN ELSE default_result END eg:
select scott.emp.empno, scott.emp.ename, case
when scott.emp.empno=7369 then 'aa' when scott.emp.empno=7499 then 'bb' when scott.emp.empno=7521 then 'cc' when scott.emp.empno=7566 then 'dd' when scott.emp.empno=7654 then 'ee' else 'ff'
end A --ֶ from scott.emp
2.ؼ%TYPE%ROWTYPEĺʲô ⣺
1%type
ıֱӳ䵽ݿijһϣôͿʹ%typeؼֽêϡ
磺declare v_ename scott.emp.ename%type; ͷ仯ʱ˷Ե÷dz
еijȣôêϵбԶ䳤ȣ
ǽv_enameΪvarchar2(10),ôempеenameз仯ʱ ǵֶv_enamΪemp.enameͬݳȣ ʹêͺͻԶе 2%rowtype
%rowtype%typeƣêУêijһУ
3δûԶ쳣 ⣺
ʹRAISE_APPLICATION_ERROR úǽӦóרеĴӷתﵽͻӦó(ϵSQLPLUSǰ̨)
42
ʮһ 洢뺯
һѡ
1.洢̱( B )С
A.ϵͳ B.ݿ C.ڴ D.ݱ
2.ĸSQL*PLUSֱӵһ̣ D A.RETURN B.CALL C.SET D.EXEC
3.ЩǹвЧģʽ C A.IN B.IN OUT C.OUT IN D.OUT
4.һΪTESTḶ́3һΪP_NUM1,ڶΪP_NUM2ΪP_NUM33ģʽIN,P_NUM1NUMBER, P_NUM2VARCHAR2, P_NUM3VARCHAR2,һǸù̵Чã D
A.TEST(1010,P_NUM3>=abc,P_num2>=bcd) B. TEST(P_NUM1>=1010,P_num2=>abc,bcd) C.TEST(P_NUM1=>1010,abc,bcd) D.
5.ͷеRETURNǣ A A.ص
B.ֵĴС C.ú
D.ͷʹRETURN
6.ڳаһ̣ûڳ淶̣ôᱻΪǣ D
A.Ƿ B.е C. D.˽е
7.ĺĸܳɹصã D
43
CREATE OR REPLACE FUNCTION Calc_Sum(Addend_x number,Addend_Y number) Return number As
Sum number; BEGIN
Sum:=Addend_x+Addend_y; Return Sum; END;
A.Calc_Sum
B.EXECUTE Calc_Sum(45) C.EXECUTE Calc_Sum(23,12) D.Sum:=Calc_Sum(23,12)
8.У B ʱ̾ͬƣ A.ƻͬʱ B.Ͳͬʱ C.ͺƲͬʱ D.Ͳͬʱ
9.FUNCTIONУУ A RETURN䡣 A0 B.1 C.2 D.3
10.ݰairlineкbook_ticket䶨£ FUNCTION book_ticketpara1 CHARRETURN DATE IS У D ȷصøݰĺ A. DECLARE
value1 CHAR10 BEGIN ----
value1 = airline.book_ticket(10); B. DECLARE
value1 CHAR10 BEGIN ----
value1 = airline.book_ticket(10); C. DECLARE value1 DATE BEGIN ----
value1 = airline.book_ticket(10); D. DECLARE value1 DATE
44