|
Re: Table name which has the maximum columns [message #11239 is a reply to message #11235] |
Mon, 15 March 2004 06:19 |
Art Metzer
Messages: 2480 Registered: December 2002
|
Senior Member |
|
|
How does this query perform? (Note, uses analytic functions and therefore requires at least version 8.1.6.)SELECT schema_name
, table_name
, max_cols
FROM (SELECT u.name schema_name
, o.name table_name
, COUNT(*) cols
, MAX(COUNT(*)) OVER () max_cols
FROM sys.col$ c
, sys.obj$ o
, sys.user$ u
WHERE u.name = UPPER('<font color=red><i>your_schema</i></font>')
AND o.obj# = c.obj#
AND o.owner# = u.user#
AND o.type# = 2 -- tables only
AND BITAND(c.property, 32) = 0 -- non-hidden column
GROUP BY u.name
, o.name)
WHERE cols = max_cols Hope this helps,
Art.
|
|
|
|
Re: Table name which has the maximum columns [message #11261 is a reply to message #11251] |
Tue, 16 March 2004 11:54 |
Art Metzer
Messages: 2480 Registered: December 2002
|
Senior Member |
|
|
quote from Hem anand:
----------------------------------------------------------------------
I want the table name in the present schema and all user owned tables
----------------------------------------------------------------------
OK, so try this related query on for size:SELECT schema_name
, table_name
, max_cols
FROM (SELECT u.name schema_name
, o.name table_name
, COUNT(*) cols
, MAX(COUNT(*)) OVER () max_cols
FROM sys.col$ c
, sys.obj$ o
, sys.user$ u
WHERE u.name = UPPER(<font color=red>USER</font>)
AND o.obj# = c.obj#
AND o.owner# = u.user#
AND o.type# = 2 -- tables only
AND BITAND(c.property, 32) = 0 -- non-hidden column
GROUP BY u.name
, o.name)
WHERE cols = max_cols
/ USER returns the name of the session user (the user who logged on) with the datatype VARCHAR2.
HTH,
Art.
|
|
|
|