stored procedure(PL/SQL) È®ÀÎ sql
ÀÛ¼ºÀÚ °ü¸®ÀÚ ÀÛ¼º½Ã°£ 2016-02-18 09:14:48
 

USER_SOURCE µ¥ÀÌÅÍ »çÀü¿¡¼­ È®ÀÎ °¡´ÉÇÏ´Ù.

-- USER_SOURCEÀÇ ±¸Á¶¸¦ »ìÆ캸¸é
SQL> DESC USER_SOURCE
 
        À̸§              À¯Çü
------------- ----------------
        NAME      VARCHAR2(30)
        TYPE      VARCHAR2(12)
        LINE            NUMBER
        TEXT    VARCHAR2(4000)


-- ¾î¶² ÇÁ·Î½ÃÁ®µéÀÌ Á¸ÀçÇÏ´ÂÁö È®ÀÎ
SQL> SELECT DISTINCT(name)
    FROM USER_SOURCE
    WHERE TYPE = 'PROCEDURE';

NAME
------------------------------
FORCURSOR_TEST
IMPLICIT_CURSOR


-- ÇÁ·Î½ÃÁ® ¼Ò½ºÀÇ È®ÀÎ
SQL> SELECT text
    FROM USER_SOURCE
    WHERE name='FORCURSOR_TEST';

-- Äõ¸® °á°ú
PROCEDURE ForCursor_Test
    IS

    CURSOR dept_sum IS
    SELECT b.dname, COUNT(a.empno) cnt, SUM(a.sal) salary
    FROM emp a, dept b
    WHERE a.deptno = b.deptno
    GROUP BY b.dname;
  BEGIN
    -- Cursor¸¦ FOR¹®¿¡¼­ ½ÇÇà½ÃŲ´Ù
    FOR emp_list IN dept_sum LOOP
      DBMS_OUTPUT.PUT_LINE('ºÎ¼­¸í : ' || emp_list.dname);
      DBMS_OUTPUT.PUT_LINE('»ç¿ø¼ö : ' || emp_list.cnt);
      DBMS_OUTPUT.PUT_LINE('±Þ¿©ÇÕ°è : ' || emp_list.salary);
    END LOOP;
EXCEPTION
    WHEN OTHERS THEN
      DBMS_OUTPUT.PUT_LINE(SQLERRM||'¿¡·¯ ¹ß»ý ');
END;


¸ñ·Ï | ÀÔ·Â | ¼öÁ¤ | ´äº¯ | »èÁ¦