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;
timestamp '2019-06-27 11:15:00'
/*
with channel_program as (
select 1 as channel_id, 1 as program_id, timestamp '2019-06-27 09:00:00' as start_time, timestamp '2019-06-27 10:00:00' as end_time union all
select 1 as channel_id, 2 as program_id, timestamp '2019-06-27 10:02:00' as start_time, timestamp '2019-06-27 11:00:00' as end_time union all
select 1 as channel_id, 3 as program_id, timestamp '2019-06-27 11:10:00' as start_time, timestamp '2019-06-27 11:30:00' as end_time union all
select 1 as channel_id, 4 as program_id, timestamp '2019-06-27 11:35:00' as start_time, timestamp '2019-06-27 12:00:00' as end_time union all
select 1 as channel_id, 4 as program_id, timestamp '2019-06-27 12:00:00' as start_time, timestamp '2019-06-27 12:30:00' as end_time
)
*/
select t.program_id
from (
select
program_id
,lag(start_time) over (order by start_time) lag_start_time
,lead(end_time) over (order by start_time) lead_end_time
from channel_program
) t
where timestamp '2019-06-27 11:15:00' between coalesce(t.lag_start_time, timestamp '1991-01-01 00:00:00')
and coalesce(t.lead_end_time, timestamp '2999-01-01 00:00:00')
with great_design_tab as (
select 700 as id, '1,11,32,531' as ass_pain from dual union all
select 701 as id, '2, 44, 321' as ass_pain from dual
)
,usrs as (
select 1 as id, 'вася' as username from dual union all
select 11 as id, 'петя' as username from dual union all
select 32 as id, 'костя' as username from dual union all
select 531 as id, 'дима' as username from dual union all
select 2 as id, 'жора' as username from dual union all
select 44 as id, 'изя' as username from dual union all
select 321 as id, 'семен' as username from dual
)
select u.id, u.username, t.id
from usrs u
,great_design_tab t
,lateral (
select level x from dual
connect by regexp_substr(ass_pain, '[^,]+', 1, level) is not null
)
where u.id = trim(regexp_substr(ass_pain,'[^,]+', 1, x));
ID USERNAME ID
---------- -------- ----------
1 вася 700
11 петя 700
32 костя 700
531 дима 700
2 жора 701
44 изя 701
321 семен 701
WITH dt_range AS (
SELECT TRUNC (&dt_start + ROWNUM - 1) dt
FROM DUAL CONNECT BY ROWNUM <= &dt_end - &dt_start + 1
)
,bal AS (
SELECT 101 id_, to_date('20171130', 'yyyymmdd') date_, 50 sum_ FROM DUAL UNION ALL
SELECT 101, to_date('20180102', 'yyyymmdd'), 300 FROM DUAL UNION ALL
SELECT 101, to_date('20180105', 'yyyymmdd'), 500 FROM DUAL UNION ALL
SELECT 101, to_date('20180107', 'yyyymmdd'), 700 FROM DUAL
)
SELECT id_ --MAX(id_) OVER (PARTITION BY grp) id_
,dt
,MAX(sum_) OVER (PARTITION BY grp) sum_
FROM (
SELECT t1.*
,SUM(start_of_group) OVER(ORDER BY t1.dt) grp
FROM (
SELECT bal.id_
,dt_range.dt
,bal.sum_
,CASE WHEN bal.sum_ IS NOT NULL THEN 1 END start_of_group
FROM dt_range
LEFT JOIN bal ON dt_range.dt = bal.date_
) t1
)
ORDER BY dt
SELECT DISTINCT CITY, AREA, REGION FROM youtube
SELECT CITY, AREA, REGION
FROM youtube
GROUP BY CITY, AREA, REGION
SELECT "CITY" || ' | ' || "AREA" || ' | ' || "REGION" FROM (
SELECT CITY, AREA, REGION
FROM youtube
GROUP BY CITY, AREA, REGION) t