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

  • Home
  • SEARCH
  • 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 7410015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:10:03+00:00 2026-05-29T06:10:03+00:00

I have a select statement that I am trying to loop over and increment

  • 0

I have a select statement that I am trying to loop over and increment a variable based on the condition of the select statement, then return the variable as an out so I can do something with it in some front end code. I am using oracle 11g and I am seeing a few ways I can do this… but I am not sure which is the best way. I have some of what I am trying to do below, but again stopped because of confusion.

First I am setting my proc and ‘in variable’

PROCEDURE SEEKER (pMonkeyID IN Number, vMarkCounter OUT Number)
AS
BEGIN

CURSOR seeker_cur IS
    Select Mokney_approved, Monkey_vaulted 
    from MonkeyBookApps 
    where MonkeyID = pMonkeyID
    and Monkey_doc_type = 'BANANA' 
    order by docu_approv_timestamp,monkey_doc_type,monkey_doc_approved desc

OPEN seeker_cur;

begin

   OPEN Seeker_cur;
   vMarkCounter := 0;

Here is the part I am not sure about. Should I loop and then exit if the condition is not met or should I do an if statement and somehow determine if there is a record that could be greater than one? If so how would that work? Is there a benefit to doing one way over the other? So… I am going to sudo-code what I am trying to do (below):

FOR (however many records) in Seeker_cur
IF seeker_cur (not found) or (returns no records)

EXIT or (break for loop);
ELSE
LOOP

vMarkCounter := vMarkCounter + 1;

EXIT WHEN seeker_cur is out of records (somehow)
END IF;
END LOOP;

END; 
END SEEKER;

I am sure there are a few ways to do this. What ways would you suggest?

  • 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-29T06:10:04+00:00Added an answer on May 29, 2026 at 6:10 am

    why dont you use implicit cursor , it will open and close itself:

    DECLARE
    
    CURSOR seeker_cur IS
        Select Mokney_approved, Monkey_vaulted 
        from MonkeyBookApps 
        where MonkeyID = pMonkeyID
        and Monkey_doc_type = 'BANANA' 
        order by docu_approv_timestamp,monkey_doc_type,monkey_doc_approved desc;
    
      vMarkCounter number:=0;
    
    BEGIN
    
      FOR i IN seeker_cur 
      LOOP
        vMarkCounter := vMarkCounter+1;
      END LOOP;
    
      dbms_output.put_line(vMarkCounter);
    END;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a perplexing SQL select statement (ugly) that I'm trying to write in
I have a SELECT CASE statement that I am trying to get working. Essentially
I have a table that I need a MYSQL Select statement so I can
I am trying to find a way to have a SELECT statement return the
Suppose I have a SELECT statement that returns some set of results. Is there
I have a SQL statement that looks like: SELECT [Phone] FROM [Table] WHERE (
I have A Script that has a Select statement to go to multiple sub
I have a relatively simple select statement in a VB6 program that I have
I have to following SQL Statement that I want to conver to LINQ Select
I have a query that makes several calls within a SELECT statement to a

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.