Posted: 11/16/2004 5:51:48 AM EDT
|
I want to take a table I have, read it in a row at a time, and change/update the values in some of the fields in each row using std programming logic (loops, if then, declaring variables, etc). I haven't used any of the pl/sql crap before, just the normal query stuff (select, create tables, decode, etc.). I could do what I need using the normal query tools, but it's getting to be a pain in the ass. I want to see if the pl/sql tools can make it easier, Suppose I have a table with lots of rows and columns A,B,C,D etc. Is it possible to do somethign like grab a row, create a dummy variable set dummy = 0 do a loop while dummy is less than the value in column B of the row dummy = dummy + 1 end the loop column C = dummy if column D > column C then column D = .223 get the next row etc. The result being that after I run the code, the table I started with has been altered with the calculations I do in the code being applied to each row. The only book I have is "oracle the complete reference" book from oracle. It has a couple of small sections on pl/sql, but it doesn't have many examples of using pl/sql to do things. Are things like what I describe above possible? If so, can you give me some example code? |
|
It's been forever since I've programmed in PL/SQL. What you're looking for is a "cursor". If someone hasn't responded with the answer by the time I get home, I'll post a simple sample. ETA: Here's a simple sample -- www.fluffycat.com/sql/sql-cursor-oracle.html google for "pl/sql cursor" for more |
|
|
Here is an example of a TSQL cursor query (you'd have to port it to PL/SQL):
HTH... |
I avoided doing that myself because T-SQL & PL/SQL are very different syntactically when it comes to cursors. FYI, there's very little that ports *easily* between the two. |