forked from momokind/orasql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExportDDL4Function.sql
64 lines (61 loc) · 1.92 KB
/
ExportDDL4Function.sql
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* 导出登陆用户的函数
* 潘欣磊 2014-04
*/
SET ECHO OFF
SET TRIMSPOOL ON
SET VERIFY OFF
SET FEEDBACK OFF
SET FEED OFF
SET TIMING OFF
SET LINESIZE 4000
SET PAGESIZE 1000
SET LONG 90000
SET NEWPAGE NONE
SET HEADING OFF
SET TERMOUT OFF
SET WRAP ON
BEGIN
DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'STORAGE',FALSE);
DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'TABLESPACE',FALSE);
DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'SEGMENT_ATTRIBUTES',FALSE);
DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'PRETTY',TRUE);
DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'SQLTERMINATOR',TRUE);
DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'CONSTRAINTS',FALSE);
END;
/
COL DDL_STR FORMAT A30000
SPOOL './DDL4Function.sql';
SELECT RPAD('-', 45, '-' )
||CHR(10)|| '-- File created on '||TO_CHAR(SYSDATE,'YYYY-MM-DD HH24:MI:SS')||' .'
||CHR(10)|| '-- Total export '||COUNT(DISTINCT OBJECT_NAME)||' function(s).'
||CHR(10)|| RPAD('-', 45, '-' )
FROM USER_PROCEDURES
WHERE OBJECT_TYPE = 'FUNCTION'
;
SELECT 'set sqlblanklines on'
||CHR(10)|| 'set define off'
FROM DUAL
;
WITH F AS (
SELECT OBJECT_NAME AS FUNC_NAME
FROM USER_PROCEDURES
WHERE OBJECT_TYPE = 'FUNCTION'
)
SELECT TO_CLOB(RPAD('-', LENGTH(F.FUNC_NAME)+18, '-' ))
||CHR(10)|| TO_CLOB('---- Function : ' || F.FUNC_NAME)
||CHR(10)|| TO_CLOB(RPAD('-', LENGTH(F.FUNC_NAME)+18, '-' ))
||CHR(10)|| REPLACE(DBMS_METADATA.GET_DDL( OBJECT_TYPE => 'FUNCTION'
, NAME => F.FUNC_NAME
, SCHEMA => USER
)
, '"'||USER||'".'
,''
) AS DDL_STR
FROM F
;
SELECT 'set define on'
||CHR(10)|| 'quit;'
FROM DUAL
;
SPOOL OFF;
QUIT;