OCPÈÏÖ¤¿¼ÊÔÖ¸ÄÏ£¨10£©£ºÊ¹ÓÃPL/SQL½øÐÐOracle±à³Ì
1¡¢±à³ÌÓïÑÔÓëOracleÊý¾Ý¿â
1.1¡¢´æ´¢µÄÓëÄäÃûµÄPL/SQL³ÌÐò¿é
Óë´æ´¢µÄPL/SQL³ÌÐò¿éÏà±È£¬ÄäÃûµÄPL/SQL³ÌÐò¿éЧÂʽϵͣ¬´ËÍâÓÉÓÚ¿ÉÄÜÔÚ¶ą̀»úÆ÷Öй«²¼Ô´´úÂ룬»¹»áÒý·¢¹ÜÀíÎÊÌâ¡£
1.2¡¢PL/SQL¶ÔÏó
PL/SQL¶ÔÏó¾ßÓÐÏÂÁÐ5ÖÖÀàÐÍ£º
¹ý³Ì
º¯Êý
³ÌÐò°ü
³ÌÐò°üÖ÷Ìå
´¥·¢Æ÷
2¡¢¹ý³Ì¡¢º¯ÊýÒÔ¼°³ÌÐò°ü
2.1¡¢¹ý³ÌÓ뺯Êý
¹ý³Ì£¨Procedure£©ÊÇÒ»¸öÖ´ÐÐijЩ¶¯×÷µÄ´úÂë¿é¡£ÒªÔËÐÐÒ»¸ö¹ý³Ì£¬¼È¿ÉÒÔÔÚPL/SQL³ÌÐò¿éÄÚ²¿µ÷ÓÃÕâ¸ö¹ý³Ì£¬Ò²¿ÉÒÔʹÓý»»¥Ê½µÄEXECUTEÃüÁî¡£
º¯Êý£¨Function£©Óë¹ý³ÌµÄ¸ÅÄîÏàËÆ£¬µ«²¢²»¾ßÓÐOUTÐÍʵ²Î£¬²¢ÇÒÎÞ·¨Ê¹ÓÃEXECUTEÃüÁîÀ´µ÷Ó᣺¯ÊýÓ¦µ±Í¨¹ýRETURN·µ»ØÒ»¸öÖµ¡£
Èç¹ûʹÓõÄÊÇCREATEÃüÁî¶ø²»ÊÇCREATE OR REPLACEÃüÁÄÇôÔÚÖ¸¶¨¶ÔÏóÒÑ´æÔÚµÄÇé¿öϱØÐëÏÈɾ³ýÕâ¸ö¶ÔÏó¡£
º¯Êý£º
?[Copy to clipboard]View Code PLSQL
SQL> create or replace function odd_even(v1 number)
2 return varchar2
3 as
4 begin
5 if
6 mod(v1,2) = 0
7 then
8 return 'even';
9 else
10 return 'odd';
11 end if;
12 end odd_even;
13 /
Function created.
SQL> select odd_even(8) from dual;
ODD_EVEN(8)
-------------------------------------------------------------------
even
SQL> select odd_even(9) from dual;
ODD_EVEN(9)
-------------------------------------------------------------------
odd
¹ý³Ì£º
?[Copy to clipboard]View Code PLSQL
SQL> conn system/oracle
Connected.
SQL> create table integers (
2 C1 number(2),
3 C2 varchar2(5));
Table created.
SQL> create or replace procedure ins_ints(v1 in number)
2 as
3 begin
4 for i in 1..v1 loop
5 insert into integers values (i, odd_even(i));
6 end loop;
7 end ins_ints;
8 /
Procedure created.
SQL> execute ins_ints(5);
PL/SQL procedure successfully completed.
SQL> select * from integers;
C1 C2
---------- -----
1 odd
2 even
3 odd
4 even
5 odd
2.2¡¢³ÌÐò°ü
³ÌÐò°ü£¨Package£©Óɹ淶ºÍÖ÷ÌåÁ½¸ö¶ÔÏó×é³É¡£
ʹÓÃCREATE PACKAGEÃü
Ïà¹ØÎĵµ£º
¹¤¾ß£º
Sybase PowerDesigner 12.5
Microsoft SQL Server 2005
µÚÒ»²½£º¸ÅÒªÉè¼Æ
´ò¿ªPowerDesignerÈí¼þ£¬Éè¼Æ“¸ÅÄîÊý¾ÝÄ£ÐÍ”(Conceptual Data Model)£º
ͼ1
Éè¼Æ±í½á¹¹£º
ͼ2
ÔÚÉè¼ÆÊôÐÔ(×Ö¶Î)µÄʱºò£¬Èý¸ö×Öĸ(M¡¢P¡¢D)·Ö±ð±íʾ£º
M£ºÊÇ·ñΪ¿Õ;(√±íʾ²»ÔÊÐíΪ¿Õ)
P£ºÊÇ·ñ뻅 ......
×î½üÓöµ½Ò»¸öÏîÄ¿£¬¿Í»§ÔÚ×ܲ¿Â¼ÈëÐÅÏ¢ºó£¬Êý¾ÝÐèҪͬ²½µ½ÏÂÊôµÄÈô¸É¸ö×ÓϵͳÖС£ÏÖÔÚ×ܲ¿µ¥¶ÀʹÓÃÒ»¸öÊý¾Ý¿â£¬ÏÂÊôµ¥Î»¸÷×ÔʹÓÃ×Ô¼ºµÄÊý¾Ý¿â¡£
¶ÔÓÚÕâ¸öÎÊÌ⣬Ïëµ½Á˼¸¸ö½â¾ö·½°¸£º
1¡¢×Ô¼ºÐ´´úÂë½â¾ö¡£¶¨ÒåºÃ·ÃÎÊÿ¸öÊý¾ ......
1. ¸´ÖƱí½á¹¹
Sql´úÂë
1. select * into B from A where 1=0;
select * into B from A where 1=0;
2.¸´ÖƱí¼Ç¼ ¸´ÖÆijЩ×Ö¶Î
Sql´úÂë
1. insert into B(a, b, c) select d, e, f from A;
insert into B(a, b, c) select d, e, f from A;
¸´Ö ......
SQLÌṩÁËËÄÖÖÄ£ºýÆ¥Å䷽ʽ
1£¬%£º±íʾÈÎÒâ0¸ö»ò¶à¸ö×Ö·û¡£¿ÉÆ¥ÅäÈÎÒâÀàÐͺͳ¤¶ÈµÄ×Ö·û£¬ÓÐЩÇé¿öÏÂÈôÊÇÖÐÎÄ£¬ÇëÔËÓÃÁ½¸ö°Ù·ÖºÅ£¨%%£©±íʾ¡£
±ÈÈç SELECT * from [user] WHERE u_name LIKE '%Èý%'
½«»á°Ñu_nameΪ“ÕÅÈý”£¬“ÕÅèÈý”¡¢“Èý½Å蔣¬“ÌÆÈý²Ø”µÈµÈÓГÈý& ......
ÕâÊÇCSDNÂÛ̳ÀïÃæµÄÒ»¸öÌû×Ó£¬×÷ÕßÊÇ°®Ð¾õÂÞ.ع»ª¡£¸Ð¾õ±È½ÏÈ«Ã棬¾ÍÕûÀíÏÂÀ´ÁË£¬Áô×÷ÒÔºó²Î¿¼±¸Óá£ÔÚ´Ë£¬Ôڴ˸Ðл±¾ÎĵÄ×÷Õß¡£
/*
±êÌ⣺һ¸öÏîÄ¿Éæ¼°µ½µÄ50¸öSqlÓï¾ä(ÕûÀí°æ)
×÷Õߣº°®Ð¾õÂÞ.ع»ª(Ê®°ËÄê·çÓ꣬ÊصñùɽѩÁ«»¨¿ª)
ʱ¼ä£º2010-05-10
µØµã£ºÖØÇ캽ÌìְҵѧԺ
˵Ã÷£ºÒÔÏÂÎåÊ®¸öÓï¾ä¶¼°´ÕÕ²âÊÔÊý¾Ý½øÐ ......