Skip to content
Advertisement

Translation from Java to Oracle SQL: use every element into a loop as result of a SELECT statement [closed]

It’s my first time using Oracle function. I’m trying to translate this piece of code in Java to Oracle SQL.

JavaScript

My translation:

JavaScript

Advertisement

Answer

Suppose you want to do something for each EMPNO in a table, EMP, in schema SCOTT. (Almost every Oracle database installation has a standard schema, SCOTT; one of the tables is EMP, with primary key EMPNO. This is often used for testing and illustrations.)

To do something with each value of EMPNO in a loop, in PL/SQL, you would do something like this:

JavaScript

Note that there is no “array index” here – you reference “records” directly. (By the way, if you want the rows to be processed in some specific order, you include that in an order by clause directly in the select statement!)

Although you can write this much more compactly (no equivalent in Java, I think):

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement