1

I want to use the total number of records in a table in a variable of data type number, but I am not able to do this if I use the following statement :

row_num number;
row_num := select count(*) from emp;

I am trying to use this in a procedure .. what's the correct way to do it?

2 Answers 2

3

Assuming this is inside a PL/SQL procedure, the correct syntax is:

SELECT COUNT(*) INTO row_num FROM emp;
Sign up to request clarification or add additional context in comments.

Comments

1

Declare a variable and follow the query to copy count to a variable

DECLARE row_num NUMBER(10) := 0;

select count(*) into row_num from emp;

1 Comment

No need to initialise the variable, I think. Count always returns an integer greater then or equal to zero, and a projection that consists only of aggregate functions always returns a single row in the absence of a group by clause

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.