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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:53:03+00:00 2026-05-17T20:53:03+00:00

Im using a cursor to go over some data but I need to declare

  • 0

Im using a cursor to go over some data but I need to declare diferents sql statments according to a parameter. The problem seems to be that Im no able to use if statmets into this declaratios:

DECLARE
   CURSOR c IS SELECT * FROM TRAFICO
              IF TipoConsulta = 'mes' then
          BEGIN   
             WHERE TO_CHAR(FECHA_BUSQUEDA, 'MM-YYYY') =To_CHAR(ADD_MONTHS(SYSDATE, -1), 'MM-YYYY')                 
          ELSE                  
              WHERE FECHA_BUSQUEDA >=  SYSDATE -7                  
          END IF;
          ORDER BY ID_TRAFICO;
begin   
  FOR r IN C LOOP
      BEGIN
          Utl_File.Put_Line(Arch, r.ID_TRAFICO );
          i:=i+1;          
      END;
  END LOOP;
END;

I just need to change the sql statment using an if.

How do I do this??

TNKS

  • 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-17T20:53:03+00:00Added an answer on May 17, 2026 at 8:53 pm

    try using a dynamic cursor REF CURSOR (i’m assuming TripoConsulta is a variable and not one of the predicates of the query):

    declare
    type some_cursor is ref cursor;
    my_cursor some_cursor;
    my_rec trafico%rowtype;
    
    begin
    
      if TripoConsulta = 'mes' then
        open my_cursor for select * from trafico where ...;
      else 
        open my_cursor for select * from trafico where ...;
      end if;
      loop
        fetch my_cur into my_rec;
        exit when my_cur%notfound;
        Utl_File.Put_Line(my_rec.Arch, my_cur.ID_TRAFICO );
      end loop;
      close my_cursor;
    end;
    

    Clearly, i don’t know what the variable all mean so i had to make a number of assumptions, but i’m thinking this is what you meant. I also don’t guaranetee the syntax since i haven’t actually tested it.

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

Sidebar

Related Questions

Is there some library for using some sort of cursor over a file? I
I am using a Cursor in my stored procedure. It works on a database
I have a bad habit of using the cursor keys of my keyboard to
In sybase, using a cursor can one delete the currently referenced row? If so
On several of my usercontrols, I change the cursor by using this.Cursor = Cursors.Wait;
I am using SetCursor to set the system cursor to my own image. The
How do you set the cursor position in a text field using jQuery? I've
Using online interfaces to a version control system is a nice way to have
Using PyObjC , you can use Python to write Cocoa applications for OS X.
Using ASP.NET MVC there are situations (such as form submission) that may require 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.