Home » SQL & PL/SQL » SQL & PL/SQL » How to assign record count to a variable
How to assign record count to a variable [message #300387] Fri, 15 February 2008 04:52 Go to next message
mivey4
Messages: 19
Registered: March 2007
Junior Member
Hi,

I am trying to help a colleague correct a syntax error within a PL/SQL procedure. I know where the error is occuring but at a lost for how to correct it.

In short, can anyone provide the functional equivalent for the following SQL statement in PL/SQL format?

SQL VERSION
***************************************
Declare @varNum INT
SELECT @varNum = count(*) from myTable
***************************************

ORACLE VERSION ???
***************************************
varNum NUMBER;

***************************************

I want to assign the record count from myTable to the variable varNum using the PL/SQL syntax but clueless for how you'd accomplish this using the ORACLE syntax; I know how to perform simple variable assignments but not how to assign the results returned from a record set. I know this is probably a no brainer but that's why I am here. Embarassed

Any help at all would be greatly appreciated.

Thanks.
Re: How to assign record count to a variable [message #300388 is a reply to message #300387] Fri, 15 February 2008 04:56 Go to previous messageGo to next message
amardeep.sidhu
Messages: 7
Registered: October 2007
Junior Member
If you are looking for PL/SQL, then declare a variable say v_count then do it like:

select count(*) into v_count from blah;

Sidhu
Re: How to assign record count to a variable [message #300391 is a reply to message #300387] Fri, 15 February 2008 05:02 Go to previous messageGo to next message
Michel Cadot
Messages: 64140
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
If you are trying to convert Sybase/MS SQL Server code into PL/SQL without reading PL/SQL User's Guide and Reference, you will fail.

In addition, please read and follow OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code and align the columns in result.
Use the "Preview Message" button to verify.
Always post your Oracle version (4 decimals).

Regards
Michel

[Updated on: Fri, 15 February 2008 05:05]

Report message to a moderator

Re: How to assign record count to a variable [message #300395 is a reply to message #300391] Fri, 15 February 2008 05:13 Go to previous message
mivey4
Messages: 19
Registered: March 2007
Junior Member
Thanks for assisting amardeep.sidhu I really appreciate the guidance.
Also thanks to Michel for the recommendations, I will do this upon my next post and refer to the link you provided as well. Failure is most definitely not what I want to acheive. Smile
Previous Topic: Problem with %ROWTYPE
Next Topic: help to search text in package
Goto Forum:
  


Current Time: Fri Dec 09 04:23:39 CST 2016

Total time taken to generate the page: 0.12216 seconds