CARIS HPD : HPD® User Guide : Loading Data : External Files : Delete Files From the Database
 

Delete Files From the Database

You can use the API procedure FEATURE_ATTRIBUTE_FILE_VW to display or delete one or all unreferenced files.

This example will delete all unreferenced files:

PROMPT 'These files are not referenced, and will be deleted:'

 

select filename

from FEATURE_ATTRIBUTE_FILE_VW

where reference_count = 0

order by filename;

 

DECLARE

CURSOR c_files IS select filename from FEATURE_ATTRIBUTE_FILE_VW;

BEGIN

FOR REC in c_files LOOP

p_feature_api.deleteUnusedFile(REC.filename);

END LOOP;

END;

/

commit

/

This example displays information about files in the schema:

select * from FEATURE_ATTRIBUTE_FILE_VW order by filename;

This example displays a list of the files with no feature references:

select filename

from FEATURE_ATTRIBUTE_FILE_VW

where reference_count = 0

order by filename;

These examples can be combined into an SQL script such as the following:

set term off

WHENEVER SQLERROR EXIT

alter session set NLS_LANGUAGE = AMERICAN;

alter session set NLS_TERRITORY = AMERICA;

 

set serveroutput on size unlimited;

set verify off

set trimspool on

set term on

 

 

COLUMN FILENAME NEW_VALUE VAR_LOGFILE

SELECT 'deleteUnusedAttributeFiles' || '_' || TO_CHAR(SYSDATE, P_SCHEMA_CONSTANTS.RETURNDATETIMEFORMAT) || '.log' FILENAME FROM DUAL;

SPOOL &&VAR_LOGFILE;

ssssssss

PROMPT

PROMPT ===========================================================================

PROMPT Delete Unused Attribute Files

PROMPT ===========================================================================

PROMPT Deletes attribute files that were never referenced by a feature attribute.

PROMPT ===========================================================================

 

PROMPT

PROMPT ===========================================================================

PROMPT WARNING!

PROMPT ===========================================================================

PROMPT

PROMPT THIS SCRIPT PERMANENTLY MODIFIES DATA.

PROMPT

PROMPT CARIS strongly recommends you backup your schema before continuing

PROMPT

PROMPT ===========================================================================

 

PROMPT 'These files are not referenced, and will be deleted:'

 

select filename

from FEATURE_ATTRIBUTE_FILE_VW

where reference_count = 0

order by filename;

 

ACCEPT WILL_CONTINUE PROMPT 'Do you wish to continue? (Yes/No): ';

 

DECLARE

CURSOR c_files IS select filename from FEATURE_ATTRIBUTE_FILE_VW where reference_count = 0;

BEGIN

IF UPPER('&&WILL_CONTINUE') IN ('YES', 'Y') THEN

 

FOR REC in c_files LOOP

p_feature_api.deleteUnusedFile(REC.filename);

END LOOP;

 

commit;

 

-- record the script was run and was successful

store_script_info('S', 'Y', 'deleteUnusedAttributeFiles.sql', 'Successful.');

ELSE

DBMS_OUTPUT.PUT_LINE('Operation canceled at user request.');

END IF;

 

EXCEPTION

WHEN OTHERS THEN

-- record the script was run and was not successful

store_script_info('S', 'N', 'deleteUnusedAttributeFiles.sql', SQLERRM);

RAISE;

END;

/

 

SPOOL OFF;

set verify on

UNDEFINE VAR_LOGFILE;

UNDEFINE WILL_CONTINUE;