OracleÊý¾Ý¿âÓαêʹÓôóÈ«
SQLÊÇÓÃÓÚ·ÃÎÊORACLEÊý¾Ý¿âµÄÓïÑÔ£¬PL/SQLÀ©Õ¹ºÍ¼ÓÇ¿ÁËSQLµÄ¹¦ÄÜ£¬Ëü ͬʱÒýÈëÁ˸üÇ¿µÄ³ÌÐòÂß¼¡£ PL/SQLÖ§³ÖDMLÃüÁîºÍSQLµÄÊÂÎñ¿ØÖÆÓï¾ä¡£DDLÔÚPL/SQLÖв»±»Ö§³Ö£¬Õâ¾ÍÒâζ×÷ÔÚPL/SQL³ÌÐò¿éÖв»ÄÜ´´½¨±í»òÆäËûÈκζÔÏ󡣽Ϻà µÄPL/SQL³ÌÐòÉè¼ÆÊÇÔÚPL/SQL¿éÖÐʹÓÃÏóDBMS_SQLÕâÑùµÄÄÚ½¨°ü»òÖ´ÐÐEXECUTE IMMEDIATEÃüÁÁ¢¶¯Ì¬SQLÀ´Ö´ÐÐDDLÃüÁPL/SQL±àÒëÆ÷±£Ö¤¶ÔÏóÒýÓÃÒÔ¼°Óû§µÄȨÏÞ¡£
¡¡¡¡ÏÂÃæÎÒÃǽ«ÌÖÂÛ¸÷ÖÖÓÃÓÚ·ÃÎÊORACLEÊý¾Ý¿âµÄDDLºÍTCLÓï¾ä¡£
¡¡¡¡²éѯ
¡¡¡¡SELECTÓï¾äÓÃÓÚ´ÓÊý¾Ý¿âÖвéѯÊý¾Ý£¬µ±ÔÚPL/SQLÖÐʹÓÃSELECTÓï¾äʱ£¬ÒªÓëINTO×Ó¾äÒ»ÆðʹÓ㬲éѯµÄ·µ»ØÖµ±»¸³ÓèINTO×Ó¾äÖеıäÁ¿£¬±äÁ¿µÄÉùÃ÷ÊÇÔÚDELCAREÖС£SELECT INTOÓï·¨ÈçÏ£º
SELECT [DISTICT|ALL]{*|column[,column,...]}
INTO (variable[,variable,...] |record)
from {table|(sub-query)}[alias]
WHERE............
¡¡¡¡PL/SQLÖÐSELECTÓï¾äÖ»·µ»ØÒ»ÐÐÊý¾Ý¡£Èç¹û³¬¹ýÒ»ÐÐÊý¾Ý£¬ÄÇô¾ÍҪʹÓÃÏÔʽÓα꣨¶ÔÓαêµÄÌÖÂÛÎÒÃǽ«ÔÚºóÃæ½øÐУ©£¬INTO×Ó¾äÖÐÒªÓÐÓëSELECT×Ó¾äÖÐÏàͬÁÐÊýÁ¿µÄ±äÁ¿¡£INTO×Ó¾äÖÐÒ²¿ÉÒÔÊǼǼ±äÁ¿¡£
¡¡¡¡%TYPEÊôÐÔ
¡¡¡¡ÔÚPL/SQLÖпÉÒÔ½«±äÁ¿ºÍ³£Á¿ÉùÃ÷ΪÄÚ½¨»òÓû§¶¨ÒåµÄÊý¾ÝÀàÐÍ£¬ÒÔÒýÓÃÒ»¸öÁÐÃû£¬Í¬Ê±¼Ì³ÐËûµÄÊý¾ÝÀàÐͺʹóС¡£ÕâÖÖ¶¯Ì¬¸³Öµ·½·¨ÊǷdz£ÓÐÓõģ¬±ÈÈç±äÁ¿ÒýÓõÄÁеÄÊý¾ÝÀàÐͺʹóС¸Ä±äÁË£¬Èç¹ûʹÓÃÁË%TYPE,ÄÇôÓû§¾Í²»±ØÐ޸ĴúÂ룬·ñÔò¾Í±ØÐëÐ޸ĴúÂë¡£
¡¡Àý£º
v_empno SCOTT.EMP.EMPNO%TYPE;
v_salary EMP.SALARY%TYPE;
¡¡¡¡²»µ«ÁÐÃû¿ÉÒÔʹÓÃ%TYPE,¶øÇÒ±äÁ¿¡¢Óαꡢ¼Ç¼£¬»òÉùÃ÷µÄ³£Á¿¶¼¿ÉÒÔʹÓÃ%TYPE¡£Õâ¶ÔÓÚ¶¨ÒåÏàͬÊý¾ÝÀàÐ͵ıäÁ¿·Ç³£ÓÐÓá£
DELCARE
V_A NUMBER(5):=10;
V_B V_A%TYPE:=15;
V_C V_A%TYPE;
BEGIN
DBMS_OUTPUT.PUT_LINE
('V_A='||V_A||'V_B='||V_B||'V_C='||V_C);
END
SQL>/
V_A=10 V_B=15 V_C=
PL/SQL procedure successfully completed.
SQL>
¡¡¡¡ÆäËûDMLÓï¾ä
¡¡ ¡¡ÆäËü²Ù×÷Êý¾ÝµÄDMLÓï¾äÊÇ:INSERT¡¢UPDATE¡¢DELETEºÍLOCK TABLE,ÕâЩÓï¾äÔÚPL/SQLÖеÄÓï·¨ÓëÔÚSQLÖеÄÓï·¨Ïàͬ¡£ÎÒÃÇÔÚÇ°ÃæÒѾÌÖÂÛ¹ýDMLÓï¾äµÄʹÓÃÕâÀï¾Í²»ÔÙÖظ´ÁË¡£ÔÚDMLÓï¾äÖпÉÒÔʹÓÃÈÎ ºÎÔÚDECLARE²¿·ÖÉùÃ÷µÄ±äÁ¿£¬Èç¹ûÊÇǶÌ׿飬ÄÇôҪעÒâ±äÁ¿µÄ×÷Ó÷¶Î§¡£
¡¡¡¡Àý£º
CREATE OR REPLACE PROCEDURE FIRE_EMPLOYEE (pempno in number)
¡¡AS
¡¡¡¡v_ename EMP.ENAME%TYPE;
¡¡BEGIN
¡¡¡¡SELECT ename INTO v
Ïà¹ØÎĵµ£º
oracle±í¿Õ¼ä²Ù×÷Ïê½â
1
2
3×÷Õߣº À´Ô´£º ¸üÐÂÈÕÆÚ£º2006-01-04
5
6
7½¨Á¢±í¿Õ¼ä
8
9CREATE TABLESPACE data01
10DATAFILE '/ora ......
ËäȻѧϰJavaºÜ¾ÃÁË£¬×Ô¼ºÒ²Á¬½Ó¹ýһЩÊý¾Ý¿â£¬±ÈÈçmysqlÖ®ÀàµÄ£¬Èç½ñÄØ£¬Ò²Ñ§Ï°ÁËÒ»¶Îʱ¼äµÄOracle£¬È»¶øÄØ£¬½ñÌìÊÇÎÒµÚÒ»´ÎÁ¬½ÓOracle£¬ºÙºÙ£¬Ó¦¸Ã»¹²»ËãÌ«³Ù°É¡£
½ñÌìÄØ£¬Óе㱿׾£¬´ó¼ÒĪЦ£¡
ÎÒÕâÊÇÒ»¸ö²éѯÀý×Ó
Ê×ÏÈ£¬Ô ......
·½·¨Ò»
µÚÒ»²½£ºµÇÈësql/plus Ö´ÐÐÃüÁÎÞÏȺó˳Ðò£©
set time on; (˵Ã÷£º´ò¿ªÊ±¼äÏÔʾ£©
set autotrace on; (˵Ã÷£º´ò¿ª×Ô¶¯·ÖÎöͳ¼Æ£¬²¢ÏÔʾSQLÓï¾äµÄÔËÐнá¹û£©
set autotrace traceonly; (˵à ......