Home » SQL & PL/SQL » SQL & PL/SQL » numeric for loop (oracle 11g)
numeric for loop [message #620874] Wed, 06 August 2014 14:04 Go to next message
tuckersuz
Messages: 26
Registered: July 2009
Junior Member
Hello:

I need to create a numeric for loop, with only 10 iterations, and it needs to show results in a dbms_output.put_line.

The values are retrieved from a query, and I need to show 5 results from a first query, and the other 5 from the same query, but with different filters. first query: select year, semester, type from table a, table b, where a.id = b.id, and year = '2011, semester = 'SPRING', and type = 1. The second query: select year, semester, type from table a, table b, where a.id = b.id, and year = '2012, semester = 'FALL', and type = 3. I think I need to have a constant for the loop, but I'm not sure how to do this. Any help is appreciated.

Thanks!

The desired output:

2011/SPRING/1
2011/SPRING/1
2011/SPRING/1
2011/SPRING/1
2011/SPRING/1
2012/FALL/3
2012/FALL/3
2012/FALL/3
2012/FALL/3
2012/FALL/3
Re: numeric for loop [message #620876 is a reply to message #620874] Wed, 06 August 2014 14:22 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
You don't need PL/SQL. Just use plain SQL.

Sql_query_1
UNION ALL
Sql_query_2

To limit the number of rows returned, use ROWNUM.

I insist, please post what you have tried so far and follow guidelines. Learn how to use code tags to post.

[Updated on: Wed, 06 August 2014 14:23]

Report message to a moderator

Re: numeric for loop [message #620879 is a reply to message #620874] Wed, 06 August 2014 14:37 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

With any SQL or PL/SQL question, please, Post a working Test case: create table (including all constraints) and insert statements along with the result you want with these data then we will be able work with your table and data. Explain with words and sentences the rules that lead to this result.

Re: numeric for loop [message #620881 is a reply to message #620879] Wed, 06 August 2014 14:38 Go to previous message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/ and read http://www.orafaq.com/forum/t/174502/
Previous Topic: Several updates vs one update
Next Topic: Creating MAT view - Long running
Goto Forum:
  


Current Time: Thu Apr 18 19:48:34 CDT 2024