0
votes

I have a table lets say table_names which contains some table names ( table1 , table2 ,table3 etc ). Now I want to fetch the data from table1 , table2 , table3 etc by going through the table table_names.

I am unable to achieve this task. Could anyone please help me out of this situation ?

I am using Oracle DB.

Thank you in advance.

3

3 Answers

0
votes

If from TableA you have to get value from Single table then use this,

SELECT * FROM (SELECT table_name FROM tableA WHERE id=3)AS b

Otherwise from getting from multiple table, I prefer below PHP-

while($a=mysql_fetch_assoc(mysql_query((SELECT table_name FROM tableA)))
{ $tablename=$a[table_name];
while($b=mysql_fetch_assoc(mysql_query((SELECT * FROM $tablename))))
  {
    echo $b[column_name];
  }
}
0
votes

try this query:

DECLARE
 str VARCHAR2(30);
 num number(5);
BEGIN
SELECT count(*) into num FROM table_names;
FOR i in 1..num loop
SELECT name into str FROM 
(SELECT ROWNUM r,t.name FROM table_names t) where r = i;
EXECUTE IMMEDIATE 'SELECT * FROM '||str;
str:='';
end loop;
END;
0
votes

Select t1.,t2.,t3.* from table1 t1,table2 t2, table3 t3 where (select name from tables)