Quantcast
Channel: Andrew's Oracle Blog
Viewing all articles
Browse latest Browse all 330

ORA-00909

$
0
0
You can count the number of different values in a column as follows:

SQL> select count(distinct owner)
  2  from dba_tables
  3  /

COUNT(DISTINCTOWNER)
--------------------
                  17

SQL>

But if you try to do this with more than 1 column, it does not work:

SQL> select count(distinct owner, table_name)
  2  from dba_tables
  3  /
select count(distinct owner, table_name)
      *
ERROR at line 1:
ORA-00909: invalid number of arguments

SQL>

There are a couple of ways to avoid this error. You can concatenate the columns into one:

SQL> select count(distinct(owner||table_name))
  2  from dba_tables
  3  /

COUNT(DISTINCT(OWNER||TABLE_NAME))
----------------------------------
                              829

SQL>

... or you can use a subquery:

SQL> select count(*) from
  2  (select distinct owner, table_name
  3  from dba_tables)
  4  /

  COUNT(*)
----------
       829

SQL>

Viewing all articles
Browse latest Browse all 330

Trending Articles