Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Populate all rows in partition based on value of first row?

763900Sep 7 2010 — edited Sep 7 2010
Hello,

select
all_catalog.*
, ROW_NUMBER( ) OVER ( PARTITION BY TABLE_TYPE
ORDER BY
OWNER ASC,
TABLE_NAME ASC
) rn
, COUNT (*) OVER ( PARTITION BY TABLE_TYPE
) rcnt

from all_catalog

I would like to apply a count of all rows in a partition, when the first row of the partition passes a certain criteria.

In the above example let's take the first rows and a later one returned which is:
OWNER | TABLE_NAME | TABLE_TYPE | RN | RCNT
DISC | EUL4_ID_SEC | SEQUENCE | 1 | 82
DISC | EUL4_ID_SEC | SEQUENCE | 1 | 82
etc............
...................
ABS_SRV | ABS_SURV_P | SYNONYM | 1 | 18998
PUBLIC | V$SGA | SYNONYM | 13811| 18998

Let's imagine that the criteria which I need the first row of the partition to pass is that the OWNER in rn 1 of partition be 'DISC'. As you can see the first partition (table_type 'sequence') passes this criteria and I would like each and every row within this partition to be populated with the count of all rows (rcnt) within that partition (here 82). The second partition (table_type 'synonym') does not pass the criteria, and I would like to assign a zero value to all rows within that partition.

Would anybody know how to do this? I've figured out how to apply a value using CASE WHEN where rn=1, but I can not figure out how to extend it to all rows within the partition?

Any help very gratefully received :)

Thanks!

Jon
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 5 2010
Added on Sep 7 2010
2 comments
1,303 views