M
M
marselabdullin2020-10-28 16:21:06
Oracle
marselabdullin, 2020-10-28 16:21:06

How to loop through the value of a field in a table column?

I have a naprav label with naprav_id and naprav_name fields, I'm trying to write something like this:

For naprav_id in (select naprav_id from naprav)
Loop
   select naprav_name from naprav where naprav.naprav_id=naprav_id
Endloop;


I understand that this code is meaningless, but what is needed is the ability to go through the value of the fields in the loop. How can this be adequately implemented?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Y, 2020-10-28
@x_shader

The idea is something like this:

for your_cursor in (select naprav_id, naprav_name from naprav)
loop
  dbms_output.put_line('ID: '||your_cursor.naprav_id);
  dbms_output.put_line('Name: '||your_cursor.naprav_name);

  insert into some_other_table(name)
  values(your_cursor.naprav_name);

  -- и всякие другие варианты обращения к значению поля через your_cursor.имя_поля
end loop;
commit;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question