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 7792141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:06:01+00:00 2026-06-01T22:06:01+00:00

Hello I’m a bit baffled that the cursor I have in this function is

  • 0

Hello I’m a bit baffled that the cursor I have in this function is only returning the top row.

I’ve been comparing it to a few different examples I’ve seen and I just don’t see what’s wrong. Any guidance is greatly appreciated.

FUNCTION FS_A_FUNCTION
(
    inDate DATE
)
RETURN VARCHAR2 IS

tAnswer     VARCHAR2(1)  := 'N';
tDates DATE;

CURSOR c1 IS

SELECT S.Dates FROM A_TABLE S;

BEGIN 
OPEN c1;
LOOP
    FETCH c1 INTO tDates;
    EXIT WHEN c1%NOTFOUND;
END LOOP;
CLOSE c1;

IF inDate IN (tDates) THEN
tAnswer := 'Y';

END IF;

RETURN (tAnswer);


END FS_A_FUNCTION

Thanks in advance.

  • 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-06-01T22:06:03+00:00Added an answer on June 1, 2026 at 10:06 pm

    Not quite sure what you’re expecting to happen. After your loop tDates will have a single value from whichever row the cursor saw last. As your select doesn’t have an order by, that could be any value from your table. I think you may mean to be checking the value against inDate inside the loop.

    I’m not sure why you’re using a cursor at all, unless the real logic is more complicated. If you’re doing what I think, you could just do something like:

    FUNCTION FS_A_FUNCTION
    (
        inDate DATE
    )
    RETURN VARCHAR2 IS
        tAnswer VARCHAR2(1);
    BEGIN
        select decode(max(dates), null, 'N', 'Y')
        into tAnswer
        from a_table
        where dates = inDate;
    
        RETURN tAnswer;
    END FS_A_FUNCTION;
    

    … or maybe a bit clearer bu the same logic:

    FUNCTION FS_A_FUNCTION
    (
        inDate DATE
    )
    RETURN VARCHAR2 IS
        tDates DATE;
    BEGIN
        select max(dates)
        into tDates
        from a_table
        where dates = inDate;
    
        IF tDates IS NULL THEN
            RETURN 'N';
        ELSE
            RETURN 'Y';
        END IF;
    END FS_A_FUNCTION;
    

    In both cases I’m using max() in case there are multiple rows with the same date.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have this problem with PyQt4-dev-tools that include: * a user interface compiler
Hello I am working with a simulator that uses rcS scripts to boot, this
Hello i have a TextField on my scene. It haves only digits, user input
Hello i have this code var queue = new BlockingCollection<int>(); queue.Add(0); var producers =
Hello I have this query... if (isset($_REQUEST['deletePost'])) { $q = $dbc -> prepare(DELETE FROM
Hello Stack Overflow users, I have a fun problem that I have in my
Hello I am making this call: $parts = $structure->parts; Now $structure only has parts
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello can anybody solve this please I'm creating the object in the action class
Hello we have an SQL server application running over a low bandwith connection. We

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.