Last active
July 3, 2020 14:12
-
-
Save NielsLiisberg/9e0031c372bffdaaed95a43847550d62 to your computer and use it in GitHub Desktop.
SQL procedure to get a quick system catalog of files, tables and views
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- SQL procedure to get a quick system catalog of files, tables and views. | |
-- I use this from ACS all the time to get a catalog overview. | |
-- | |
-- Simply paste this gist into ACS SQL and select "run all" | |
-- | |
-- 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 2020 | |
------------------------------------------------------------------------------------- | |
create or replace procedure qusrsys.syscat ( | |
in lib varchar(20) default '', | |
in file varchar(10) default '', | |
in table varchar(32) default '', | |
in text varchar(32) default '' | |
) | |
language sql | |
dynamic result sets 1 | |
begin | |
declare c1 cursor with return for | |
select | |
table_schema as lib, | |
system_table_name as file, | |
table_name as table, | |
table_text as text , | |
table_type, file_type | |
from systables | |
where table_schema like '%' concat upper(lib) concat '%' | |
and system_table_name like '%' concat upper(file) concat '%' | |
and table_name like '%' concat upper(table) concat '%' | |
and lower(table_text) like '%' concat lower(text) concat '%' | |
order by 1, 2; | |
open c1; | |
end; | |
-- Usecases: | |
-- Get list of all files, tables and views in all libraries and schemas | |
call syscat (); | |
-- Get list of all files, tables and views in library with names like QIWS | |
-- Note it is not case sensistive and makes a generic search | |
call syscat (lib=>'qiws'); | |
-- Get list of all files, tables and views in library (schema) with | |
-- names like QIWS and table name contains 'cust' somwhere | |
-- Note it is not case sensistive and makes a generic search | |
call syscat (lib=>'qiws', table =>'cust'); | |
-- Get list of all files, tables and views in library (schema) with | |
-- names like QIWS and description contains 'cust' somwhere | |
-- Note it is not case sensistive and makes a generic search | |
call syscat (lib=>'qiws', text =>'cust'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment