Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count number of columns in a View? - Oracle SQL

I'm trying to figure out a way to count the number of columns in a view in Oracle. There's a lot of answers around on how to count the number of columns in a table, but none for views.

The database has many, many views, and I have to count for each one. It would be most efficient to find a solution in the form of a query I can repeatedly execute - hand counting isn't going to work here.

Thanks for any help you can provide!

like image 250
London Avatar asked Sep 13 '25 04:09

London


1 Answers

SELECT
      table_name,
      column_name,
      data_type
 FROM all_tab_columns
WHERE table_name = 'VIEWNAME'
  AND owner      = 'OWNER'
ORDER BY column_id;

for counting

SELECT
  count(*) columnCount
FROM all_tab_columns
WHERE table_name = 'VIEWNAME'
  AND owner      = 'OWNER'
like image 97
Derviş Kayımbaşıoğlu Avatar answered Sep 15 '25 01:09

Derviş Kayımbaşıoğlu