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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:59:32+00:00 2026-05-27T13:59:32+00:00

I have a cursor which returns two values: one which I will use (and

  • 0

I have a cursor which returns two values: one which I will use (and therefore will assign to an out variable) and another which I’ve only had returned to make the ROWNUM thing work.

If I run the cursor as a query, it works as expected. But if I execute the procedure the out variable comes empty. Is my approach somehow not supported? I mean, returning two values but only using one of them?

Here is my procedure code: (Don’t delve too much on the query itself. It works, I know it’s a bit ugly but it works. It was the only way I found to return the second-last row)

procedure retorna_infos_tabela_164(i_nip in varchar,
                               o_CODSDPANTERIOR out number) is
cursor c_tabela_164 is
    select *
    from(
        select CODSDP,ROWNUM rn
        from
              (
                select NRONIP,CODTIPOMOV,CODSDP
                from TB164_HISTORICOMOVIMENTACOES
                where NRONIP = i_nip and
                CODTIPOMOV='S1'
                order by DTHMOV desc
              )
        )
    where rn=2;

    v_temp_nr number;

begin
    open c_tabela_164;
    fetch c_tabela_164 into o_CODSDPANTERIOR,v_temp_nr;
    close c_tabela_164;
end retorna_infos_tabela_164; 

EDIT The way I’ve tried to run this procedure was by dbms_output.put_line(o_CODSDPANTERIOR) which didn’t work. Then I googled a little bit and saw I should TO_CHAR() my var first and then have it output. Didn’t work either.

  • 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-27T13:59:33+00:00Added an answer on May 27, 2026 at 1:59 pm

    I’m sorry I’ve had you guys take the time to answer me when the answer was something to do with the tool I’m using. I hope all you guys have learnt something.

    The query does work for me at least, I’ve not come across any edge cases where it doesn’t work, but I haven’t tested it exhaustively.

    The problem was that TOAD, the tool I’m using to run the procedures, sometimes populates the procedures with the parameters I tell it to but sometimes it doesn’t. The issue here was that I was trying to execute the procedure with no parameters, yielding no results…

    Lesson Learnt: double check the generated procedure code when you run a Procedure using Right Click > Run Procedure on TOAD version 9.

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

Sidebar

Related Questions

I have a stored procedure which returns a ref cursor as follows: CREATE OR
If I have a function which returns a reference cursor for a query, how
i have a Stored Procedure which returns output as a ref cursor. I would
I have a DataBaseHelper which has a fetchData() method that returns a Cursor containing
I have a stored procedure, which returns a cursor. The application passes a parameter
I have an SQLiteDatabase helper, which returns a cursor with just the name column
I have the following code in an oracle procedure, which returns a cursor (
I am creating a Control Library project. I have some Cursor files which i
I have the following Python code: cursor.execute("INSERT INTO table VALUES var1, var2, var3,") where
I have a simple query over a table, which returns results like the following:

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.