Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PL/SQL 101 Question: Value to Variable 3

Status
Not open for further replies.

Michael42

Programmer
Oct 8, 2001
1,454
US
Hello,

in PL/SQL how can I perform a count on a table (SELECT count(*) FROM table1;) and place the value in a PL/SQL variable?

Thanks,

Michael42

 
Hi

Code:
[b]declare[/b]
  [green][i]variable[/i][/green] [b]number[/b];
[b]begin[/b]
  [b]select[/b] count(*) [b]into[/b] [green][i]variable[/i][/green] [b]from[/b] [green][i]table[/i][/green];
[b]end[/b];

Feherke.
 
Code:
declare
v_count  number;
begin
    SELECT count(*)
    INTO   v_count
    FROM   dual;
    dbms_output.put_line('Count='||v_count);
end;
/

Count=1



Beware of false knowledge; it is more dangerous than ignorance. ~George Bernard Shaw
Consultant Developer/Analyst Oracle, Forms, Reports & PL/SQL (Windows)
My website: www.EmuProductsPlus.com
 
If you are talking about a sql*plus variable, then

column my_variable new_value my_variable noprint

select count(*) my_variable
from table1;

Bill
Oracle DBA/Developer
New York State, USA
 
Guys,

These are all VERY useful ways of handling this.

Thanks for posting! :)

Michael42
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top