Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Select tables matching condition from all tables

I want to select for all tables with columns that contain the word deposit from a list of all tables when the owner is like bi. How can I implement this?

For example, I can select all tables and owner:

SELECT * FROM ALL_TABLES WHERE OWNER LIKE '%BI';

But I want to then select all tables from table_name and run a query to find those columns that are type character and contain the string deposit. This I cannot understand how to do.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

UPDATE:
The following query worked:

SELECT * 
FROM ALL_TAB_COLUMNS 
WHERE OWNER LIKE '%BI' 
AND DATA_TYPE 
LIKE '%NUMBER' 
AND COLUMN_NAME 
LIKE '%DEPOSIT%';

>Solution :

Just change the data_type to varchar% (to catch varchar and varchar2):

SELECT DISTINCT TABLE_NAME
  FROM DBA_TAB_COLUMNS TBLS
 WHERE UPPER(TBLS.OWNER)  LIKE '%BI'
   AND UPPER(COLUMN_NAME) LIKE '%DEPOSIT%'
   AND UPPER(DATA_TYPE)   LIKE 'VARCHAR%';
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading