We help IT Professionals succeed at work.
Get Started

setting local variables in a cursor block

LuckyLucks
LuckyLucks asked
on
182 Views
Last Modified: 2018-02-02
Hi

I want to set the cntpm local var in my PL/SQL block. This value is originally returned from a SQL that uses the present cursor variable. But I get an error in my code.

DBMS_OUTPUT.ENABLE;
DECLARE CNTPM INTEGER;

  CURSOR c1 IS
    SELECT distinct proj_code from all_projects_plan ;
   
  BEGIN
  FOR item IN c1
  LOOP
 
    SET CNTPM =: select count(distinct pm) from MYTABLE where pmloc= 'NA' and p_code = item.proj_code

    DBMS_OUTPUT.PUT_LINE('Project = ' || item.proj_code || ' with number of project managers = ' || CNTPM );
   
    IF CNTPM > 1 THEN DBMS_OUTPUT.PUT_LINE ('Several Project managers')
    ELSE  DBMS_OUTPUT.PUT_LINE ('just one project manager');
     
  END LOOP;
END;

Error starting at line : 1 in command -
DBMS_OUTPUT.ENABLE
Error report -
Unknown Command
Comment
Watch Question
Database Developer & Administrator
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2012
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE