Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Example code for an outer join for Oracle?
Beware of Outer-joins!!
These are very useful. However, at times cause full table scans on the table being outer-joined. That is, in the example below, the table2 will result in a full-table scan even if you specify an index hint.
In order to get around this performance problem, you can use in-line SQL functions. For example,
create function get_field2 ( vid in table2.id%type )
return field2type
as
cursor c_field2 is
select /*+ index(table2 table2-index-name) */ field2
from table2 where id = vid;
return output_field2;
end;
/
2. modify the select statement to make a call to the above function:
select table1.fielda, get_field2( table1.id ) fieldb from table1;
This will produce the same result. But, the performance gain in this case is quiet significant.
-Farah
R.Schierbeek wrote:
>
> Hey Mark,
>
> How about:
>
> select table1.fielda, table2.fieldb
> from table1
> ,table2
> where table1.id = table2.id(+)
>
> ------------------------------
> Roelof Schierbeek, DBA
> Bytelife BV
> The Hague, Holland
> email: bytelife AT worldonline.nl http://home.worldonline.nl/~bytelife
> check out : http://home.worldonline.nl/~bytelife/storage.htm
>
> Mark Cain <mark_at_alimar.demon.co.ukNOSPAM> schreef in artikel
> <3448d967.3775955_at_news.demon.co.uk>...
> > Can anyone give me a simple example of an outer right join, using 2
tables?
> >
> > I'm trying something like:
> >
> > select table1.fielda, table2.fieldb from table1 outer join table2 on
table1.id = table2.id
> >
> >
> > Thanks in anticipation
> > ---------------------------------------------------
> > | Mark Cain mark_at_alimar.demon.co.uk (remove NOPSAM)
> > | www.alimar.demon.co.uk
> > ---------------------------------------------------
> >
Received on Mon Oct 20 1997 - 00:00:00 CDT