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ÏàËÆ£»²»¹ýËü½«±äÁ¿Ãª¶¨µ½±íµÄËùÓÐÁУ¬¶ø²»ÊÇ궨µ½Ä³Ò»ÁУ»
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_NUM3¡£3¸ö²ÎÊýµÄģʽ¶¼ÊÇIN,P_NUM1²ÎÊýµÄÊý¾ÝÀàÐÍÊÇNUMBER, P_NUM2²ÎÊýµÄÊý¾ÝÀàÐÍÊÇVARCHAR2, P_NUM3²ÎÊýµÄÊý¾ÝÀàÐÍÊÇVARCHAR2,ÏÂÁÐÄÄÒ»¸öÊǸùý³ÌµÄÓÐЧµ÷Óã¿£¨ 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Óï¾ä¡£ A£®0 B.1 C.2 D.3
10.Êý¾Ý°üairlineÖÐÓк¯Êýbook_ticket£¬Æ䶨ÒåÈçÏ£º FUNCTION book_ticket£¨para1 CHAR£©RETURN DATE IS ÏÂÁУ¨ D £©³ÌÐò¶ÎÕýÈ·µØµ÷ÓøÃÊý¾Ý°üµÄº¯Êý¡£ A. DECLARE
value1 CHAR£¨10£©£» BEGIN ----
value1 £º= airline.book_ticket(10); B. DECLARE
value1 CHAR£¨10£©£» BEGIN ----
value1 £º= airline.book_ticket(¡®10¡¯); C. DECLARE value1 DATE£» BEGIN ----
value1 £º= airline.book_ticket(10); D. DECLARE value1 DATE£»
44