PL/SQL - Update a table after spooling the metadata into a file

285 views Asked by At

I've got the following script, which stores the metadata for the tables that are in the MTTO_TAB_EXIST_ALL column. The files are stored individually and its file name is the same of the current spooling table

set pagesize 0
set linesize 100
set long 90000

SET TERMOUT OFF
spool out.sql

select 'spool C:\Users\personal\MAIN_USR\table\'||REPLACE(table_name, '$', '_')||'.txt'||chr(13)||chr(10)||
       'SELECT DBMS_METADATA.GET_DDL'||chr(13)||chr(10)||
       '(''TABLE'','''||table_name||''',''MTO_TABL'') '||chr(13)||chr(10)||
       'FROM DUAL;'||chr(13)||chr(10)||
       'spool off' as cmd
FROM MTTO_TAB_EXIST_ALL tea
WHERE tea.MRK_DEL_PERM = 'Y'
AND tea.OWNER_NM = 'MTO_TABL'
AND MRK_BACKUP_DDL != 'Y';

spool off

@OUT.SQL

What I need is after spooling that table, the existing record of it in column MRK_BACKUP_DDL updates to 'Y'

TABLE_NAME                    | MRK_BACKUP_DDL
— — — — — — — — — — — — — — — — — — — — — — — — — —
CA_3092_MVTO_NODISTR_2_MISC   | Y
ED_EXTR_CSV_PRIMA_DEA_PUBLI   | N
CA_T3054_GRP_OFICINAS_O_MISC0 | N

I couldn't find anything similar to the UPDATE statement, so I would like to know if there is any way to do it.

I appreciate any help.

1

There are 1 answers

0
Littlefoot On BEST ANSWER

As you're creating everything dynamically, add update in between, here:

'FROM DUAL;'||chr(13)||chr(10)||
--> here
       'spool off' as cmd

"Here" would look like this; maybe I failed with single quotes and stuff (I don't have your tables and code you wrote is kind of difficult to hop into) so - fix it, if necessary.

'update MTTO_TAB_EXIST_ALL set mrk_backup_ddl = ''N'' where table_name = ' || 
chr(39) || MTO_TABL || chr(39) || ';'