Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: [Q]HowTo get the count of selected rows
Hello again,
I forgot to mention that one solution that works for the example in my first posting is:
CREATE OR REPLACE VIEW cntsql AS SELECT DISTINCT fld1,fld2 FROM table1; SELECT COUNT(*) FROM cntsql;
However, one cannot create a view with non-unique column names so the following would fail if a column name occured in both table1 and table2:
CREATE OR REPLACE VIEW cntsql AS SELECT DISTINCT * FROM table1,table2; SELECT COUNT(*) FROM cntsql;
Randall Smith
> Is it possible to construct a new SQL statement from an arbitrary
> SELECT statement which will always simply return the number of rows
> which would be selected by the original query?
>
> For example, suppose I had the following:
>
> SELECT DISTINCT fld1,fld2 FROM table1;
>
> How can one quickly determine the number of rows that this statement
> will match without actually returning the data. I could simply issue
> the query twice, and count the rows the first time, but I need
> better performance. If DISTINCT was not present in the query above,
> one could simply say
>
> SELECT COUNT(*) FROM table1;
>
> Using stored procedures is not an option for us at this point because
> our CORBA RDBMS server won't properly invoke stored procedures in
> Oracle. We are using Oracle 7.3.2.
>
Received on Fri Mar 14 1997 - 00:00:00 CST