프린트 하기

OS환경 : Oracle Linux6.8(64bit)


DB 환경 : Oracle Database 11.2.0.4


방법 : dbms_metadata로 프로시저 생성문 뽑기


아래 절차대로 진행

1
2
3
4
5
6
7
8
9
10
11
12
connect user/user;
 
spool procedures.log
 
select
DBMS_METADATA.GET_DDL('PROCEDURE','OBJECT_NAME')
from
user_objects u
where
object_type = 'PROCEDURE';
 
spool off;



테스트 시나리오

프로시저 생성

1
2
3
4
5
6
7
8
9
10
11
12
13
conn jsh/jsh;
 
CREATE OR REPLACE PROCEDURE UPDATE_SAL 
  /* IN  PARAMETER */
  (V_EMPNO    IN    NUMBER) 
  IS 
  BEGIN 
    UPDATE EMP 
    SET SAL = SAL  * 1.1 
    WHERE EMPNO = V_EMPNO; 
    COMMIT; 
  END UPDATE_SAL; 
/   



dbms_metadata로 출력

1
2
3
4
5
6
7
8
9
10
11
set long 2000000000;     
SPOOL procedures.log
 
SELECT
DBMS_METADATA.GET_DDL('PROCEDURE','UPDATE_SAL')
FROM
USER_OBJECTS U
WHERE
OBJECT_TYPE = 'PROCEDURE';
 
SPOOL OFF;


SPOOL 출력파일 확인
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
!cat procedures.log
SELECT
  2  DBMS_METADATA.GET_DDL('PROCEDURE','UPDATE_SAL')
  3  FROM
  4  USER_OBJECTS U
  5  WHERE
  6  OBJECT_TYPE = 'PROCEDURE';
 
DBMS_METADATA.GET_DDL('PROCEDURE','UPDATE_SAL')            
-----------------------------------------------------------
                                                           
  CREATE OR REPLACE PROCEDURE "JSH"."UPDATE_SAL"           
     /* IN  Parameter */                                   
     (v_empno    IN    NUMBER)                             
                                                           
     IS                                                    
                                                           
     BEGIN                                                 
                                                           
       UPDATE emp                                          
       SET sal = sal  * 1.1                                
       WHERE empno = v_empno;                              
                                                           
       COMMIT;                                             
                                                           
     END update_sal;                                       
                                                           
                                                           
  CREATE OR REPLACE PROCEDURE "JSH"."UPDATE_SAL"           
     /* IN  Parameter */                                   
     (v_empno    IN    NUMBER)                             
                                                           
     IS                                                    
                                                           
     BEGIN                                                 
                                                           
       UPDATE emp                                          
       SET sal = sal  * 1.1                                
       WHERE empno = v_empno;                              
                                                           
       COMMIT;                                             
                                                           
     END update_sal;                                       
                                                           
 
2 rows selected.
 
Elapsed: 00:00:00.03
 
SPOOL OFF;
같은 프로시저가 2번나왔는데 왜이러는지는 모르겠다.


참조 : http://www.dba-oracle.com/t_dbms_metadata_tips.htm