Stored Procedure Problem

Database
Enthusiast

Stored Procedure Problem

Hi everyone,
I'm a teradata beginner and try to use stored procedure.
I'm trying to get database name, table name from a table then to count the line number in this table and to store the result in another table.
But my variable iDBNAME, iTABLE_NAME do not take any value.
Please note that dwh1 database name and table1,table2 table name are not generic, it really exist.
Here is my code:

REPLACE PROCEDURE dwh1.COUNT_GENERIC()
BEGIN
DECLARE iDBNAME VARCHAR(30);

DECLARE iTABLE_NAME VARCHAR(30);
DECLARE oNB_LINES INTEGER;
DECLARE counter INTEGER DEFAULT 0;

FOR counter AS cursor1 CURSOR FOR
select DBNAME,TABLE_NAME from dwh1.table1
DO
select DBNAME into :iDBNAME from dwh1.table1;
select TABLE_NAME into :iTABLE_NAME from dwh1.table1;

select count(*) into :oNB_LIGNES from iDBNAME.iTABLE_NAME;

INSERT INTO dwh1.table2(database, table_name,line_number)
VALUES(:iDBNAME,:iTABLE_NAME,:oNB_LIGNES);

END FOR;
END;

I receive the following error : SPL1027:E(L16), Missing/Invalid SQL statement'E(3802):Database 'iDBNAME' does not exist.'.

Thank you for giving you ideas,
BR