ORACLE How to use spool with dynamic spool location

后端 未结 3 1578
旧时难觅i
旧时难觅i 2020-12-19 13:58

Ok, so i\'m a complete newb with oracle. Now that that\'s out of the way;

I think you can get an understand of what i\'m trying to do below. For each stored procedur

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-19 14:27

    SPOOL is a SQLPlus directive and you can't mix it into the PL/SQL anonymous block. If you're going to do this purely in SQLPlus, I think the general idea would be to process in two passes, i.e. use a first script that dynamically generates the spool filename references into a second script that actually makes the dbms_metadata call.

    [Edit]

    This should be close to what you need - maybe a line termination problem, depending on your platform:
    
        set pagesize 0
        set linesize 300
        spool wrapper.sql
        select
        'spool '||object_name||'.sql'||chr(10)||
        'begin 
        dbms_metadata.get_ddl('||chr(39)||object_type||chr(39)||','||chr(39)||object_name||chr(39)||')'||' end;'||chr(10)||
        '/'||chr(10)||
        'spool off'
        from user_objects
        where object_type = 'PROCEDURE'
    ;
    spool off
    

提交回复
热议问题