Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Help, SQL Problem!!!

Re: Help, SQL Problem!!!

From: EXE <exe_at_exesolutions.com>
Date: Mon, 17 Aug 1998 00:04:26 -0700
Message-ID: <35D7D5FA.F66BDCD@exesolutions.com>


> 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 you
would 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;

   END LOOP;
END; Regards,

Daniel A. Morgan Received on Mon Aug 17 1998 - 02:04:26 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US