Syntax error in PL SQL i'm trying to do a command that gather stats of tables that has more than 10 million rows. Right now only one table has, but i want the command to execute the gathering to more tables as soon as they reach 10 million rows.

Right now I have this command, but i can't find out what is wrong that is preventing it of running ok. I have ~ok~ sql skills, but almost zero experience with Oracle PL SQL.

Can someone point me a direction? Tks in advance.

DECLARE
 CURSOR t1 is
     select table_name from dba_tables where owner='SAPIENS_TESTE' and num_rows &gt; 10000000;
BEGIN
 OPEN t1
 FOR t IN t1 LOOP
    EXEC DBMS_STATS.GATHER_TABLE_STATS(OWNNAME =&gt; 'SAPIENS_TESTE', TABNAME =&gt; '||t.table_name||', partname =&gt; NULL, granularity =&gt; 'GLOBAL', CASCADE =&gt; TRUE, method_opt =&gt; 'FOR ALL INDEXED COLUMNS SIZE AUTO');
 END LOOP;
END
DECLARE
 CURSOR t1 is
     select table_name from dba_tables where owner='SAPIENS_TESTE' and num_rows &gt; 10000000;
BEGIN
 FOR t IN t1 LOOP
    DBMS_STATS.GATHER_TABLE_STATS(OWNNAME =&gt; 'SAPIENS_TESTE', TABNAME =&gt; t.table_name, partname =&gt; NULL, granularity =&gt; 'GLOBAL', CASCADE =&gt; TRUE, method_opt =&gt; 'FOR ALL INDEXED COLUMNS SIZE AUTO');
 END LOOP;
END;
/