|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
For Loop using 'i'
All right...
I'm trying to develop a for-loop to basically do as follows: for i in 1..4 loop select value into variablename[i] from table; end loop; That's the basic gyst of it; a lot like you would in a language like ActionScript or PHP and whatnot... Is there a way to accomplish this in SQL? |
|
#2
|
||||
|
||||
|
you cant do that in sql. To create that using a database you would have to use stored procedure.
|
|
#3
|
|||
|
|||
|
You actually would need to code it in PL/SQL, something like this:
Code:
Declare
I Pls_Integer;
Type Chr_Typ Is Table Of Varchar2(30)
Indexed By Pls_Integer;
Var Chr_Typ;
Begin
For I In 1..10
Loop
Select The_Value Into Var(I)
From My_Table Where Id = I;
End Loop;
End;
/
![]()
__________________
|
|
#4
|
|||
|
|||
|
Quote:
I'm a litlte confused by your code... where is My_Table? Actually I'm having a lot of trouble understanding what most of the first half means. |
|
#5
|
||||
|
||||
|
Executing a query in a loop is ugly and a performance killer, 99% of times this should be done with a join
__________________
My blog about OpenSource Databases PDF tutorials about OSS databases, DBMonster ... Please contribute to Open Source Development, fill bug reports!!! Developer Shed eSupport Commented my.ini/my.cnf (PLEASE ADD YOUR OWN CONFIG TRICK) An introduction to database normalization Natural or Surrogate key Custom ordering for your results Correlated and uncorrelated subqueries Don't turn your outer joins into inner joins |
|
#6
|
|||
|
|||
|
Quote:
Maybe you don't even understand what you are asking for. ![]() Your request seems to be just an exercize in futility with no real purpose whatsoever...or do you have any actual requirements you wish to share with us? PS: I substituted the Oracle "reserved words" you were using in your example (like 'value' and 'table') with 'the_value' and 'my_table'. |
|
#7
|
|||
|
|||
|
Quote:
Again, I can't hlep but take your first statement as an insult with that litlte smiley you put in. In any case, I solved the problem and this is no longer an issue... |
|
#8
|
||||
|
||||
|
Quote:
with SQL or ? would be nice if you can post the solution, maybe other can benefit from it too. |
![]() |
| Viewing: Dev Shed Forums > Databases > Oracle Development > For Loop using 'i' |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|