Re: Using variables in FROM clause?

From: José M Gómez Martín <jgomez_at_sgosoft.com>
Date: 1998/01/18
Message-ID: <34C1FA02.5652_at_sgosoft.com>#1/1


It's a good way, but not the "only". What about: declare
  cursor curs is
   select count(*)
     from mytab
    where today = 'monday'
   union all
   select count(*)
     from yourtab
    where nvl(today,'*')!='monday';
  c1 number;
begin
  open curs;
  fetch curs into c1;
  close curs;
end;

-- 
José M. Gómez Martín
SGO Software
Barcelona (Spain)
jgomez_at_sgosoft.com
--

>
> >In PL/SQL can you use a variable in the FROM clause of a 'select' statement
> >or do you have to use the DBMS_SQL package to do this. For example, the
> >following shows what I'd like to do:
> >
> >tab1 varchar(30) ;
> >c1 number(5);
> >today varchar(10) := 'monday';
> >
> >if today = 'monday' then
> > tab1 := 'mytab' /* mytab and yourtab a different tables
*/
> >else
> > tab1 := 'yourtab';
> >
> >select count(*) into c1 from tab1;
> >

> If you are use Forms or a procedure, the DBMS_SQL package is the only option.
Received on Sun Jan 18 1998 - 00:00:00 CET

Original text of this message