Furkan Ayık Furkan Ayık - 3 months ago 14
SQL Question

Oracle getting count of select query

I have a procedure in oracle and I'm trying to fix errors. There is a line with error. Check out the line;

table_count := (SELECT * FROM AUDITCONFG_RANDOMQUESTIONS WHERE AUDIT_ID=audit_id).COUNT;


table_count
is a
NUMBER
type variable and I want set it that select query's row count. What should I do?

Answer

In PL/SQL to assign a query's result into a variable use select into syntax

SELECT count(*) into table_count 
FROM AUDITCONFG_RANDOMQUESTIONS 
WHERE AUDIT_ID = audit_id