|
ÇÁ·Î½ÃÁ®(Procedure)
ÇÁ·Î½ÃÁ®(Procedure)¶õ ?
PL/SQLºí·°µé·Î ±¸¼ºµÈ´Ù.
ÇÔ¼ö, ÇÁ·Î½ÃÁ®µîÀ» È£ÃâÇÒ ¼ö ÀÖ´Ù.
¸®ÅÏ°ªÀ» °¡Áú ¼ö ¾ø´Ù.
Query¹®¿¡¼ µ¶¸³ÀûÀ¸·Î »ç¿ëµÉ ¼ö ¾ø´Ù.
µ¥ÀÌŸ¿¡ º¯ÇüÀ» °¡ÇÒ ¼ö ÀÖ´Ù.
ÇÁ·Î½ÃÀú ³»ÀÇ PL/SQLºí·°Àº ¾î¶² DML¹®À̵ç Æ÷ÇÔÀÌ µÉ ¼ö ÀÖÀ¸³ª DDL¹®Àº »ç¿ëÇÒ ¼ö ¾ø´Ù.
1. ÇÁ·Î½ÃÁ®(Procedure)ÀÇ »ý¼º
CREATE [OR REPLACE] PROCEDURE [schema.]procedure
[ (argument [IN | OUT | IN OUT] datatype
[, argument [IN | OUT | IN OUT] datatype] ...)]
{IS | AS} pl/sql_subprogram_body
[schema.]procedure
ÇÁ·Î½ÃÁ®ÀÇ À̸§
argument [IN | OUT | IN OUT] datatype
Argument¸¦ Á¤ÀÇÇÑ´Ù.
ÀÎÀÚŸÀÔ
IN : ÀбâÀü¿ë, ÇÁ·Î½ÃÁ®°¡ ¸®Åϵɶ§ ÇÁ·Î½ÃÁ®³»ÀÇ °ªÀº Àü´ÞµÇÁö ¾Ê´Â´Ù.
ÇÁ·Î½ÃÁ®³»¿¡¼ °ªÀ» ÇÒ´ç ÇÒ ¼ö ¾ø´Ù.
ÇÁ·Î½ÃÁ® ³»¿¡¼ rvalueÀÌ´Ù. ´ëÀÔ¹®ÀÇ ¿À¸¥ÂÊ¿¡¸¸ ¾µ ¼ö ÀÖ´Ù.
OUT: ¾²±âÀü¿ë, ÇÁ·Î½ÃÁ®°¡ È£ÃâµÉ¶§ ½ÇÁ¦ ÆĶó¸ÞÅÍ°¡ °¡Áö´Â °ªÀº ¹«½ÃµÈ´Ù.
ÇÁ·Î¼Á® ³»¿¡¼ lvalueÀÌ´Ù. ´ëÀÔ¹®ÀÇ ¿ÞÂÊ¿¡¸¸ ¾µ ¼ö ÀÖ´Ù.
IN OUT : Àб⾲±â, ÆĶó¹ÌÅÍÀÇ °ªÀº ÇÁ·Î½ÃÀú°¡ ºÒ¸± ¶§ ÇÁ·Î½ÃÁ®¿¡°Ô Àü´ÞµÇ°í,
Á¦¾î°¡ ¸®Åϵɶ§ ½ÇÁ¦ ÆĶó¸ÞÅÍ¿¡°Ô Àü´ÞµÈ´Ù.
datatype
ParameterÀÇ type¸¸ °áÁ¤ÇØÁÖ°í ±æÀÌ´Â Á¤ÇØÁÖÁö ¾Ê´Â´Ù.
ORA-6502: numberic or value error
CREATE OR REPLACE PROCEDURE parameter_length(
p_para1 IN OUT VARCHAR2,
p_para2 IN OUT NUMBER) AS
BEGIN
p_para1 := 'abcdefghijklmno';
p_para2 := 12.3;
END;
½ÇÁ¦ ÆĶó¹ÌÅÍÀÇ ±æÀÌ´Â ÇÁ·Î½ÃÁ®¸¦ È£ÃâÇÏ´Â ÂÊ¿¡ ÀÖ´Ù.
±×·¡¼
DECLARE
v_var1 VARCHAR2(10);
v_var2 NUMBER(3,4);
BEGIN
parameter_length(v_var1,v_var2);
END;
´Ü¼øÈ÷ ÇÁ·Î½ÃÁ® Çϳª¸¸ È£ÃâÇÏ´Â PL/SQL¹®Àε¥.. ¿©±â¼ ORA-6502 ¿¡·¯°¡ ¹ß»ýÇÑ´Ù.
±æÀÌ°¡ 10ÀÚ¸®ÀÎ º¯¼ö¿¡ ÇÁ·Î½ÃÀú¿¡¼ 16ÀÚ¸®ÀÇ µ¥ÀÌŸ¸¦ ´ëÀÔÇÏ·Á ÇÏ¿´±â ¶§¹®ÀÌ´Ù.
pl/sql_subprogram_body
ÇÁ·Î½ÃÁ®ÀÇ ½ÇÁ¦ ±¸Çö ºÎºÐÀÌ´Ù.
PL/SQLºí·°ÀÌ µé¾î°£´Ù.
2. ÇÁ·Î½ÃÁ®(Procedure)ÀÇ ±¸¼º
ÇÁ·Î½ÃÁ®ÀÇ ÁÖ¿äºÎ´Â ¼±¾ð, ½ÇÇà, ¿¹¿Ü ¼½¼ÇÀ» °¡Áø PL/SQLºí·°ÀÌ´Ù.
CREATE OR REPLACE PROCEDURE procedurename AS
Declarative section
Executable section
EXCEPTION
Exception section
END [procedurename];
Declarative section: ÇÁ·Î½ÃÁ®³ª function¿¡´Â DECLAREÅ°¿öµå°¡ ¾ø´Â ÀÌÀ¯´Â
IS, AS°¡ ÀÌ°ÍÀ» ´ë½ÅÇØ Áֱ⠶§¹®ÀÌ´Ù.
3. ÇÁ·Î½ÃÁ®(Procedure)ÀÇ »ý¼º°ú ½ÇÇà
ÇÁ·Î½ÃÁ®ÀÇ »ý¼º°ú ½ÇÇàÀ» ÇϱâÀ§Çؼ´Â ±ÇÇÑÀÌ ÀÖ¾î¾ß ÇÑ´Ù.
ÇÁ·Î½ÃÀúÀÇ »ý¼ºÀ» À§ÇÑ ±ÇÇÑ : CREATE PROCEDURE ±ÇÇÑ.
ÇÁ·Î½ÃÀúÀÇ ½ÇÇàÀ» À§ÇÑ ±ÇÇÑ : EXECUTE ±ÇÇÑ.
DBA ±ÇÇÑÀÇ User°¡ Procedure¸¦ »ç¿ëÇÒ ¼ö ÀÖ´Â ±ÇÇÑÀ» ºÎ¿©.
GRANT EXECUTE ON my_procedure to scotte;
ÇÁ·Î½ÃÁ®ÀÇ ½ÇÇà¿¡´Â ±× ÇÁ·Î½ÃÁ®¸¦ ½ÇÇàÇÒ ¼ö ÀÖ´Â ±ÇÇÑ(EXECUTE±ÇÇÑ)
ÀÌ ÀÖ¾î¾ß ÇÑ´Ù.
EXECUTE ANY PROCEDURE ½Ã½ºÅÛ Æ¯±Ç.
EXECUTE new_worker('PARK JAE OH');
sqlplus ¿¡¼´Â execute¸í·É¿¡ ÀÇÇØ ÇÁ·Î½ÃÁ®°¡ È£ÃâµÈ´Ù.
new_worker('PARK JAE OH');
´Ù¸¥ ÇÁ·Î½ÃÁ®, ÇÔ¼ö,ÆÐÅ°Áö ȤÀº Æ®¸®°Å ³»¿¡¼´Â EXECUTE¸í·ÉÀÌ
¾øÀ̵µ È£Ãâ µÉ ¼ö ÀÖ´Ù.
EXECUTE Georage.new_worker('PARK JAE OH');
´Ù¸¥ À¯Àú(Georage)ÀÇ ¼ÒÀ¯ÀÇ ÇÁ·Î½ÃÁ®¸¦ ½ÇÇàÇÏ°íÀÚ ÇÑ´Ù.
CREATE SYNONYM new_worker for George.new_worker;
´Ù¸¥ À¯ÀúÀÇ ÇÁ·Î½ÃÁ®¿¡ ´ëÇÑ µ¿ÀǾ ¸¸µç´Ù.
ÀÌ·¸°Ô µ¿ÀǾ »ý¼ºÇÏ°í ³ ÈÄ¿¡´Â ¼ÒÀ¯ÀÚ¸¦ ¸í½ÃÇÒ ÇÊ¿ä´Â ¾ø´Ù.
EXECUTE new_worker('PARK JAE OH');
µ¿ÀǾî·Î ´Ù¸¥ À¯ÀúÀÇ ÇÁ·Î½ÃÁ®¸¦ È£ÃâÇÑ´Ù.
EXECUTE new_worker@REMOTE_CONNECT('PARK JAE OH');
REMOTE_CONNECT¶ó´Â µ¥ÀÌŸº£À̽º ¸µÅ©¸¦ ÀÌ¿ëÇÏ¿©
´Ù¸¥ µ¥ÀÌŸº£À̽º¿¡ ÀÖ´Â ÇÁ·Î½ÃÁ®¸¦ È£Ãâ ÇÒ ¼ö ÀÖ´Ù.
¹°·Ð ¿©±â¼µµ µ¿ÀǾî(synonym)¸¦ »ý¼ºÇÏ¿© »ç¿ë ÇÒ ¼ö ÀÖ´Ù.
4. ÇÁ·Î½ÃÁ®(Procedure)ÀÇ µð¹ö±ë(Debugging)
show error
ÇÁ·Î½ÃÁ®³ª ÇÔ¼ö,µîÀ» ÄÄÆÄÀÏ ÇÒ ¶§ ERROR°¡ ¹ß»ýÇßÀ» ¶§
¸¶Áö¸·À¸·Î ÄÄÆÄÀÏ µÈ ÇÁ·Î±×·¥ ¸¶Áö¸·À¸·Î ÄÄÆÄÀÏ µÈ ÇÁ·Î¼Àú³ª ÇÔ¼öÀÇ
DBMS_OUTPUTÆÐÅ°Áö¸¦ »ç¿ë
$ORACLE_HOME/product/7.3.2/rdbms/admin/
»ý¼º ½ºÅ©¸³ÅÍ : dbms_otpt.sql
»ç¿ëÇÑ ¿¹Á¦ ½ºÅ©¸³ÅÍ: catrepad.sql
|