Hi,
I am trying to write a generic bit of SQL (Oracle 8i) to run against more than one table - the table being unknown until runtime. I am therfore trying to pass the table name as a variable to the Select statement as follows:
1 DECLARE
2 var1 char(20):= 'ng1.users';
3 sql_stmt varchar2(500):=
4 'select count(*)
5 from :var1
6 BEGIN
8 EXECUTE IMMEDIATE sql_stmt USING var1;
9 end;
the result is
ERROR at line 1:
ORA-00903: invalid table name
ORA-06512: at line 7
I am now at the hair tearing out stage. Any help appreciated.
I am trying to write a generic bit of SQL (Oracle 8i) to run against more than one table - the table being unknown until runtime. I am therfore trying to pass the table name as a variable to the Select statement as follows:
1 DECLARE
2 var1 char(20):= 'ng1.users';
3 sql_stmt varchar2(500):=
4 'select count(*)
5 from :var1
6 BEGIN
8 EXECUTE IMMEDIATE sql_stmt USING var1;
9 end;
the result is
ERROR at line 1:
ORA-00903: invalid table name
ORA-06512: at line 7
I am now at the hair tearing out stage. Any help appreciated.