Skip to content

Instantly share code, notes, and snippets.

@NielsLiisberg
Last active August 2, 2022 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NielsLiisberg/2eee9fad946151d953361a31717fc9f9 to your computer and use it in GitHub Desktop.
Save NielsLiisberg/2eee9fad946151d953361a31717fc9f9 to your computer and use it in GitHub Desktop.
SQL Drop old backup files made by RSTOBJ commd
-- This procedure deletes old backup files produced
-- when the RSTOBJ command restores file objects.
--
-- It uses the regex to filter the names of the files
-- the RSTOBJ command gives these file objets in the rename process.
--
-- Simply paste this gist into ACS SQL and step through the code.
--
-- Note: I am using library QUSRSYS. I suggest you put it into your own tool library
--
-- It is a cool example how far you can go with SQL: Have fun 😀
-- (C) Niels Liisberg 2022
--
-- This gist is distributed on an "as is" basis, without warranties
-- or conditions of any kind, either express or implied.
----------------------------------------------------------------------------------------------
create or replace procedure qusrsys.drop_old_files (
in library char(10)
)
begin
declare continue handler for sqlstate '42704', sqlstate '42809' begin end;
for
Select *
from table(OBJECT_STATISTICS ( library , '*FILE' ))
where regexp_like (objtext , 'Old name .* in .* owned by .*')
do
execute immediate 'drop table ' || rtrim(objLongSchema) || '.' || rtrim(objLongName);
end for;
end;
-- Use case:
call qusrsys.drop_old_files ( 'MYTESTLIB');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment