simple query Delete records in a table based on count logic
Posted
by
user1905941
on Stack Overflow
See other posts from Stack Overflow
or by user1905941
Published on 2012-12-18T11:01:58Z
Indexed on
2012/12/18
11:02 UTC
Read the original article
Hit count: 133
a table with a pk and status column which is having values as 'Y','N','NULL'
Query:
get the count of records with status column as 'Y', if this count exceeds 1% of total count of records then dont delete , else delete the records in the table.
i tried like this
Declare
v_count Number;
v_count1 Number;
BEGIN
v_count := select count(*) from temp;
v_count1 := select count(*) from temp where status = 'Y' ;
v_count := v_count + ((0.1) * (v_count))
if (v_count1 > v_count)
{
insert into temp1 values(pk,status)
}
else
{
Delete from temp ;
}
END;
© Stack Overflow or respective owner