I have to do counts to the quantity of entitys in the database i have to obtain the quantity of registries for entities that appear
ENTITY OVERALL DATE HOUR
====== ===== ==== ====
ENT1 5 20100318 12:00
ENT2 20 20100318 12:00
ENT3 12 20100318 12:00
CURSOR1
SELECT distinct(rp.cod_entidad),
YYYYYYYYY,
to_date(to_char(SYSDATE,'YYYYMMDD'),'YYYY-MM-DD') as fecha_pago,
to_char(sysdate,'hh-mi-ss') as hora_pago
FROM registry rp, product pc
where pc.nro_solicitud = rp.nro_solicitud
and pc.resp_2= 'OK'
and pc.resp_1= 'OK'
Use a
GROUP BYon the column that you want to be unique.In order for PL-SQL to not complain you’ll have to use an aggregate function that will select a value for the other columns.
I’ve picked
MAX(), butMIN()or the non-existentwhatever()will do just as well.Implicit where join considered harmful
P.S. please don’t use that ugly implicit where join, it is confusing and bad practise, because you are mixing selection criteria with join criteria in your
whereclause for no reason whatsoever.We’ve had explicit join syntax since 1993, I warmly recommend it.
It will make writing correct queries much much easier and it will make your intentions clearer.