Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6795693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:22:39+00:00 2026-05-26T18:22:39+00:00

The below mentioned procedure is intended to: fetch jobids from cp_work_card which exist in

  • 0

The below mentioned procedure is intended to:

  1. fetch jobids from cp_work_card which exist in cpTemplateWorkCard
  2. Fetch the first record of bhours for the jobid from the cp_work_card
  3. update the same to cpTemplateworkCard

Hwoever, all the rows of cpTemplateworkCard are updated with the value of bHours found in last row. But, the values in the variable are stored correctly while execution

DECLARE
     jobId       VARCHAR2(30);
     bHours      float;
     idx         NUMBER(4,0);
     CURSOR         c1 
     IS
        select distinct 
               cp.job_id 
          from cp_work_card cp,
               cptemplateworkcard temp 
         where cp.job_id = temp.JOBID;
BEGIN
   idx:=1;
   DBMS_OUTPUT.PUT_LINE('id : jobId  :  bHours');
   OPEN c1;
   LOOP
      FETCH c1 INTO jobId;
      EXIT WHEN C1%NOTFOUND;
      select cpw.BUDGET_HOUR 
        into bHours 
        from cp_work_card cpw 
       where cpw.job_id=jobId 
         AND rownum<2;
      /*DBMS_OUTPUT.PUT_LINE('Budget Hours: '||bHours);

      UPDATE TO CPTEMPLATE*/

      UPDATE cptemplateworkcard tmpCard 
         SET tmpCard.BUDGET_HOUR=bHours 
       where tmpCard.JOBID=jobId;

      DBMS_OUTPUT.PUT_LINE(idx || ' : ' || jobId || ' : ' || bHours);
      idx:= idx+1;

   END LOOP;

   CLOSE c1;
END;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:22:40+00:00Added an answer on May 26, 2026 at 6:22 pm

    Couldn’t you achieve the same with a single SQL update statement?

    UPDATE cptemplateworkcard tmpcard
       SET tmpcard.budget_hour = (SELECT budget_hour
                                    FROM cp_work_card cp
                                   WHERE cp.job_id = tmpcard.jobid
                                     AND rownum < 2)
     WHERE EXISTS
          (SELECT 1 
             FROM cp_work_card cp
            WHERE cp.job_id = tmpcard.jobid);
    

    I haven’t tested this but the principle is the same…

    EDIT: Given your constraints and if you must use a procedure then could you not:

    DECLARE
       CURSOR c1
       IS
          SELECT DISTINCT
                 cp.job_id,
                 cp.budget_hour
            FROM cp_work_card cp
           INNER JOIN cptemplateworkcard temp
              ON (cp.job_id = temp.jobid)
           WHERE rownum < 2;
    BEGIN
       DBMS_OUTPUT.put_line( 'job_id  :  budget_hour' );
    
       FOR c_rec IN c1
       LOOP
          UPDATE cptemplateworkcard tmpcard
             SET tmpcard.budget_hour = c_rec.budget_hour
           WHERE tmpcard.jobid = c_rec.job_id;
    
          DBMS_OUTPUT.put_line( c_rec.job_id || ' : ' || c_rec.budget_hour );
       END LOOP;
    END;
    

    EDIT:
    FYI, your current procedure isn’t working because you have named your variable holding the job ID as jobId which also happens to be the name of a column in the table cptemplateworkcard. Therefore when you perform your update it defaults to thinking your WHERE clause is comparing the table column with itself thereby updating every row with whatever the value of bHours is. When the procedure has finished, obviously the last value of bHours what the final value returned from the cursor hence you are seeing all the values in the table set to this final value.

    If you rename your jobId variable to something like v_jobid then it should solve the problem.

    Hope it helps…

    If the only constraint is that it must be in a PL/SQL procedureal block then this will be the most efficient procedure:

    BEGIN
       UPDATE cptemplateworkcard tmpcard
          SET tmpcard.budget_hour = (SELECT budget_hour
                                       FROM cp_work_card cp
                                      WHERE cp.job_id = tmpcard.jobid
                                        AND rownum < 2)
        WHERE EXISTS
             (SELECT 1 
                FROM cp_work_card cp
               WHERE cp.job_id = tmpcard.jobid);
    
       DBMS_OUTPUT.put_line(SQL%rowcount||' record(s) updated');
    END;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please help with below mentioned scenario-> I am having wanna display values from 1
HI all, Below mentioned javascript code works fine in all browsers including chrome(from second
I am using the below mentioned library to create a barcode which is storing
Below mentioned stored procedure is giving error while creating Msg 156, Level 15, State
I have a stored procedure mentioned as below. I'm using SQL Server 2008 R2.
I have tried fetching the ip from below mentioned methods HttpContext.Current.Request.ServerVariables[HTTP_X_FORWARDED_FOR] & Request.UserHostAddress &
Below mentioned is my XML, <?xml version=1.0 encoding=utf-8?> <soap:Envelopexmlns:soap=http://schemas.xmlsoap.org/soap/envelope/xmlns:xsi=http://www.w3.org/2001/XMLSchema-instancexmlns:xsd=http://www.w3.org/2001/XMLSchema> <soap:Body> <Response xmlns=http://tempuri.org/> <Result> <mp_response>
My below mentioned code still submits form on special character in name field. Validation
I am getting the below mentioned error while loading the JSF page. The page
I the below mentioned program: string s; cout<<Enter a string:; gets(s); I expect my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.