Domanda

I'm trying extract the number of rows using the count(*) with the respect of it's condition and sending it to a variable for later use.

How do I create variables for the number of rows within a table. Thank you.

VARIABLE 
VAR CHAR(10)

SELECT COUNT(*) INTO :VAR 

FROM [Database]
WHERE [condition 1]
AND [condition 2]
È stato utile?

Soluzione

You need to use PL/SQL to do the select:

SQL> variable var number
SQL> begin
  2     select count(*)
  3     into :var
  4     from all_tables
  5     where owner = user;
  6  end;
  7  /

PL/SQL procedure successfully completed.

SQL> print var

       VAR
----------
       163

Altri suggerimenti

What about passing the result of the whole query to the variable?

VARIABLE 
VAR CHAR(10)

(
SELECT COUNT(*) 
FROM [Database]
WHERE [condition 1]
AND [condition 2]
)
INTO :VAR
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top