I'm trying to loop through a set of views and gather the view name and counts. I created a new table and added an ID columns. I'd like to loop through my sql statment and retrieve the values while the ID < 10.
Here is my create table statement I'm using to set my id column;
create table View_Table AS
select VIEW_NAME,
row_number() over ( order by VIEW_NAME ) as id
from all_views;
--My attempt to loop through the sql statement
DECLARE
x NUMBER := 0;
BEGIN
LOOP
select view_name,count(*) from VIEW_TABLE where id = x group by VIEW_NAME;
x := x + 1;
EXIT WHEN x > 10;
END LOOP;
END;
---Here is the error message I'm receiving:
Error starting at line : 13 in command -
DECLARE
x NUMBER := 0;
BEGIN
LOOP
select view_name,count(*) from VIEW_TABLE where id = x group by VIEW_NAME;
x := x + 1;
EXIT WHEN x > 10;
END LOOP;
END;
Error report -
ORA-06550: line 5, column 9:
PLS-00428: an INTO clause is expected in this SELECT statement
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Any help would be appreciated.
count(*)is always going to be 1, since each view appears in your new table once (unless you have the same view in multiple schemas). Are you actually trying to count the number of rows in each view - which you would have to do with dynamic SQL?