Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Help, SQL Problem!!!
> I hope this doesn't seem like a silly question but I'm new to all this.
> Is there any way to dynamically alter the FROM part of a select
> statement either in SQL or PL/SQL.
>
> My requirement is this: I have to gather data from 52 tables all of
> which have an identical structure.
This is very simple. Try this in a stored procedure.
TableName varchar2(32);
BEGIN
LOOP
TableName := 'table1';
use dynamic SQL here to put together your select statement. You can change the table, the fields, the where clause, whatever youwould like.
put a DECODE here to take the value of TableName and replace it with the next value.
Make the name of the last table "EXIT" and also make the default "EXIT".
IF TableName = 'EXIT' THEN EXIT; END IF;
Daniel A. Morgan Received on Mon Aug 17 1998 - 02:04:26 CDT