Reputation: 8659
In Oracle how do you read a Count(*)
from a table into a variable?
In Microsoft SQL Server, you would do like
select @variable = count(*) from Table where x=1;
I tried similarly in Oracle to no avail:
SELECT v_count_of_rows_bad := Count(*) FROM SCHEMANAME.TABLENAME WHERE ...;
Upvotes: 0
Views: 86
Reputation: 958
Easy Peasie:
DECLARE
v_count_of_rows_bad NUMBER;
BEGIN
SELECT COUNT(*) INTO v_count_of_rows_bad FROM SCHEMANAME.TABLENAME WHERE ...;
END
Upvotes: 1
Reputation: 231741
You'd use a SELECT INTO
SELECT COUNT(*)
INTO v_count_of_rows_bad
FROM schemaname.tablename
WHERE ...
Upvotes: 2