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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:21:35+00:00 2026-06-04T16:21:35+00:00

Is there a way to do a for each in oracle, something like this:

  • 0

Is there a way to do a “for each” in oracle, something like this:

begin
  for VAR in {1,2,5}
  loop
    dbms_output.put_line('The value: '||VAR);
  end loop;
end;

I know you can do something like:

begin
  for VAR in 1..5
  loop
    if VAR in(1,3,5) then
      dbms_output.put_line('The value: '||VAR);
    end if;
  end loop;
end;

But isn’t there a way to do this in a nicer way? Defining a set of values and iterating through them?

Thanks.

  • 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-04T16:21:36+00:00Added an answer on June 4, 2026 at 4:21 pm

    You could do this, though probably not as slick as you’d like:

    declare
      type nt_type is table of number;
      nt nt_type := nt_type (1, 3, 5);
    begin
      for i in 1..nt.count loop
        dbms_output.put_line(nt(i));
      end loop;
    end;
    

    If you create a type in the database:

    create type number_table is table of number;
    

    then you can do this:

    begin
      for r in (select column_value as var from table (number_table (1, 3, 5))) loop
        dbms_output.put_line(r.var);
      end loop;
    end;
    

    Also, as A.B.Cade has commented below there are database types that come with Oracle that you can use, such as sys.dbms_debug_vc2coll:

    begin
      for r in (select column_value as var from table (dbms_debug_vc2coll (1, 3, 5))) loop
        dbms_output.put_line(r.var);
      end loop;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is the there a way to multiply each NSNumber contained in the array by
Is there a way to offset the 'each' iteration when using the Jade template
Is there a way I can programatically move my screens in relation to each
Is there any way to do some kind of while() for each post variable
Is there any way to Use the Builtin ScrollBars that comes with each .Net
Is there any way I can print/show images on top of each other. The
Is there a way to have different Global Configurations for each section of articles?
Is there a way that i can save data on each step in wizard
Is there a way to see how many context switches each thread generates? (both
Is there a way to get a report of how long each test is

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.