SlideShare ist ein Scribd-Unternehmen logo
1 von 95
Downloaden Sie, um offline zu lesen
Write Less (Code)
With More (Features)
Oren Nakdimon
www.db-oriented.com
 oren@db-oriented.com
 +972-54-4393763
@DBoriented
©
Oren
Nakdimon
©
Oren
Nakdimon
http://db-oriented.com
Who Am
I?
©
Oren
Nakdimon
©
Oren
Nakdimon
Demo – GTFS
 General Transit Feed Specification
 File Set
 agency.txt
 stops.txt
 routes.txt
 trips.txt
 stop_times.txt
 calendar.txt
 calendar_dates.txt
 ...
 London Underground
 https://data.bus-data.dft.gov.uk/timetable/download/gtfs-file/london/
©
Oren
Nakdimon
©
Oren
Nakdimon
Demo – Data Model
TRIPS
# trip_id
* route_name
o trip_headsign
STOP_TIMES
# stop_sequence
* arrival_time
* departure_time
* pickup_type
* drop_off_type
STOPS
# stop_id
* stop_name
* location
o stop_code
...
CALENDAR
# service_id
* start_date
* end_date
* Monday
* Tuesday
* Wednesday
* Thursday
* Friday
* Saturday
* Sunday
©
Oren
Nakdimon
©
Oren
Nakdimon
©
Oren
Nakdimon
©
Oren
Nakdimon
SQL*Loader Express Mode
 No need to create a control file
 Defaults
 File name: <tableName>.dat, in current directory
 Record delimiter: newline
 Field delimiter: comma
 No enclosures
6
@xt1
12.1
©
Oren
Nakdimon
©
Oren
Nakdimon
Inline External Tables
 Runtime definition
 No persistent objects in the data dictionary
9
@xt2
18c
©
Oren
Nakdimon
©
Oren
Nakdimon
 Persistent external tables
 A procedure for reload
@xt3
©
Oren
Nakdimon
©
Oren
Nakdimon
create or replace package gtfs as
procedure reload;
end gtfs;
©
Oren
Nakdimon
©
Oren
Nakdimon
procedure reload is
begin
delete stop_times;
delete stops;
delete trips;
delete calendar;
load_calendar;
load_trips;
load_stops;
load_stop_times;
commit;
end reload;
©
Oren
Nakdimon
©
Oren
Nakdimon
procedure reload is
begin
delete stop_times;
delete stops;
delete trips;
delete calendar;
load_calendar;
load_trips;
load_stops;
load_stop_times;
commit;
end reload;
procedure load_calendar is
begin
insert into calendar
(service_id,
monday,
tuesday,
wednesday,
thursday,
friday,
saturday,
sunday,
start_date,
end_date)
select service_id,
monday,
tuesday,
wednesday,
thursday,
friday,
saturday,
sunday,
to_date(start_date, 'yyyymmdd'),
to_date(end_date, 'yyyymmdd')
from calendar_x;
end load_calendar;
©
Oren
Nakdimon
©
Oren
Nakdimon
procedure reload is
begin
delete stop_times;
delete stops;
delete trips;
delete calendar;
load_calendar;
load_trips;
load_stops;
load_stop_times;
commit;
end reload;
procedure load_trips is
begin
insert into trips
(trip_x_id,
route_name,
service_id,
trip_headsign)
select t.trip_id,
r.route_short_name,
t.service_id,
t.trip_headsign
from routes_x r,
trips_x t,
calendar c
where t.route_id = r.route_id
and c.service_id = t.service_id;
end load_trips;
©
Oren
Nakdimon
©
Oren
Nakdimon
procedure reload is
begin
delete stop_times;
delete stops;
delete trips;
delete calendar;
load_calendar;
load_trips;
load_stops;
load_stop_times;
commit;
end reload;
procedure load_stops is
begin
insert into stops
(stop_id,
stop_code,
stop_name,
location)
select stop_id,
stop_code,
replace(stop_name, ' Underground Station'),
mdsys.sdo_geometry(2001, -- 2 dimensional point
8307, -- lat/long coord. system
mdsys.sdo_point_type(stop_lon,
stop_lat,
null),
null, -- n/a for point type
null) -- n/a for point type
from stops_x;
end load_stops;
©
Oren
Nakdimon
©
Oren
Nakdimon
procedure reload is
begin
delete stop_times;
delete stops;
delete trips;
delete calendar;
load_calendar;
load_trips;
load_stops;
load_stop_times;
commit;
end reload;
procedure load_stops is
begin
insert into stops
(stop_id,
stop_code,
stop_name,
location)
select stop_id,
stop_code,
replace(stop_name, ' Underground Station'),
mdsys.sdo_geometry(2001, -- 2 dimensional point
8307, -- lat/long coord. system
mdsys.sdo_point_type(stop_lon,
stop_lat,
null),
null, -- n/a for point type
null) -- n/a for point type
from stops_x;
end load_stops;
©
Oren
Nakdimon
©
Oren
Nakdimon
procedure reload is
begin
delete stop_times;
delete stops;
delete trips;
delete calendar;
load_calendar;
load_trips;
load_stops;
load_stop_times;
commit;
end reload;
procedure load_stop_times is
begin
insert into stop_times
(trip_id,
stop_sequence,
arrival_time,
departure_time,
stop_id,
pickup_type,
drop_off_type)
select t.trip_id,
st.stop_sequence,
st.arrival_time,
st.departure_time,
st.stop_id,
st.pickup_type,
st.drop_off_type
from stop_times_x st,
trips t
where st.trip_id = t.trip_x_id;
end load_stop_times;
©
Oren
Nakdimon
©
Oren
Nakdimon
create sequence trips_seq;
create table trips (
trip_id
integer
default trips_seq.nextval
not null
constraint trips_pk primary key,
route_name
varchar2(100)
not null,
service_id
not null
constraint trips_fk_calendar references calendar(service_id),
trip_headsign
varchar2(100),
trip_x_id
varchar2(100)
invisible
not null
constraint trips_uk unique
);
©
Oren
Nakdimon
©
Oren
Nakdimon
create sequence trips_seq;
create table trips (
trip_id
integer
default trips_seq.nextval
not null
constraint trips_pk primary key,
route_name
varchar2(100)
not null,
service_id
not null
constraint trips_fk_calendar references calendar(service_id),
trip_headsign
varchar2(100),
trip_x_id
varchar2(100)
invisible
not null
constraint trips_uk unique
);
12.1
©
Oren
Nakdimon
©
Oren
Nakdimon
create sequence trips_seq session;
create table trips (
trip_id
integer
default trips_seq.nextval
not null
constraint trips_pk primary key,
route_name
varchar2(100)
not null,
service_id
not null
constraint trips_fk_calendar references calendar(service_id),
trip_headsign
varchar2(100),
trip_x_id
varchar2(100)
invisible
not null
constraint trips_uk unique
);
12.1
©
Oren
Nakdimon
©
Oren
Nakdimon
create sequence trips_seq session;
create table trips (
trip_id
integer
default trips_seq.nextval
not null
constraint trips_pk primary key,
route_name
varchar2(100)
not null,
service_id
not null
constraint trips_fk_calendar references calendar(service_id),
trip_headsign
varchar2(100),
trip_x_id
varchar2(100)
invisible
not null
constraint trips_uk unique
);
12.1
©
Oren
Nakdimon
©
Oren
Nakdimon
Overriding Parameters in a Query
 Overridable Clauses
 DEFAULT DIRECTORY
 LOCATION
 ACCESS PARAMETERS
 REJECT LIMIT
@xt4
12.2
©
Oren
Nakdimon
©
Oren
Nakdimon
The CALENDAR Table
©
Oren
Nakdimon
©
Oren
Nakdimon
select c.*
from calendar c
where trunc(sysdate) between c.start_date and c.end_date
and decode(to_char(sysdate, 'fmDay', 'nls_date_language=english'),
'Sunday', c.sunday,
'Monday', c.monday,
'Tuesday', c.tuesday,
'Wednesday',c.wednesday,
'Thursday', c.thursday,
'Friday', c.friday,
'Saturday', c.saturday) = 1;
©
Oren
Nakdimon
©
Oren
Nakdimon
select c.*
from calendar c
where trunc(sysdate) between c.start_date and c.end_date
and decode(to_char(sysdate, 'fmDay', 'nls_date_language=english'),
'Sunday', c.sunday,
'Monday', c.monday,
'Tuesday', c.tuesday,
'Wednesday',c.wednesday,
'Thursday', c.thursday,
'Friday', c.friday,
'Saturday', c.saturday) = 1;
©
Oren
Nakdimon
©
Oren
Nakdimon
select c.*
from calendar c
where trunc(sysdate) between c.start_date and c.end_date
and decode(to_char(sysdate, 'fmDay', 'nls_date_language=english'),
'Sunday', c.sunday,
'Monday', c.monday,
'Tuesday', c.tuesday,
'Wednesday',c.wednesday,
'Thursday', c.thursday,
'Friday', c.friday,
'Saturday', c.saturday) = 1;
©
Oren
Nakdimon
©
Oren
Nakdimon
select c.*
from calendar c
where trunc(sysdate+1) between c.start_date and c.end_date
and decode(to_char(sysdate+1, 'fmDay', 'nls_date_language=english'),
'Sunday', c.sunday,
'Monday', c.monday,
'Tuesday', c.tuesday,
'Wednesday',c.wednesday,
'Thursday', c.thursday,
'Friday', c.friday,
'Saturday', c.saturday) = 1;
©
Oren
Nakdimon
©
Oren
Nakdimon
select c.*
from calendar c
where trunc(date'2021-08-29') between c.start_date and c.end_date
and decode(to_char(date'2021-08-29', 'fmDay', 'nls_date_language=english'),
'Sunday', c.sunday,
'Monday', c.monday,
'Tuesday', c.tuesday,
'Wednesday',c.wednesday,
'Thursday', c.thursday,
'Friday', c.friday,
'Saturday', c.saturday) = 1;
©
Oren
Nakdimon
©
Oren
Nakdimon
Parameterized Views?
©
Oren
Nakdimon
©
Oren
Nakdimon
Table SQL Macro – Parameterized Views
create or replace package body gtfs_sm as
function services(i_date in date default sysdate)
return varchar2 sql_macro(table) is
begin
return q'<
select c.service_id
from calendar c
where trunc(i_date) between c.start_date and c.end_date
and decode(to_char(i_date, 'fmDay', 'nls_date_language=english'),
'Sunday', c.sunday,
'Monday', c.monday,
'Tuesday', c.tuesday,
'Wednesday',c.wednesday,
'Thursday', c.thursday,
'Friday', c.friday,
'Saturday', c.saturday) = 1
>';
end services;
end gtfs_sm;
21c 19.7
©
Oren
Nakdimon
©
Oren
Nakdimon
Table SQL Macro – Parameterized Views
create or replace package body gtfs_sm as
function services(i_date in date default sysdate)
return varchar2 sql_macro(table) is
begin
return q'<
select c.service_id
from calendar c
where trunc(i_date) between c.start_date and c.end_date
and decode(to_char(i_date, 'fmDay', 'nls_date_language=english'),
'Sunday', c.sunday,
'Monday', c.monday,
'Tuesday', c.tuesday,
'Wednesday',c.wednesday,
'Thursday', c.thursday,
'Friday', c.friday,
'Saturday', c.saturday) = 1
>';
end services;
end gtfs_sm;
21c 19.7
©
Oren
Nakdimon
©
Oren
Nakdimon
Table SQL Macro – Parameterized Views
create or replace package body gtfs_sm as
function services(i_date in date default sysdate)
return varchar2 sql_macro(table) is
begin
return q'<
select c.service_id
from calendar c
where trunc(i_date) between c.start_date and c.end_date
and decode(to_char(i_date, 'fmDay', 'nls_date_language=english'),
'Sunday', c.sunday,
'Monday', c.monday,
'Tuesday', c.tuesday,
'Wednesday',c.wednesday,
'Thursday', c.thursday,
'Friday', c.friday,
'Saturday', c.saturday) = 1
>';
end services;
end gtfs_sm;
21c 19.7
@macro1
©
Oren
Nakdimon
©
Oren
Nakdimon
declare
v_in clob := q'<select t.route_name,count(*) number_of_trips
from gtfs_sm.services(sysdate) s, trips t
where t.service_id = s.service_id
group by t.route_name
order by number_of_trips>';
v_out clob;
begin
dbms_utility.expand_sql_text(input_sql_text => v_in,
output_sql_text => v_out);
dbms_output.put_line(v_out);
end;
/
12.1
©
Oren
Nakdimon
©
Oren
Nakdimon
SELECT "A1"."ROUTE_NAME" "ROUTE_NAME",
COUNT(*) "NUMBER_OF_TRIPS"
FROM (SELECT "A3"."SERVICE_ID" "SERVICE_ID"
FROM (SELECT "A4"."SERVICE_ID" "SERVICE_ID"
FROM "DEMO_WLWM"."CALENDAR" "A4"
WHERE TRUNC(SYSDATE) >= "A4"."START_DATE"
AND TRUNC(SYSDATE) <= "A4"."END_DATE"
AND DECODE(TO_CHAR(SYSDATE, 'fmDay', 'nls_date_language=english'),
'Sunday',"A4"."SUNDAY",
'Monday',"A4"."MONDAY",
'Tuesday',"A4"."TUESDAY",
'Wednesday',"A4"."WEDNESDAY",
'Thursday',"A4"."THURSDAY",
'Friday',"A4"."FRIDAY",
'Saturday',"A4"."SATURDAY") = 1) "A3") "A2",
"DEMO_WLWM"."TRIPS" "A1"
WHERE "A1"."SERVICE_ID" = "A2"."SERVICE_ID"
GROUP BY "A1"."ROUTE_NAME"
ORDER BY COUNT(*)
select t.route_name,count(*) number_of_trips
from gtfs_sm.services(sysdate) s, trips t
where t.service_id = s.service_id
group by t.route_name
order by number_of_trips
©
Oren
Nakdimon
©
Oren
Nakdimon
create or replace package gtfs_sm as
function services(i_date in date default sysdate) return varchar2 sql_macro(table);
function services
(
i_from_date in date,
i_days in integer
) return varchar2 sql_macro(table);
end gtfs_sm;
©
Oren
Nakdimon
©
Oren
Nakdimon
create or replace package body gtfs_sm as
function services(i_date in date default sysdate) return varchar2 sql_macro(table) is
...
end services;
function services
(
i_from_date in date,
i_days in integer
) return varchar2 sql_macro(table) is
begin
return '
select day, service_id
from (select trunc(i_from_date)+level-1 day from dual connect by level<=i_days),
gtfs_sm.services(day)';
end services;
end gtfs_sm;
©
Oren
Nakdimon
©
Oren
Nakdimon
create or replace package body gtfs_sm as
function services(i_date in date default sysdate) return varchar2 sql_macro(table) is
...
end services;
function services
(
i_from_date in date,
i_days in integer
) return varchar2 sql_macro(table) is
begin
return '
select day, service_id
from (select trunc(i_from_date)+level-1 day from dual connect by level<=i_days),
gtfs_sm.services(day)';
end services;
end gtfs_sm;
@macro1.5
©
Oren
Nakdimon
©
Oren
Nakdimon
-0.11641, 51.48416
@macro2
©
Oren
Nakdimon
©
Oren
Nakdimon
create or replace function nearby_stops
(
i_longitude in number,
i_latitude in number,
i_radius in number
) return varchar2 sql_macro(table) as
begin
return '
select *
from stops s
where sdo_within_distance(
s.location,
sdo_geometry(2001, 8307,
sdo_point_type(i_longitude, i_latitude, null), null, null),
''distance=' || i_radius || ' unit=meter'') = ''TRUE''';
end nearby_stops;
/
©
Oren
Nakdimon
©
Oren
Nakdimon
create or replace function nearby_stops
(
i_longitude in number,
i_latitude in number,
i_radius in number
) return varchar2 sql_macro(table) as
begin
return '
select *
from stops s
where sdo_within_distance(
s.location,
sdo_geometry(2001, 8307,
sdo_point_type(i_longitude, i_latitude, null), null, null),
''distance=' || i_radius || ' unit=meter'') = ''TRUE''';
end nearby_stops;
/
©
Oren
Nakdimon
©
Oren
Nakdimon
create or replace function nearby_stops
(
i_longitude in number,
i_latitude in number,
i_radius in number
) return varchar2 sql_macro(table) as
begin
return '
select *
from stops s
where sdo_within_distance(
s.location,
sdo_geometry(2001, 8307,
sdo_point_type(i_longitude, i_latitude, null), null, null),
''distance=' || i_radius || ' unit=meter'') = ''TRUE''';
end nearby_stops;
/
@macro2.5
©
Oren
Nakdimon
©
Oren
Nakdimon
Table SQL Macro – Polymorphic Views
create or replace function nearby_points
(
i_longitude in number,
i_latitude in number,
i_radius in number,
i_table in dbms_tf.table_t,
i_column in dbms_tf.columns_t
) return varchar2 sql_macro(table) as
begin
return 'select * from i_table s
where sdo_within_distance(
s.' || i_column(1) || ',
sdo_geometry(2001, 8307,
sdo_point_type(i_longitude, i_latitude, null),
null, null),
''distance=' || i_radius || ' unit=meter'') = ''TRUE''';
end nearby_points;
/
©
Oren
Nakdimon
©
Oren
Nakdimon
Table SQL Macro – Polymorphic Views
create or replace function nearby_points
(
i_longitude in number,
i_latitude in number,
i_radius in number,
i_table in dbms_tf.table_t,
i_column in dbms_tf.columns_t
) return varchar2 sql_macro(table) as
begin
return 'select * from i_table s
where sdo_within_distance(
s.' || i_column(1) || ',
sdo_geometry(2001, 8307,
sdo_point_type(i_longitude, i_latitude, null),
null, null),
''distance=' || i_radius || ' unit=meter'') = ''TRUE''';
end nearby_points;
/
©
Oren
Nakdimon
©
Oren
Nakdimon
Table SQL Macro – Polymorphic Views
create or replace function nearby_points
(
i_longitude in number,
i_latitude in number,
i_radius in number,
i_table in dbms_tf.table_t,
i_column in dbms_tf.columns_t
) return varchar2 sql_macro(table) as
begin
return 'select * from i_table s
where sdo_within_distance(
s.' || i_column(1) || ',
sdo_geometry(2001, 8307,
sdo_point_type(i_longitude, i_latitude, null),
null, null),
''distance=' || i_radius || ' unit=meter'') = ''TRUE''';
end nearby_points;
/
@macro2b
©
Oren
Nakdimon
©
Oren
Nakdimon
@any_value1
©
Oren
Nakdimon
©
Oren
Nakdimon
select s.stop_id,
count(*) number_of_trips,
sum(st.pickup_type) no_pickups,
sum(st.drop_off_type) no_drop_offs
from nearby_stops(-0.11641, 51.48416, 1000) s,
stop_times st
where st.stop_id = s.stop_id
group by s.stop_id
order by number_of_trips;
©
Oren
Nakdimon
©
Oren
Nakdimon
select s.stop_id,
s.stop_name,
count(*) number_of_trips,
sum(st.pickup_type) no_pickups,
sum(st.drop_off_type) no_drop_offs
from nearby_stops(-0.11641, 51.48416, 1000) s,
stop_times st
where st.stop_id = s.stop_id
group by s.stop_id
order by number_of_trips;
©
Oren
Nakdimon
©
Oren
Nakdimon
select s.stop_id,
s.stop_name,
count(*) number_of_trips,
sum(st.pickup_type) no_pickups,
sum(st.drop_off_type) no_drop_offs
from nearby_stops(-0.11641, 51.48416, 1000) s,
stop_times st
where st.stop_id = s.stop_id
group by s.stop_id
order by number_of_trips;
ERROR at line 2:
ORA-00979: not a GROUP BY expression
©
Oren
Nakdimon
©
Oren
Nakdimon
Option 1
select s.stop_id,
s.stop_name,
count(*) number_of_trips,
sum(st.pickup_type) no_pickups,
sum(st.drop_off_type) no_drop_offs
from nearby_stops(-0.11641, 51.48416, 1000) s,
stop_times st
where st.stop_id = s.stop_id
group by s.stop_id,
s.stop_name
order by number_of_trips
©
Oren
Nakdimon
©
Oren
Nakdimon
Option 2
select s.stop_id,
min(s.stop_name) stop_name,
count(*) number_of_trips,
sum(st.pickup_type) no_pickups,
sum(st.drop_off_type) no_drop_offs
from nearby_stops(-0.11641, 51.48416, 1000) s,
stop_times st
where st.stop_id = s.stop_id
group by s.stop_id
order by number_of_trips
©
Oren
Nakdimon
©
Oren
Nakdimon
Option 3 – ANY_VALUE
select s.stop_id,
any_value(s.stop_name) stop_name,
count(*) number_of_trips,
sum(st.pickup_type) no_pickups,
sum(st.drop_off_type) no_drop_offs
from nearby_stops(-0.11641, 51.48416, 1000) s,
stop_times st
where st.stop_id = s.stop_id
group by s.stop_id
order by number_of_trips
19c
©
Oren
Nakdimon
©
Oren
Nakdimon
Option 4
select s.stop_id,
s.stop_name,
st1.number_of_trips,
st1.no_pickups,
st1.no_drop_offs
from nearby_stops(-0.11641, 51.48416, 1000) s,
(select st.stop_id,
count(*) number_of_trips,
sum(st.pickup_type) no_pickups,
sum(st.drop_off_type) no_drop_offs
from stop_times st
group by st.stop_id) st1
where st1.stop_id = s.stop_id
order by st1.number_of_trips;
©
Oren
Nakdimon
©
Oren
Nakdimon
Option 4
select s.stop_id,
s.stop_name,
st1.number_of_trips,
st1.no_pickups,
st1.no_drop_offs
from nearby_stops(-0.11641, 51.48416, 1000) s,
(select st.stop_id,
count(*) number_of_trips,
sum(st.pickup_type) no_pickups,
sum(st.drop_off_type) no_drop_offs
from stop_times st
group by st.stop_id) st1
where st1.stop_id = s.stop_id
order by st1.number_of_trips;
©
Oren
Nakdimon
©
Oren
Nakdimon
Option 5
select s.stop_id,
s.stop_name,
st1.number_of_trips,
st1.no_pickups,
st1.no_drop_offs
from nearby_stops(-0.11641, 51.48416, 1000) s,
(select count(*) number_of_trips,
sum(st.pickup_type) no_pickups,
sum(st.drop_off_type) no_drop_offs
from stop_times st
where st.stop_id = s.stop_id) st1
order by st1.number_of_trips;
©
Oren
Nakdimon
©
Oren
Nakdimon
Option 5
select s.stop_id,
s.stop_name,
st1.number_of_trips,
st1.no_pickups,
st1.no_drop_offs
from nearby_stops(-0.11641, 51.48416, 1000) s,
(select count(*) number_of_trips,
sum(st.pickup_type) no_pickups,
sum(st.drop_off_type) no_drop_offs
from stop_times st
where st.stop_id = s.stop_id) st1
order by st1.number_of_trips;
©
Oren
Nakdimon
©
Oren
Nakdimon
Option 5
select s.stop_id,
s.stop_name,
st1.number_of_trips,
st1.no_pickups,
st1.no_drop_offs
from nearby_stops(-0.11641, 51.48416, 1000) s,
(select count(*) number_of_trips,
sum(st.pickup_type) no_pickups,
sum(st.drop_off_type) no_drop_offs
from stop_times st
where st.stop_id = s.stop_id) st1
order by st1.number_of_trips;
ERROR at line 11:
ORA-00904: "S"."STOP_ID": invalid identifier
©
Oren
Nakdimon
©
Oren
Nakdimon
Option 5 – LATERAL Inline Views
select s.stop_id,
s.stop_name,
st1.number_of_trips,
st1.no_pickups,
st1.no_drop_offs
from nearby_stops(-0.11641, 51.48416, 1000) s,
lateral (select count(*) number_of_trips,
sum(st.pickup_type) no_pickups,
sum(st.drop_off_type) no_drop_offs
from stop_times st
where st.stop_id = s.stop_id) st1
order by st1.number_of_trips;
12.1
@lateral
©
Oren
Nakdimon
©
Oren
Nakdimon
select st.*,
s.stop_name
from stop_times st,
stops s
where st.trip_id = 171
and s.stop_id = st.stop_id
order by st.stop_sequence;
©
Oren
Nakdimon
©
Oren
Nakdimon
create or replace view trip_end_points_v as
select
st.trip_id,
min(st.departure_time) trip_start_time,
max(st.arrival_time) trip_end_time,
? first_stop_name,
? last_stop_name
from stop_times st,
stops s
where s.stop_id = st.stop_id
group by st.trip_id;
©
Oren
Nakdimon
©
Oren
Nakdimon
create or replace view trip_end_points_v as
select
st.trip_id,
min(st.departure_time) trip_start_time,
max(st.arrival_time) trip_end_time,
any_value(s.stop_name) keep(dense_rank first order by st.stop_sequence) first_stop_name,
any_value(s.stop_name) keep(dense_rank last order by st.stop_sequence) last_stop_name
from stop_times st,
stops s
where s.stop_id = st.stop_id
group by st.trip_id;
©
Oren
Nakdimon
©
Oren
Nakdimon
create or replace view trip_end_points_v as
select
st.trip_id,
min(st.departure_time) trip_start_time,
max(st.arrival_time) trip_end_time,
any_value(s.stop_name) keep(dense_rank first order by st.stop_sequence) first_stop_name,
any_value(s.stop_name) keep(dense_rank last order by st.stop_sequence) last_stop_name
from stop_times st,
stops s
where s.stop_id = st.stop_id
group by st.trip_id;
©
Oren
Nakdimon
©
Oren
Nakdimon
create or replace view trip_end_points_v as
select
st.trip_id,
min(st.departure_time) trip_start_time,
max(st.arrival_time) trip_end_time,
any_value(s.stop_name) keep(dense_rank first order by st.stop_sequence) first_stop_name,
any_value(s.stop_name) keep(dense_rank last order by st.stop_sequence) last_stop_name
from stop_times st,
stops s
where s.stop_id = st.stop_id
group by st.trip_id;
©
Oren
Nakdimon
©
Oren
Nakdimon
create or replace view trip_end_points_v as
select
st.trip_id,
min(st.departure_time) trip_start_time,
max(st.arrival_time) trip_end_time,
any_value(s.stop_name) keep(dense_rank first order by st.stop_sequence) first_stop_name,
any_value(s.stop_name) keep(dense_rank last order by st.stop_sequence) last_stop_name
from stop_times st,
stops s
where s.stop_id = st.stop_id
group by st.trip_id;
©
Oren
Nakdimon
©
Oren
Nakdimon
create or replace view trip_end_points_v as
select
st.trip_id,
min(st.departure_time) trip_start_time,
max(st.arrival_time) trip_end_time,
any_value(s.stop_name) keep(dense_rank first order by st.stop_sequence) first_stop_name,
any_value(s.stop_name) keep(dense_rank last order by st.stop_sequence) last_stop_name
from stop_times st,
stops s
where s.stop_id = st.stop_id
group by st.trip_id;
©
Oren
Nakdimon
©
Oren
Nakdimon
create or replace package body gtfs as
...
procedure get_trips
(
i_route_name in trips.route_name%type,
i_date in date,
i_from_time in trip_end_points_v.trip_start_time%type,
i_to_time in trip_end_points_v.trip_start_time%type,
o_rc out sys_refcursor
) is
begin
open o_rc for
select t.trip_headsign,
v.*
from gtfs_sm.services(i_date) s,
trips t,
trip_end_points_v v
where t.service_id = s.service_id
and t.route_name = i_route_name
and v.trip_id = t.trip_id
and v.trip_start_time between i_from_time and i_to_time
order by v.trip_start_time;
end get_trips;
©
Oren
Nakdimon
©
Oren
Nakdimon
create or replace package body gtfs as
...
procedure get_trips
(
i_route_name in trips.route_name%type,
i_date in date,
i_from_time in trip_end_points_v.trip_start_time%type,
i_to_time in trip_end_points_v.trip_start_time%type,
o_rc out sys_refcursor
) is
begin
open o_rc for
select t.trip_headsign,
v.*
from gtfs_sm.services(i_date) s,
trips t,
trip_end_points_v v
where t.service_id = s.service_id
and t.route_name = i_route_name
and v.trip_id = t.trip_id
and v.trip_start_time between i_from_time and i_to_time
order by v.trip_start_time;
end get_trips;
©
Oren
Nakdimon
©
Oren
Nakdimon
create or replace package body gtfs as
...
procedure get_trips
(
i_route_name in trips.route_name%type,
i_date in date,
i_from_time in trip_end_points_v.trip_start_time%type,
i_to_time in trip_end_points_v.trip_start_time%type,
o_rc out sys_refcursor
) is
begin
open o_rc for
select t.trip_headsign,
v.*
from gtfs_sm.services(i_date) s,
trips t,
trip_end_points_v v
where t.service_id = s.service_id
and t.route_name = i_route_name
and v.trip_id = t.trip_id
and v.trip_start_time between i_from_time and i_to_time
order by v.trip_start_time;
end get_trips;
©
Oren
Nakdimon
©
Oren
Nakdimon
create or replace package body gtfs as
...
procedure get_trips
(
i_route_name in trips.route_name%type,
i_date in date,
i_from_time in trip_end_points_v.trip_start_time%type,
i_to_time in trip_end_points_v.trip_start_time%type,
o_rc out sys_refcursor
) is
begin
open o_rc for
select t.trip_headsign,
v.*
from gtfs_sm.services(i_date) s,
trips t,
trip_end_points_v v
where t.service_id = s.service_id
and t.route_name = i_route_name
and v.trip_id = t.trip_id
and v.trip_start_time between i_from_time and i_to_time
order by v.trip_start_time;
end get_trips;
©
Oren
Nakdimon
©
Oren
Nakdimon
create or replace package body gtfs as
...
procedure get_trips
(
i_route_name in trips.route_name%type,
i_date in date,
i_from_time in trip_end_points_v.trip_start_time%type,
i_to_time in trip_end_points_v.trip_start_time%type,
o_rc out sys_refcursor
) is
begin
open o_rc for
select t.trip_headsign,
v.*
from gtfs_sm.services(i_date) s,
trips t,
trip_end_points_v v
where t.service_id = s.service_id
and t.route_name = i_route_name
and v.trip_id = t.trip_id
and v.trip_start_time between i_from_time and i_to_time
order by v.trip_start_time;
end get_trips;
©
Oren
Nakdimon
©
Oren
Nakdimon
create or replace package body gtfs as
...
procedure get_trips
(
i_route_name in trips.route_name%type,
i_date in date,
i_from_time in trip_end_points_v.trip_start_time%type,
i_to_time in trip_end_points_v.trip_start_time%type,
o_rc out sys_refcursor
) is
begin
open o_rc for
select t.trip_headsign,
v.*
from gtfs_sm.services(i_date) s,
trips t,
trip_end_points_v v
where t.service_id = s.service_id
and t.route_name = i_route_name
and v.trip_id = t.trip_id
and v.trip_start_time between i_from_time and i_to_time
order by v.trip_start_time;
end get_trips;
@collation
©
Oren
Nakdimon
©
Oren
Nakdimon
Column-Level Collation
Schema
Table
Column
create user ...
default collation using_nls_comp
create table ... (...)
default collation binary
create table trips (
...
route_name varchar2(100) collate binary_ci not null,
...
);
12.2
* MAX_STRING_SIZE must be set to EXTENDED 12.1
@collation2
©
Oren
Nakdimon
©
Oren
Nakdimon
@macro3
©
Oren
Nakdimon
©
Oren
Nakdimon
Scalar SQL Macro
create function datetime
(
i_date in date,
i_time in varchar2
) return varchar2 sql_macro(scalar) is
begin
return q'<trunc(i_date)
+ numtodsinterval(to_number(substr(i_time, 1, 2)), 'hour’)
+ numtodsinterval(to_number(substr(i_time, 4, 2)), 'minute')
+ numtodsinterval(to_number(substr(i_time, 7, 2)), 'second')>';
end datetime;
/
21c
©
Oren
Nakdimon
©
Oren
Nakdimon
Scalar SQL Macro
create function datetime
(
i_date in date,
i_time in varchar2
) return varchar2 sql_macro(scalar) is
begin
return q'<trunc(i_date)
+ numtodsinterval(to_number(substr(i_time, 1, 2)), 'hour’)
+ numtodsinterval(to_number(substr(i_time, 4, 2)), 'minute')
+ numtodsinterval(to_number(substr(i_time, 7, 2)), 'second')>';
end datetime;
/
21c
@macro4
©
Oren
Nakdimon
©
Oren
Nakdimon
create or replace package body gtfs as
...
procedure get_departures
(
i_stop_id in stops.stop_id%type,
i_from_date in date default sysdate,
i_days in integer default 1,
o_rc out sys_refcursor
) is
begin
open o_rc for
select t.route_name,
datetime(s.day, st.departure_time) departure_time
from stop_times st,
trips t,
gtfs_sm.services(i_from_date, i_days) s
where st.stop_id = i_stop_id
and t.trip_id = st.trip_id
and s.service_id = t.service_id
order by t.route_name,
departure_time;
end get_departures;
©
Oren
Nakdimon
©
Oren
Nakdimon
create or replace package body gtfs as
...
procedure get_departures
(
i_stop_id in stops.stop_id%type,
i_from_date in date default sysdate,
i_days in integer default 1,
o_rc out sys_refcursor
) is
begin
open o_rc for
select t.route_name,
datetime(s.day, st.departure_time) departure_time
from stop_times st,
trips t,
gtfs_sm.services(i_from_date, i_days) s
where st.stop_id = i_stop_id
and t.trip_id = st.trip_id
and s.service_id = t.service_id
order by t.route_name,
departure_time;
end get_departures;
©
Oren
Nakdimon
©
Oren
Nakdimon
create or replace package body gtfs as
...
procedure get_departures
(
i_stop_id in stops.stop_id%type,
i_from_date in date default sysdate,
i_days in integer default 1,
o_rc out sys_refcursor
) is
begin
open o_rc for
select t.route_name,
datetime(s.day, st.departure_time) departure_time
from stop_times st,
trips t,
gtfs_sm.services(i_from_date, i_days) s
where st.stop_id = i_stop_id
and t.trip_id = st.trip_id
and s.service_id = t.service_id
order by t.route_name,
departure_time;
end get_departures;
©
Oren
Nakdimon
©
Oren
Nakdimon
create or replace package body gtfs as
...
procedure get_departures
(
i_stop_id in stops.stop_id%type,
i_from_date in date default sysdate,
i_days in integer default 1,
o_rc out sys_refcursor
) is
begin
open o_rc for
select t.route_name,
datetime(s.day, st.departure_time) departure_time
from stop_times st,
trips t,
gtfs_sm.services(i_from_date, i_days) s
where st.stop_id = i_stop_id
and t.trip_id = st.trip_id
and s.service_id = t.service_id
order by t.route_name,
departure_time;
end get_departures;
©
Oren
Nakdimon
©
Oren
Nakdimon
create or replace package body gtfs as
...
procedure get_departures
(
i_stop_id in stops.stop_id%type,
i_from_date in date default sysdate,
i_days in integer default 1,
o_rc out sys_refcursor
) is
begin
open o_rc for
select t.route_name,
datetime(s.day, st.departure_time) departure_time
from stop_times st,
trips t,
gtfs_sm.services(i_from_date, i_days) s
where st.stop_id = i_stop_id
and t.trip_id = st.trip_id
and s.service_id = t.service_id
order by t.route_name,
departure_time;
end get_departures;
©
Oren
Nakdimon
©
Oren
Nakdimon
create or replace package body gtfs as
...
procedure get_departures
(
i_stop_id in stops.stop_id%type,
i_from_date in date default sysdate,
i_days in integer default 1,
o_rc out sys_refcursor
) is
begin
open o_rc for
select t.route_name,
datetime(s.day, st.departure_time) departure_time
from stop_times st,
trips t,
gtfs_sm.services(i_from_date, i_days) s
where st.stop_id = i_stop_id
and t.trip_id = st.trip_id
and s.service_id = t.service_id
order by t.route_name,
departure_time;
end get_departures;
©
Oren
Nakdimon
©
Oren
Nakdimon
create or replace package body gtfs as
...
procedure get_departures
(
i_stop_id in stops.stop_id%type,
i_from_date in date default sysdate,
i_days in integer default 1,
o_rc out sys_refcursor
) is
begin
open o_rc for
select t.route_name,
datetime(s.day, st.departure_time) departure_time
from stop_times st,
trips t,
gtfs_sm.services(i_from_date, i_days) s
where st.stop_id = i_stop_id
and t.trip_id = st.trip_id
and s.service_id = t.service_id
order by t.route_name,
departure_time;
end get_departures;
@pm1
©
Oren
Nakdimon
©
Oren
Nakdimon
select route_name, number_of_trips,
to_char(from_time,'hh24:mi')
||nvl2(to_time,
' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes',
null) departures
from (
select t.route_name,
datetime(s.day, st.departure_time) departure_time
from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s
where st.stop_id = i_stop_id
and t.trip_id = st.trip_id
and s.service_id = t.service_id
) match_recognize (
partition by route_name
order by departure_time
measures X.departure_time from_time,
last(Y.departure_time) to_time,
(first(Y.departure_time)-X.departure_time)*24*60 minutes,
count(*) number_of_trips
pattern (X Y{2,} | X)
define
Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time
) t
order by route_name, from_time;
©
Oren
Nakdimon
©
Oren
Nakdimon
select route_name, number_of_trips,
to_char(from_time,'hh24:mi')
||nvl2(to_time,
' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes',
null) departures
from (
select t.route_name,
datetime(s.day, st.departure_time) departure_time
from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s
where st.stop_id = i_stop_id
and t.trip_id = st.trip_id
and s.service_id = t.service_id
) match_recognize (
partition by route_name
order by departure_time
measures X.departure_time from_time,
last(Y.departure_time) to_time,
(first(Y.departure_time)-X.departure_time)*24*60 minutes,
count(*) number_of_trips
pattern (X Y{2,} | X)
define
Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time
)
order by route_name, from_time;
12.1
©
Oren
Nakdimon
©
Oren
Nakdimon
select route_name, number_of_trips,
to_char(from_time,'hh24:mi')
||nvl2(to_time,
' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes',
null) departures
from (
select t.route_name,
datetime(s.day, st.departure_time) departure_time
from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s
where st.stop_id = i_stop_id
and t.trip_id = st.trip_id
and s.service_id = t.service_id
) match_recognize (
partition by route_name
order by departure_time
measures X.departure_time from_time,
last(Y.departure_time) to_time,
(first(Y.departure_time)-X.departure_time)*24*60 minutes,
count(*) number_of_trips
pattern (X Y{2,} | X)
define
Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time
)
order by route_name, from_time;
©
Oren
Nakdimon
©
Oren
Nakdimon
select route_name, number_of_trips,
to_char(from_time,'hh24:mi')
||nvl2(to_time,
' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes',
null) departures
from (
select t.route_name,
datetime(s.day, st.departure_time) departure_time
from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s
where st.stop_id = i_stop_id
and t.trip_id = st.trip_id
and s.service_id = t.service_id
) match_recognize (
partition by route_name
order by departure_time
measures X.departure_time from_time,
last(Y.departure_time) to_time,
(first(Y.departure_time)-X.departure_time)*24*60 minutes,
count(*) number_of_trips
pattern (X Y{2,} | X)
define
Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time
)
order by route_name, from_time;
©
Oren
Nakdimon
©
Oren
Nakdimon
select route_name, number_of_trips,
to_char(from_time,'hh24:mi')
||nvl2(to_time,
' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes',
null) departures
from (
select t.route_name,
datetime(s.day, st.departure_time) departure_time
from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s
where st.stop_id = i_stop_id
and t.trip_id = st.trip_id
and s.service_id = t.service_id
) match_recognize (
partition by route_name
order by departure_time
measures X.departure_time from_time,
last(Y.departure_time) to_time,
(first(Y.departure_time)-X.departure_time)*24*60 minutes,
count(*) number_of_trips
pattern (X Y{2,} | X)
define
Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time
)
order by route_name, from_time;
©
Oren
Nakdimon
©
Oren
Nakdimon
select route_name, number_of_trips,
to_char(from_time,'hh24:mi')
||nvl2(to_time,
' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes',
null) departures
from (
select t.route_name,
datetime(s.day, st.departure_time) departure_time
from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s
where st.stop_id = i_stop_id
and t.trip_id = st.trip_id
and s.service_id = t.service_id
) match_recognize (
partition by route_name
order by departure_time
measures X.departure_time from_time,
last(Y.departure_time) to_time,
(first(Y.departure_time)-X.departure_time)*24*60 minutes,
count(*) number_of_trips
pattern (X Y{2,} | X)
define
Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time
)
order by route_name, from_time;
©
Oren
Nakdimon
©
Oren
Nakdimon
select route_name, number_of_trips,
to_char(from_time,'hh24:mi')
||nvl2(to_time,
' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes',
null) departures
from (
select t.route_name,
datetime(s.day, st.departure_time) departure_time
from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s
where st.stop_id = i_stop_id
and t.trip_id = st.trip_id
and s.service_id = t.service_id
) match_recognize (
partition by route_name
order by departure_time
measures X.departure_time from_time,
last(Y.departure_time) to_time,
(first(Y.departure_time)-X.departure_time)*24*60 minutes,
count(*) number_of_trips
pattern (X Y{2,} | X)
define
Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time
)
order by route_name, from_time;
©
Oren
Nakdimon
©
Oren
Nakdimon
select route_name, number_of_trips,
to_char(from_time,'hh24:mi')
||nvl2(to_time,
' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes',
null) departures
from (
select t.route_name,
datetime(s.day, st.departure_time) departure_time
from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s
where st.stop_id = i_stop_id
and t.trip_id = st.trip_id
and s.service_id = t.service_id
) match_recognize (
partition by route_name
order by departure_time
measures X.departure_time from_time,
last(Y.departure_time) to_time,
(first(Y.departure_time)-X.departure_time)*24*60 minutes,
count(*) number_of_trips
pattern (X Y{2,} | X)
define
Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time
)
order by route_name, from_time;
©
Oren
Nakdimon
©
Oren
Nakdimon
select route_name, number_of_trips,
to_char(from_time,'hh24:mi')
||nvl2(to_time,
' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes',
null) departures
from (
select t.route_name,
datetime(s.day, st.departure_time) departure_time
from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s
where st.stop_id = i_stop_id
and t.trip_id = st.trip_id
and s.service_id = t.service_id
) match_recognize (
partition by route_name
order by departure_time
measures X.departure_time from_time,
last(Y.departure_time) to_time,
(first(Y.departure_time)-X.departure_time)*24*60 minutes,
count(*) number_of_trips
pattern (X Y{2,} | X)
define
Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time
)
order by route_name, from_time;
©
Oren
Nakdimon
©
Oren
Nakdimon
select route_name, number_of_trips,
to_char(from_time,'hh24:mi')
||nvl2(to_time,
' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes',
null) departures
from (
select t.route_name,
datetime(s.day, st.departure_time) departure_time
from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s
where st.stop_id = i_stop_id
and t.trip_id = st.trip_id
and s.service_id = t.service_id
) match_recognize (
partition by route_name
order by departure_time
measures X.departure_time from_time,
last(Y.departure_time) to_time,
(first(Y.departure_time)-X.departure_time)*24*60 minutes,
count(*) number_of_trips
pattern (X Y{2,} | X)
define
Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time
)
order by route_name, from_time;
©
Oren
Nakdimon
©
Oren
Nakdimon
select route_name, number_of_trips,
to_char(from_time,'hh24:mi')
||nvl2(to_time,
' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes',
null) departures
from (
select t.route_name,
datetime(s.day, st.departure_time) departure_time
from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s
where st.stop_id = i_stop_id
and t.trip_id = st.trip_id
and s.service_id = t.service_id
) match_recognize (
partition by route_name
order by departure_time
measures X.departure_time from_time,
last(Y.departure_time) to_time,
(first(Y.departure_time)-X.departure_time)*24*60 minutes,
count(*) number_of_trips
pattern (X Y{2,} | X)
define
Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time
)
order by route_name, from_time;
©
Oren
Nakdimon
©
Oren
Nakdimon
select route_name, number_of_trips,
to_char(from_time,'hh24:mi')
||nvl2(to_time,
' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes',
null) departures
from (
select t.route_name,
datetime(s.day, st.departure_time) departure_time
from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s
where st.stop_id = i_stop_id
and t.trip_id = st.trip_id
and s.service_id = t.service_id
) match_recognize (
partition by route_name
order by departure_time
measures X.departure_time from_time,
last(Y.departure_time) to_time,
(first(Y.departure_time)-X.departure_time)*24*60 minutes,
count(*) number_of_trips
pattern (X Y{2,} | X)
define
Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time
)
order by route_name, from_time;
©
Oren
Nakdimon
©
Oren
Nakdimon
select route_name, number_of_trips,
to_char(from_time,'hh24:mi')
||nvl2(to_time,
' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes',
null) departures
from (
select t.route_name,
datetime(s.day, st.departure_time) departure_time
from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s
where st.stop_id = i_stop_id
and t.trip_id = st.trip_id
and s.service_id = t.service_id
) match_recognize (
partition by route_name
order by departure_time
measures X.departure_time from_time,
last(Y.departure_time) to_time,
(first(Y.departure_time)-X.departure_time)*24*60 minutes,
count(*) number_of_trips
pattern (X Y{2,} | X)
define
Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time
)
order by route_name, from_time;
©
Oren
Nakdimon
©
Oren
Nakdimon
select route_name, number_of_trips,
to_char(from_time,'hh24:mi')
||nvl2(to_time,
' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes',
null) departures
from (
select t.route_name,
datetime(s.day, st.departure_time) departure_time
from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s
where st.stop_id = i_stop_id
and t.trip_id = st.trip_id
and s.service_id = t.service_id
) match_recognize (
partition by route_name
order by departure_time
measures X.departure_time from_time,
last(Y.departure_time) to_time,
(first(Y.departure_time)-X.departure_time)*24*60 minutes,
count(*) number_of_trips
pattern (X Y{2,} | X)
define
Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time
)
order by route_name, from_time;
©
Oren
Nakdimon
©
Oren
Nakdimon
select route_name, number_of_trips,
to_char(from_time,'hh24:mi')
||nvl2(to_time,
' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes',
null) departures
from (
select t.route_name,
datetime(s.day, st.departure_time) departure_time
from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s
where st.stop_id = i_stop_id
and t.trip_id = st.trip_id
and s.service_id = t.service_id
) match_recognize (
partition by route_name
order by departure_time
measures X.departure_time from_time,
last(Y.departure_time) to_time,
(first(Y.departure_time)-X.departure_time)*24*60 minutes,
count(*) number_of_trips
pattern (X Y{2,} | X)
define
Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time
)
order by route_name, from_time;
©
Oren
Nakdimon
©
Oren
Nakdimon
select route_name, number_of_trips,
to_char(from_time,'hh24:mi')
||nvl2(to_time,
' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes',
null) departures
from (
select t.route_name,
datetime(s.day, st.departure_time) departure_time
from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s
where st.stop_id = i_stop_id
and t.trip_id = st.trip_id
and s.service_id = t.service_id
) match_recognize (
partition by route_name
order by departure_time
measures X.departure_time from_time,
last(Y.departure_time) to_time,
(first(Y.departure_time)-X.departure_time)*24*60 minutes,
count(*) number_of_trips
pattern (X Y{2,} | X)
define
Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time
)
order by route_name, from_time;
@pm2

Weitere ähnliche Inhalte

Ähnlich wie Oren nakdimon - Write Less With More - UKOUGtogether21

Can you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdfCan you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdf
aksachdevahosymills
 
Geo distance search with my sql presentation
Geo distance search with my sql presentationGeo distance search with my sql presentation
Geo distance search with my sql presentation
GSMboy
 
Trees And More With Postgre S Q L
Trees And  More With  Postgre S Q LTrees And  More With  Postgre S Q L
Trees And More With Postgre S Q L
PerconaPerformance
 
最近作ったN個のCPANモジュール Yokohama.pm #10
最近作ったN個のCPANモジュール Yokohama.pm #10最近作ったN個のCPANモジュール Yokohama.pm #10
最近作ったN個のCPANモジュール Yokohama.pm #10
Masahiro Nagano
 
e computer notes - Date time functions
e computer notes - Date time functionse computer notes - Date time functions
e computer notes - Date time functions
ecomputernotes
 

Ähnlich wie Oren nakdimon - Write Less With More - UKOUGtogether21 (20)

Write Less (Code) With More (Features) [UKOUG 22]
Write Less (Code) With More (Features) [UKOUG 22]Write Less (Code) With More (Features) [UKOUG 22]
Write Less (Code) With More (Features) [UKOUG 22]
 
Can you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdfCan you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdf
 
Jsr310 - Java 8 Date and Time API
Jsr310 - Java 8 Date and Time APIJsr310 - Java 8 Date and Time API
Jsr310 - Java 8 Date and Time API
 
PyParis - weather and climate data
PyParis - weather and climate dataPyParis - weather and climate data
PyParis - weather and climate data
 
Sample document
Sample documentSample document
Sample document
 
Geo distance search with my sql presentation
Geo distance search with my sql presentationGeo distance search with my sql presentation
Geo distance search with my sql presentation
 
Aggarwal Draft
Aggarwal DraftAggarwal Draft
Aggarwal Draft
 
Oracle 12c SQL: Date Ranges
Oracle 12c SQL: Date RangesOracle 12c SQL: Date Ranges
Oracle 12c SQL: Date Ranges
 
Libor Market Model C++ code
Libor Market Model C++ codeLibor Market Model C++ code
Libor Market Model C++ code
 
Libor Market Model
Libor Market ModelLibor Market Model
Libor Market Model
 
C# Assignmet Help
C# Assignmet HelpC# Assignmet Help
C# Assignmet Help
 
Gps c
Gps cGps c
Gps c
 
4Developers 2018: Beyond c++17 (Mateusz Pusz)
4Developers 2018: Beyond c++17 (Mateusz Pusz)4Developers 2018: Beyond c++17 (Mateusz Pusz)
4Developers 2018: Beyond c++17 (Mateusz Pusz)
 
Trees And More With Postgre S Q L
Trees And  More With  Postgre S Q LTrees And  More With  Postgre S Q L
Trees And More With Postgre S Q L
 
C vs Java: Finding Prime Numbers
C vs Java: Finding Prime NumbersC vs Java: Finding Prime Numbers
C vs Java: Finding Prime Numbers
 
Management Science : Project SchedulingPert_cpm.ppt
Management Science : Project SchedulingPert_cpm.pptManagement Science : Project SchedulingPert_cpm.ppt
Management Science : Project SchedulingPert_cpm.ppt
 
Code
CodeCode
Code
 
最近作ったN個のCPANモジュール Yokohama.pm #10
最近作ったN個のCPANモジュール Yokohama.pm #10最近作ったN個のCPANモジュール Yokohama.pm #10
最近作ったN個のCPANモジュール Yokohama.pm #10
 
e computer notes - Date time functions
e computer notes - Date time functionse computer notes - Date time functions
e computer notes - Date time functions
 
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
 

Mehr von Oren Nakdimon

Mehr von Oren Nakdimon (11)

Design Patterns in PLSQL and SQL [UKOUG 22]
Design Patterns in PLSQL and SQL [UKOUG 22]Design Patterns in PLSQL and SQL [UKOUG 22]
Design Patterns in PLSQL and SQL [UKOUG 22]
 
Oren Nakdimon - Oracle SQL Pattern Matching Made Easy
Oren Nakdimon - Oracle SQL Pattern Matching Made EasyOren Nakdimon - Oracle SQL Pattern Matching Made Easy
Oren Nakdimon - Oracle SQL Pattern Matching Made Easy
 
Oracle Inter-Session Communication
Oracle Inter-Session CommunicationOracle Inter-Session Communication
Oracle Inter-Session Communication
 
Constraint Optimization
Constraint OptimizationConstraint Optimization
Constraint Optimization
 
Edition Based Redefinition Made Easy - Oren Nakdimon
Edition Based Redefinition Made Easy - Oren NakdimonEdition Based Redefinition Made Easy - Oren Nakdimon
Edition Based Redefinition Made Easy - Oren Nakdimon
 
Oren nakdimon - Oracle 12c SQL Pattern Matching Made Easy
Oren nakdimon - Oracle 12c SQL Pattern Matching Made EasyOren nakdimon - Oracle 12c SQL Pattern Matching Made Easy
Oren nakdimon - Oracle 12c SQL Pattern Matching Made Easy
 
Oren nakdimon oh really... i didn't know it is supported in standard edition
Oren nakdimon   oh really... i didn't know it is supported in standard editionOren nakdimon   oh really... i didn't know it is supported in standard edition
Oren nakdimon oh really... i didn't know it is supported in standard edition
 
Write Less (code) With More (Oracle Database 12c New Features)
Write Less (code) With More (Oracle Database 12c New Features)Write Less (code) With More (Oracle Database 12c New Features)
Write Less (code) With More (Oracle Database 12c New Features)
 
Indexes and Indexing in Oracle 12c
Indexes and Indexing in Oracle 12cIndexes and Indexing in Oracle 12c
Indexes and Indexing in Oracle 12c
 
How to upgrade your application with no downtime (using edition-based redefin...
How to upgrade your application with no downtime (using edition-based redefin...How to upgrade your application with no downtime (using edition-based redefin...
How to upgrade your application with no downtime (using edition-based redefin...
 
The Features That (maybe) You Didn't Know About
The Features That (maybe) You Didn't Know AboutThe Features That (maybe) You Didn't Know About
The Features That (maybe) You Didn't Know About
 

Kürzlich hochgeladen

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 

Kürzlich hochgeladen (20)

WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 

Oren nakdimon - Write Less With More - UKOUGtogether21

  • 1. Write Less (Code) With More (Features) Oren Nakdimon www.db-oriented.com  oren@db-oriented.com  +972-54-4393763 @DBoriented
  • 3. © Oren Nakdimon © Oren Nakdimon Demo – GTFS  General Transit Feed Specification  File Set  agency.txt  stops.txt  routes.txt  trips.txt  stop_times.txt  calendar.txt  calendar_dates.txt  ...  London Underground  https://data.bus-data.dft.gov.uk/timetable/download/gtfs-file/london/
  • 4. © Oren Nakdimon © Oren Nakdimon Demo – Data Model TRIPS # trip_id * route_name o trip_headsign STOP_TIMES # stop_sequence * arrival_time * departure_time * pickup_type * drop_off_type STOPS # stop_id * stop_name * location o stop_code ... CALENDAR # service_id * start_date * end_date * Monday * Tuesday * Wednesday * Thursday * Friday * Saturday * Sunday
  • 6. © Oren Nakdimon © Oren Nakdimon SQL*Loader Express Mode  No need to create a control file  Defaults  File name: <tableName>.dat, in current directory  Record delimiter: newline  Field delimiter: comma  No enclosures 6 @xt1 12.1
  • 7. © Oren Nakdimon © Oren Nakdimon Inline External Tables  Runtime definition  No persistent objects in the data dictionary 9 @xt2 18c
  • 8. © Oren Nakdimon © Oren Nakdimon  Persistent external tables  A procedure for reload @xt3
  • 9. © Oren Nakdimon © Oren Nakdimon create or replace package gtfs as procedure reload; end gtfs;
  • 10. © Oren Nakdimon © Oren Nakdimon procedure reload is begin delete stop_times; delete stops; delete trips; delete calendar; load_calendar; load_trips; load_stops; load_stop_times; commit; end reload;
  • 11. © Oren Nakdimon © Oren Nakdimon procedure reload is begin delete stop_times; delete stops; delete trips; delete calendar; load_calendar; load_trips; load_stops; load_stop_times; commit; end reload; procedure load_calendar is begin insert into calendar (service_id, monday, tuesday, wednesday, thursday, friday, saturday, sunday, start_date, end_date) select service_id, monday, tuesday, wednesday, thursday, friday, saturday, sunday, to_date(start_date, 'yyyymmdd'), to_date(end_date, 'yyyymmdd') from calendar_x; end load_calendar;
  • 12. © Oren Nakdimon © Oren Nakdimon procedure reload is begin delete stop_times; delete stops; delete trips; delete calendar; load_calendar; load_trips; load_stops; load_stop_times; commit; end reload; procedure load_trips is begin insert into trips (trip_x_id, route_name, service_id, trip_headsign) select t.trip_id, r.route_short_name, t.service_id, t.trip_headsign from routes_x r, trips_x t, calendar c where t.route_id = r.route_id and c.service_id = t.service_id; end load_trips;
  • 13. © Oren Nakdimon © Oren Nakdimon procedure reload is begin delete stop_times; delete stops; delete trips; delete calendar; load_calendar; load_trips; load_stops; load_stop_times; commit; end reload; procedure load_stops is begin insert into stops (stop_id, stop_code, stop_name, location) select stop_id, stop_code, replace(stop_name, ' Underground Station'), mdsys.sdo_geometry(2001, -- 2 dimensional point 8307, -- lat/long coord. system mdsys.sdo_point_type(stop_lon, stop_lat, null), null, -- n/a for point type null) -- n/a for point type from stops_x; end load_stops;
  • 14. © Oren Nakdimon © Oren Nakdimon procedure reload is begin delete stop_times; delete stops; delete trips; delete calendar; load_calendar; load_trips; load_stops; load_stop_times; commit; end reload; procedure load_stops is begin insert into stops (stop_id, stop_code, stop_name, location) select stop_id, stop_code, replace(stop_name, ' Underground Station'), mdsys.sdo_geometry(2001, -- 2 dimensional point 8307, -- lat/long coord. system mdsys.sdo_point_type(stop_lon, stop_lat, null), null, -- n/a for point type null) -- n/a for point type from stops_x; end load_stops;
  • 15. © Oren Nakdimon © Oren Nakdimon procedure reload is begin delete stop_times; delete stops; delete trips; delete calendar; load_calendar; load_trips; load_stops; load_stop_times; commit; end reload; procedure load_stop_times is begin insert into stop_times (trip_id, stop_sequence, arrival_time, departure_time, stop_id, pickup_type, drop_off_type) select t.trip_id, st.stop_sequence, st.arrival_time, st.departure_time, st.stop_id, st.pickup_type, st.drop_off_type from stop_times_x st, trips t where st.trip_id = t.trip_x_id; end load_stop_times;
  • 16. © Oren Nakdimon © Oren Nakdimon create sequence trips_seq; create table trips ( trip_id integer default trips_seq.nextval not null constraint trips_pk primary key, route_name varchar2(100) not null, service_id not null constraint trips_fk_calendar references calendar(service_id), trip_headsign varchar2(100), trip_x_id varchar2(100) invisible not null constraint trips_uk unique );
  • 17. © Oren Nakdimon © Oren Nakdimon create sequence trips_seq; create table trips ( trip_id integer default trips_seq.nextval not null constraint trips_pk primary key, route_name varchar2(100) not null, service_id not null constraint trips_fk_calendar references calendar(service_id), trip_headsign varchar2(100), trip_x_id varchar2(100) invisible not null constraint trips_uk unique ); 12.1
  • 18. © Oren Nakdimon © Oren Nakdimon create sequence trips_seq session; create table trips ( trip_id integer default trips_seq.nextval not null constraint trips_pk primary key, route_name varchar2(100) not null, service_id not null constraint trips_fk_calendar references calendar(service_id), trip_headsign varchar2(100), trip_x_id varchar2(100) invisible not null constraint trips_uk unique ); 12.1
  • 19. © Oren Nakdimon © Oren Nakdimon create sequence trips_seq session; create table trips ( trip_id integer default trips_seq.nextval not null constraint trips_pk primary key, route_name varchar2(100) not null, service_id not null constraint trips_fk_calendar references calendar(service_id), trip_headsign varchar2(100), trip_x_id varchar2(100) invisible not null constraint trips_uk unique ); 12.1
  • 20. © Oren Nakdimon © Oren Nakdimon Overriding Parameters in a Query  Overridable Clauses  DEFAULT DIRECTORY  LOCATION  ACCESS PARAMETERS  REJECT LIMIT @xt4 12.2
  • 22. © Oren Nakdimon © Oren Nakdimon select c.* from calendar c where trunc(sysdate) between c.start_date and c.end_date and decode(to_char(sysdate, 'fmDay', 'nls_date_language=english'), 'Sunday', c.sunday, 'Monday', c.monday, 'Tuesday', c.tuesday, 'Wednesday',c.wednesday, 'Thursday', c.thursday, 'Friday', c.friday, 'Saturday', c.saturday) = 1;
  • 23. © Oren Nakdimon © Oren Nakdimon select c.* from calendar c where trunc(sysdate) between c.start_date and c.end_date and decode(to_char(sysdate, 'fmDay', 'nls_date_language=english'), 'Sunday', c.sunday, 'Monday', c.monday, 'Tuesday', c.tuesday, 'Wednesday',c.wednesday, 'Thursday', c.thursday, 'Friday', c.friday, 'Saturday', c.saturday) = 1;
  • 24. © Oren Nakdimon © Oren Nakdimon select c.* from calendar c where trunc(sysdate) between c.start_date and c.end_date and decode(to_char(sysdate, 'fmDay', 'nls_date_language=english'), 'Sunday', c.sunday, 'Monday', c.monday, 'Tuesday', c.tuesday, 'Wednesday',c.wednesday, 'Thursday', c.thursday, 'Friday', c.friday, 'Saturday', c.saturday) = 1;
  • 25. © Oren Nakdimon © Oren Nakdimon select c.* from calendar c where trunc(sysdate+1) between c.start_date and c.end_date and decode(to_char(sysdate+1, 'fmDay', 'nls_date_language=english'), 'Sunday', c.sunday, 'Monday', c.monday, 'Tuesday', c.tuesday, 'Wednesday',c.wednesday, 'Thursday', c.thursday, 'Friday', c.friday, 'Saturday', c.saturday) = 1;
  • 26. © Oren Nakdimon © Oren Nakdimon select c.* from calendar c where trunc(date'2021-08-29') between c.start_date and c.end_date and decode(to_char(date'2021-08-29', 'fmDay', 'nls_date_language=english'), 'Sunday', c.sunday, 'Monday', c.monday, 'Tuesday', c.tuesday, 'Wednesday',c.wednesday, 'Thursday', c.thursday, 'Friday', c.friday, 'Saturday', c.saturday) = 1;
  • 28. © Oren Nakdimon © Oren Nakdimon Table SQL Macro – Parameterized Views create or replace package body gtfs_sm as function services(i_date in date default sysdate) return varchar2 sql_macro(table) is begin return q'< select c.service_id from calendar c where trunc(i_date) between c.start_date and c.end_date and decode(to_char(i_date, 'fmDay', 'nls_date_language=english'), 'Sunday', c.sunday, 'Monday', c.monday, 'Tuesday', c.tuesday, 'Wednesday',c.wednesday, 'Thursday', c.thursday, 'Friday', c.friday, 'Saturday', c.saturday) = 1 >'; end services; end gtfs_sm; 21c 19.7
  • 29. © Oren Nakdimon © Oren Nakdimon Table SQL Macro – Parameterized Views create or replace package body gtfs_sm as function services(i_date in date default sysdate) return varchar2 sql_macro(table) is begin return q'< select c.service_id from calendar c where trunc(i_date) between c.start_date and c.end_date and decode(to_char(i_date, 'fmDay', 'nls_date_language=english'), 'Sunday', c.sunday, 'Monday', c.monday, 'Tuesday', c.tuesday, 'Wednesday',c.wednesday, 'Thursday', c.thursday, 'Friday', c.friday, 'Saturday', c.saturday) = 1 >'; end services; end gtfs_sm; 21c 19.7
  • 30. © Oren Nakdimon © Oren Nakdimon Table SQL Macro – Parameterized Views create or replace package body gtfs_sm as function services(i_date in date default sysdate) return varchar2 sql_macro(table) is begin return q'< select c.service_id from calendar c where trunc(i_date) between c.start_date and c.end_date and decode(to_char(i_date, 'fmDay', 'nls_date_language=english'), 'Sunday', c.sunday, 'Monday', c.monday, 'Tuesday', c.tuesday, 'Wednesday',c.wednesday, 'Thursday', c.thursday, 'Friday', c.friday, 'Saturday', c.saturday) = 1 >'; end services; end gtfs_sm; 21c 19.7 @macro1
  • 31. © Oren Nakdimon © Oren Nakdimon declare v_in clob := q'<select t.route_name,count(*) number_of_trips from gtfs_sm.services(sysdate) s, trips t where t.service_id = s.service_id group by t.route_name order by number_of_trips>'; v_out clob; begin dbms_utility.expand_sql_text(input_sql_text => v_in, output_sql_text => v_out); dbms_output.put_line(v_out); end; / 12.1
  • 32. © Oren Nakdimon © Oren Nakdimon SELECT "A1"."ROUTE_NAME" "ROUTE_NAME", COUNT(*) "NUMBER_OF_TRIPS" FROM (SELECT "A3"."SERVICE_ID" "SERVICE_ID" FROM (SELECT "A4"."SERVICE_ID" "SERVICE_ID" FROM "DEMO_WLWM"."CALENDAR" "A4" WHERE TRUNC(SYSDATE) >= "A4"."START_DATE" AND TRUNC(SYSDATE) <= "A4"."END_DATE" AND DECODE(TO_CHAR(SYSDATE, 'fmDay', 'nls_date_language=english'), 'Sunday',"A4"."SUNDAY", 'Monday',"A4"."MONDAY", 'Tuesday',"A4"."TUESDAY", 'Wednesday',"A4"."WEDNESDAY", 'Thursday',"A4"."THURSDAY", 'Friday',"A4"."FRIDAY", 'Saturday',"A4"."SATURDAY") = 1) "A3") "A2", "DEMO_WLWM"."TRIPS" "A1" WHERE "A1"."SERVICE_ID" = "A2"."SERVICE_ID" GROUP BY "A1"."ROUTE_NAME" ORDER BY COUNT(*) select t.route_name,count(*) number_of_trips from gtfs_sm.services(sysdate) s, trips t where t.service_id = s.service_id group by t.route_name order by number_of_trips
  • 33. © Oren Nakdimon © Oren Nakdimon create or replace package gtfs_sm as function services(i_date in date default sysdate) return varchar2 sql_macro(table); function services ( i_from_date in date, i_days in integer ) return varchar2 sql_macro(table); end gtfs_sm;
  • 34. © Oren Nakdimon © Oren Nakdimon create or replace package body gtfs_sm as function services(i_date in date default sysdate) return varchar2 sql_macro(table) is ... end services; function services ( i_from_date in date, i_days in integer ) return varchar2 sql_macro(table) is begin return ' select day, service_id from (select trunc(i_from_date)+level-1 day from dual connect by level<=i_days), gtfs_sm.services(day)'; end services; end gtfs_sm;
  • 35. © Oren Nakdimon © Oren Nakdimon create or replace package body gtfs_sm as function services(i_date in date default sysdate) return varchar2 sql_macro(table) is ... end services; function services ( i_from_date in date, i_days in integer ) return varchar2 sql_macro(table) is begin return ' select day, service_id from (select trunc(i_from_date)+level-1 day from dual connect by level<=i_days), gtfs_sm.services(day)'; end services; end gtfs_sm; @macro1.5
  • 37. © Oren Nakdimon © Oren Nakdimon create or replace function nearby_stops ( i_longitude in number, i_latitude in number, i_radius in number ) return varchar2 sql_macro(table) as begin return ' select * from stops s where sdo_within_distance( s.location, sdo_geometry(2001, 8307, sdo_point_type(i_longitude, i_latitude, null), null, null), ''distance=' || i_radius || ' unit=meter'') = ''TRUE'''; end nearby_stops; /
  • 38. © Oren Nakdimon © Oren Nakdimon create or replace function nearby_stops ( i_longitude in number, i_latitude in number, i_radius in number ) return varchar2 sql_macro(table) as begin return ' select * from stops s where sdo_within_distance( s.location, sdo_geometry(2001, 8307, sdo_point_type(i_longitude, i_latitude, null), null, null), ''distance=' || i_radius || ' unit=meter'') = ''TRUE'''; end nearby_stops; /
  • 39. © Oren Nakdimon © Oren Nakdimon create or replace function nearby_stops ( i_longitude in number, i_latitude in number, i_radius in number ) return varchar2 sql_macro(table) as begin return ' select * from stops s where sdo_within_distance( s.location, sdo_geometry(2001, 8307, sdo_point_type(i_longitude, i_latitude, null), null, null), ''distance=' || i_radius || ' unit=meter'') = ''TRUE'''; end nearby_stops; / @macro2.5
  • 40. © Oren Nakdimon © Oren Nakdimon Table SQL Macro – Polymorphic Views create or replace function nearby_points ( i_longitude in number, i_latitude in number, i_radius in number, i_table in dbms_tf.table_t, i_column in dbms_tf.columns_t ) return varchar2 sql_macro(table) as begin return 'select * from i_table s where sdo_within_distance( s.' || i_column(1) || ', sdo_geometry(2001, 8307, sdo_point_type(i_longitude, i_latitude, null), null, null), ''distance=' || i_radius || ' unit=meter'') = ''TRUE'''; end nearby_points; /
  • 41. © Oren Nakdimon © Oren Nakdimon Table SQL Macro – Polymorphic Views create or replace function nearby_points ( i_longitude in number, i_latitude in number, i_radius in number, i_table in dbms_tf.table_t, i_column in dbms_tf.columns_t ) return varchar2 sql_macro(table) as begin return 'select * from i_table s where sdo_within_distance( s.' || i_column(1) || ', sdo_geometry(2001, 8307, sdo_point_type(i_longitude, i_latitude, null), null, null), ''distance=' || i_radius || ' unit=meter'') = ''TRUE'''; end nearby_points; /
  • 42. © Oren Nakdimon © Oren Nakdimon Table SQL Macro – Polymorphic Views create or replace function nearby_points ( i_longitude in number, i_latitude in number, i_radius in number, i_table in dbms_tf.table_t, i_column in dbms_tf.columns_t ) return varchar2 sql_macro(table) as begin return 'select * from i_table s where sdo_within_distance( s.' || i_column(1) || ', sdo_geometry(2001, 8307, sdo_point_type(i_longitude, i_latitude, null), null, null), ''distance=' || i_radius || ' unit=meter'') = ''TRUE'''; end nearby_points; / @macro2b
  • 44. © Oren Nakdimon © Oren Nakdimon select s.stop_id, count(*) number_of_trips, sum(st.pickup_type) no_pickups, sum(st.drop_off_type) no_drop_offs from nearby_stops(-0.11641, 51.48416, 1000) s, stop_times st where st.stop_id = s.stop_id group by s.stop_id order by number_of_trips;
  • 45. © Oren Nakdimon © Oren Nakdimon select s.stop_id, s.stop_name, count(*) number_of_trips, sum(st.pickup_type) no_pickups, sum(st.drop_off_type) no_drop_offs from nearby_stops(-0.11641, 51.48416, 1000) s, stop_times st where st.stop_id = s.stop_id group by s.stop_id order by number_of_trips;
  • 46. © Oren Nakdimon © Oren Nakdimon select s.stop_id, s.stop_name, count(*) number_of_trips, sum(st.pickup_type) no_pickups, sum(st.drop_off_type) no_drop_offs from nearby_stops(-0.11641, 51.48416, 1000) s, stop_times st where st.stop_id = s.stop_id group by s.stop_id order by number_of_trips; ERROR at line 2: ORA-00979: not a GROUP BY expression
  • 47. © Oren Nakdimon © Oren Nakdimon Option 1 select s.stop_id, s.stop_name, count(*) number_of_trips, sum(st.pickup_type) no_pickups, sum(st.drop_off_type) no_drop_offs from nearby_stops(-0.11641, 51.48416, 1000) s, stop_times st where st.stop_id = s.stop_id group by s.stop_id, s.stop_name order by number_of_trips
  • 48. © Oren Nakdimon © Oren Nakdimon Option 2 select s.stop_id, min(s.stop_name) stop_name, count(*) number_of_trips, sum(st.pickup_type) no_pickups, sum(st.drop_off_type) no_drop_offs from nearby_stops(-0.11641, 51.48416, 1000) s, stop_times st where st.stop_id = s.stop_id group by s.stop_id order by number_of_trips
  • 49. © Oren Nakdimon © Oren Nakdimon Option 3 – ANY_VALUE select s.stop_id, any_value(s.stop_name) stop_name, count(*) number_of_trips, sum(st.pickup_type) no_pickups, sum(st.drop_off_type) no_drop_offs from nearby_stops(-0.11641, 51.48416, 1000) s, stop_times st where st.stop_id = s.stop_id group by s.stop_id order by number_of_trips 19c
  • 50. © Oren Nakdimon © Oren Nakdimon Option 4 select s.stop_id, s.stop_name, st1.number_of_trips, st1.no_pickups, st1.no_drop_offs from nearby_stops(-0.11641, 51.48416, 1000) s, (select st.stop_id, count(*) number_of_trips, sum(st.pickup_type) no_pickups, sum(st.drop_off_type) no_drop_offs from stop_times st group by st.stop_id) st1 where st1.stop_id = s.stop_id order by st1.number_of_trips;
  • 51. © Oren Nakdimon © Oren Nakdimon Option 4 select s.stop_id, s.stop_name, st1.number_of_trips, st1.no_pickups, st1.no_drop_offs from nearby_stops(-0.11641, 51.48416, 1000) s, (select st.stop_id, count(*) number_of_trips, sum(st.pickup_type) no_pickups, sum(st.drop_off_type) no_drop_offs from stop_times st group by st.stop_id) st1 where st1.stop_id = s.stop_id order by st1.number_of_trips;
  • 52. © Oren Nakdimon © Oren Nakdimon Option 5 select s.stop_id, s.stop_name, st1.number_of_trips, st1.no_pickups, st1.no_drop_offs from nearby_stops(-0.11641, 51.48416, 1000) s, (select count(*) number_of_trips, sum(st.pickup_type) no_pickups, sum(st.drop_off_type) no_drop_offs from stop_times st where st.stop_id = s.stop_id) st1 order by st1.number_of_trips;
  • 53. © Oren Nakdimon © Oren Nakdimon Option 5 select s.stop_id, s.stop_name, st1.number_of_trips, st1.no_pickups, st1.no_drop_offs from nearby_stops(-0.11641, 51.48416, 1000) s, (select count(*) number_of_trips, sum(st.pickup_type) no_pickups, sum(st.drop_off_type) no_drop_offs from stop_times st where st.stop_id = s.stop_id) st1 order by st1.number_of_trips;
  • 54. © Oren Nakdimon © Oren Nakdimon Option 5 select s.stop_id, s.stop_name, st1.number_of_trips, st1.no_pickups, st1.no_drop_offs from nearby_stops(-0.11641, 51.48416, 1000) s, (select count(*) number_of_trips, sum(st.pickup_type) no_pickups, sum(st.drop_off_type) no_drop_offs from stop_times st where st.stop_id = s.stop_id) st1 order by st1.number_of_trips; ERROR at line 11: ORA-00904: "S"."STOP_ID": invalid identifier
  • 55. © Oren Nakdimon © Oren Nakdimon Option 5 – LATERAL Inline Views select s.stop_id, s.stop_name, st1.number_of_trips, st1.no_pickups, st1.no_drop_offs from nearby_stops(-0.11641, 51.48416, 1000) s, lateral (select count(*) number_of_trips, sum(st.pickup_type) no_pickups, sum(st.drop_off_type) no_drop_offs from stop_times st where st.stop_id = s.stop_id) st1 order by st1.number_of_trips; 12.1 @lateral
  • 56. © Oren Nakdimon © Oren Nakdimon select st.*, s.stop_name from stop_times st, stops s where st.trip_id = 171 and s.stop_id = st.stop_id order by st.stop_sequence;
  • 57. © Oren Nakdimon © Oren Nakdimon create or replace view trip_end_points_v as select st.trip_id, min(st.departure_time) trip_start_time, max(st.arrival_time) trip_end_time, ? first_stop_name, ? last_stop_name from stop_times st, stops s where s.stop_id = st.stop_id group by st.trip_id;
  • 58. © Oren Nakdimon © Oren Nakdimon create or replace view trip_end_points_v as select st.trip_id, min(st.departure_time) trip_start_time, max(st.arrival_time) trip_end_time, any_value(s.stop_name) keep(dense_rank first order by st.stop_sequence) first_stop_name, any_value(s.stop_name) keep(dense_rank last order by st.stop_sequence) last_stop_name from stop_times st, stops s where s.stop_id = st.stop_id group by st.trip_id;
  • 59. © Oren Nakdimon © Oren Nakdimon create or replace view trip_end_points_v as select st.trip_id, min(st.departure_time) trip_start_time, max(st.arrival_time) trip_end_time, any_value(s.stop_name) keep(dense_rank first order by st.stop_sequence) first_stop_name, any_value(s.stop_name) keep(dense_rank last order by st.stop_sequence) last_stop_name from stop_times st, stops s where s.stop_id = st.stop_id group by st.trip_id;
  • 60. © Oren Nakdimon © Oren Nakdimon create or replace view trip_end_points_v as select st.trip_id, min(st.departure_time) trip_start_time, max(st.arrival_time) trip_end_time, any_value(s.stop_name) keep(dense_rank first order by st.stop_sequence) first_stop_name, any_value(s.stop_name) keep(dense_rank last order by st.stop_sequence) last_stop_name from stop_times st, stops s where s.stop_id = st.stop_id group by st.trip_id;
  • 61. © Oren Nakdimon © Oren Nakdimon create or replace view trip_end_points_v as select st.trip_id, min(st.departure_time) trip_start_time, max(st.arrival_time) trip_end_time, any_value(s.stop_name) keep(dense_rank first order by st.stop_sequence) first_stop_name, any_value(s.stop_name) keep(dense_rank last order by st.stop_sequence) last_stop_name from stop_times st, stops s where s.stop_id = st.stop_id group by st.trip_id;
  • 62. © Oren Nakdimon © Oren Nakdimon create or replace view trip_end_points_v as select st.trip_id, min(st.departure_time) trip_start_time, max(st.arrival_time) trip_end_time, any_value(s.stop_name) keep(dense_rank first order by st.stop_sequence) first_stop_name, any_value(s.stop_name) keep(dense_rank last order by st.stop_sequence) last_stop_name from stop_times st, stops s where s.stop_id = st.stop_id group by st.trip_id;
  • 63. © Oren Nakdimon © Oren Nakdimon create or replace package body gtfs as ... procedure get_trips ( i_route_name in trips.route_name%type, i_date in date, i_from_time in trip_end_points_v.trip_start_time%type, i_to_time in trip_end_points_v.trip_start_time%type, o_rc out sys_refcursor ) is begin open o_rc for select t.trip_headsign, v.* from gtfs_sm.services(i_date) s, trips t, trip_end_points_v v where t.service_id = s.service_id and t.route_name = i_route_name and v.trip_id = t.trip_id and v.trip_start_time between i_from_time and i_to_time order by v.trip_start_time; end get_trips;
  • 64. © Oren Nakdimon © Oren Nakdimon create or replace package body gtfs as ... procedure get_trips ( i_route_name in trips.route_name%type, i_date in date, i_from_time in trip_end_points_v.trip_start_time%type, i_to_time in trip_end_points_v.trip_start_time%type, o_rc out sys_refcursor ) is begin open o_rc for select t.trip_headsign, v.* from gtfs_sm.services(i_date) s, trips t, trip_end_points_v v where t.service_id = s.service_id and t.route_name = i_route_name and v.trip_id = t.trip_id and v.trip_start_time between i_from_time and i_to_time order by v.trip_start_time; end get_trips;
  • 65. © Oren Nakdimon © Oren Nakdimon create or replace package body gtfs as ... procedure get_trips ( i_route_name in trips.route_name%type, i_date in date, i_from_time in trip_end_points_v.trip_start_time%type, i_to_time in trip_end_points_v.trip_start_time%type, o_rc out sys_refcursor ) is begin open o_rc for select t.trip_headsign, v.* from gtfs_sm.services(i_date) s, trips t, trip_end_points_v v where t.service_id = s.service_id and t.route_name = i_route_name and v.trip_id = t.trip_id and v.trip_start_time between i_from_time and i_to_time order by v.trip_start_time; end get_trips;
  • 66. © Oren Nakdimon © Oren Nakdimon create or replace package body gtfs as ... procedure get_trips ( i_route_name in trips.route_name%type, i_date in date, i_from_time in trip_end_points_v.trip_start_time%type, i_to_time in trip_end_points_v.trip_start_time%type, o_rc out sys_refcursor ) is begin open o_rc for select t.trip_headsign, v.* from gtfs_sm.services(i_date) s, trips t, trip_end_points_v v where t.service_id = s.service_id and t.route_name = i_route_name and v.trip_id = t.trip_id and v.trip_start_time between i_from_time and i_to_time order by v.trip_start_time; end get_trips;
  • 67. © Oren Nakdimon © Oren Nakdimon create or replace package body gtfs as ... procedure get_trips ( i_route_name in trips.route_name%type, i_date in date, i_from_time in trip_end_points_v.trip_start_time%type, i_to_time in trip_end_points_v.trip_start_time%type, o_rc out sys_refcursor ) is begin open o_rc for select t.trip_headsign, v.* from gtfs_sm.services(i_date) s, trips t, trip_end_points_v v where t.service_id = s.service_id and t.route_name = i_route_name and v.trip_id = t.trip_id and v.trip_start_time between i_from_time and i_to_time order by v.trip_start_time; end get_trips;
  • 68. © Oren Nakdimon © Oren Nakdimon create or replace package body gtfs as ... procedure get_trips ( i_route_name in trips.route_name%type, i_date in date, i_from_time in trip_end_points_v.trip_start_time%type, i_to_time in trip_end_points_v.trip_start_time%type, o_rc out sys_refcursor ) is begin open o_rc for select t.trip_headsign, v.* from gtfs_sm.services(i_date) s, trips t, trip_end_points_v v where t.service_id = s.service_id and t.route_name = i_route_name and v.trip_id = t.trip_id and v.trip_start_time between i_from_time and i_to_time order by v.trip_start_time; end get_trips; @collation
  • 69. © Oren Nakdimon © Oren Nakdimon Column-Level Collation Schema Table Column create user ... default collation using_nls_comp create table ... (...) default collation binary create table trips ( ... route_name varchar2(100) collate binary_ci not null, ... ); 12.2 * MAX_STRING_SIZE must be set to EXTENDED 12.1 @collation2
  • 71. © Oren Nakdimon © Oren Nakdimon Scalar SQL Macro create function datetime ( i_date in date, i_time in varchar2 ) return varchar2 sql_macro(scalar) is begin return q'<trunc(i_date) + numtodsinterval(to_number(substr(i_time, 1, 2)), 'hour’) + numtodsinterval(to_number(substr(i_time, 4, 2)), 'minute') + numtodsinterval(to_number(substr(i_time, 7, 2)), 'second')>'; end datetime; / 21c
  • 72. © Oren Nakdimon © Oren Nakdimon Scalar SQL Macro create function datetime ( i_date in date, i_time in varchar2 ) return varchar2 sql_macro(scalar) is begin return q'<trunc(i_date) + numtodsinterval(to_number(substr(i_time, 1, 2)), 'hour’) + numtodsinterval(to_number(substr(i_time, 4, 2)), 'minute') + numtodsinterval(to_number(substr(i_time, 7, 2)), 'second')>'; end datetime; / 21c @macro4
  • 73. © Oren Nakdimon © Oren Nakdimon create or replace package body gtfs as ... procedure get_departures ( i_stop_id in stops.stop_id%type, i_from_date in date default sysdate, i_days in integer default 1, o_rc out sys_refcursor ) is begin open o_rc for select t.route_name, datetime(s.day, st.departure_time) departure_time from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s where st.stop_id = i_stop_id and t.trip_id = st.trip_id and s.service_id = t.service_id order by t.route_name, departure_time; end get_departures;
  • 74. © Oren Nakdimon © Oren Nakdimon create or replace package body gtfs as ... procedure get_departures ( i_stop_id in stops.stop_id%type, i_from_date in date default sysdate, i_days in integer default 1, o_rc out sys_refcursor ) is begin open o_rc for select t.route_name, datetime(s.day, st.departure_time) departure_time from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s where st.stop_id = i_stop_id and t.trip_id = st.trip_id and s.service_id = t.service_id order by t.route_name, departure_time; end get_departures;
  • 75. © Oren Nakdimon © Oren Nakdimon create or replace package body gtfs as ... procedure get_departures ( i_stop_id in stops.stop_id%type, i_from_date in date default sysdate, i_days in integer default 1, o_rc out sys_refcursor ) is begin open o_rc for select t.route_name, datetime(s.day, st.departure_time) departure_time from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s where st.stop_id = i_stop_id and t.trip_id = st.trip_id and s.service_id = t.service_id order by t.route_name, departure_time; end get_departures;
  • 76. © Oren Nakdimon © Oren Nakdimon create or replace package body gtfs as ... procedure get_departures ( i_stop_id in stops.stop_id%type, i_from_date in date default sysdate, i_days in integer default 1, o_rc out sys_refcursor ) is begin open o_rc for select t.route_name, datetime(s.day, st.departure_time) departure_time from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s where st.stop_id = i_stop_id and t.trip_id = st.trip_id and s.service_id = t.service_id order by t.route_name, departure_time; end get_departures;
  • 77. © Oren Nakdimon © Oren Nakdimon create or replace package body gtfs as ... procedure get_departures ( i_stop_id in stops.stop_id%type, i_from_date in date default sysdate, i_days in integer default 1, o_rc out sys_refcursor ) is begin open o_rc for select t.route_name, datetime(s.day, st.departure_time) departure_time from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s where st.stop_id = i_stop_id and t.trip_id = st.trip_id and s.service_id = t.service_id order by t.route_name, departure_time; end get_departures;
  • 78. © Oren Nakdimon © Oren Nakdimon create or replace package body gtfs as ... procedure get_departures ( i_stop_id in stops.stop_id%type, i_from_date in date default sysdate, i_days in integer default 1, o_rc out sys_refcursor ) is begin open o_rc for select t.route_name, datetime(s.day, st.departure_time) departure_time from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s where st.stop_id = i_stop_id and t.trip_id = st.trip_id and s.service_id = t.service_id order by t.route_name, departure_time; end get_departures;
  • 79. © Oren Nakdimon © Oren Nakdimon create or replace package body gtfs as ... procedure get_departures ( i_stop_id in stops.stop_id%type, i_from_date in date default sysdate, i_days in integer default 1, o_rc out sys_refcursor ) is begin open o_rc for select t.route_name, datetime(s.day, st.departure_time) departure_time from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s where st.stop_id = i_stop_id and t.trip_id = st.trip_id and s.service_id = t.service_id order by t.route_name, departure_time; end get_departures; @pm1
  • 80. © Oren Nakdimon © Oren Nakdimon select route_name, number_of_trips, to_char(from_time,'hh24:mi') ||nvl2(to_time, ' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes', null) departures from ( select t.route_name, datetime(s.day, st.departure_time) departure_time from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s where st.stop_id = i_stop_id and t.trip_id = st.trip_id and s.service_id = t.service_id ) match_recognize ( partition by route_name order by departure_time measures X.departure_time from_time, last(Y.departure_time) to_time, (first(Y.departure_time)-X.departure_time)*24*60 minutes, count(*) number_of_trips pattern (X Y{2,} | X) define Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time ) t order by route_name, from_time;
  • 81. © Oren Nakdimon © Oren Nakdimon select route_name, number_of_trips, to_char(from_time,'hh24:mi') ||nvl2(to_time, ' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes', null) departures from ( select t.route_name, datetime(s.day, st.departure_time) departure_time from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s where st.stop_id = i_stop_id and t.trip_id = st.trip_id and s.service_id = t.service_id ) match_recognize ( partition by route_name order by departure_time measures X.departure_time from_time, last(Y.departure_time) to_time, (first(Y.departure_time)-X.departure_time)*24*60 minutes, count(*) number_of_trips pattern (X Y{2,} | X) define Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time ) order by route_name, from_time; 12.1
  • 82. © Oren Nakdimon © Oren Nakdimon select route_name, number_of_trips, to_char(from_time,'hh24:mi') ||nvl2(to_time, ' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes', null) departures from ( select t.route_name, datetime(s.day, st.departure_time) departure_time from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s where st.stop_id = i_stop_id and t.trip_id = st.trip_id and s.service_id = t.service_id ) match_recognize ( partition by route_name order by departure_time measures X.departure_time from_time, last(Y.departure_time) to_time, (first(Y.departure_time)-X.departure_time)*24*60 minutes, count(*) number_of_trips pattern (X Y{2,} | X) define Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time ) order by route_name, from_time;
  • 83. © Oren Nakdimon © Oren Nakdimon select route_name, number_of_trips, to_char(from_time,'hh24:mi') ||nvl2(to_time, ' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes', null) departures from ( select t.route_name, datetime(s.day, st.departure_time) departure_time from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s where st.stop_id = i_stop_id and t.trip_id = st.trip_id and s.service_id = t.service_id ) match_recognize ( partition by route_name order by departure_time measures X.departure_time from_time, last(Y.departure_time) to_time, (first(Y.departure_time)-X.departure_time)*24*60 minutes, count(*) number_of_trips pattern (X Y{2,} | X) define Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time ) order by route_name, from_time;
  • 84. © Oren Nakdimon © Oren Nakdimon select route_name, number_of_trips, to_char(from_time,'hh24:mi') ||nvl2(to_time, ' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes', null) departures from ( select t.route_name, datetime(s.day, st.departure_time) departure_time from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s where st.stop_id = i_stop_id and t.trip_id = st.trip_id and s.service_id = t.service_id ) match_recognize ( partition by route_name order by departure_time measures X.departure_time from_time, last(Y.departure_time) to_time, (first(Y.departure_time)-X.departure_time)*24*60 minutes, count(*) number_of_trips pattern (X Y{2,} | X) define Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time ) order by route_name, from_time;
  • 85. © Oren Nakdimon © Oren Nakdimon select route_name, number_of_trips, to_char(from_time,'hh24:mi') ||nvl2(to_time, ' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes', null) departures from ( select t.route_name, datetime(s.day, st.departure_time) departure_time from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s where st.stop_id = i_stop_id and t.trip_id = st.trip_id and s.service_id = t.service_id ) match_recognize ( partition by route_name order by departure_time measures X.departure_time from_time, last(Y.departure_time) to_time, (first(Y.departure_time)-X.departure_time)*24*60 minutes, count(*) number_of_trips pattern (X Y{2,} | X) define Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time ) order by route_name, from_time;
  • 86. © Oren Nakdimon © Oren Nakdimon select route_name, number_of_trips, to_char(from_time,'hh24:mi') ||nvl2(to_time, ' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes', null) departures from ( select t.route_name, datetime(s.day, st.departure_time) departure_time from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s where st.stop_id = i_stop_id and t.trip_id = st.trip_id and s.service_id = t.service_id ) match_recognize ( partition by route_name order by departure_time measures X.departure_time from_time, last(Y.departure_time) to_time, (first(Y.departure_time)-X.departure_time)*24*60 minutes, count(*) number_of_trips pattern (X Y{2,} | X) define Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time ) order by route_name, from_time;
  • 87. © Oren Nakdimon © Oren Nakdimon select route_name, number_of_trips, to_char(from_time,'hh24:mi') ||nvl2(to_time, ' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes', null) departures from ( select t.route_name, datetime(s.day, st.departure_time) departure_time from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s where st.stop_id = i_stop_id and t.trip_id = st.trip_id and s.service_id = t.service_id ) match_recognize ( partition by route_name order by departure_time measures X.departure_time from_time, last(Y.departure_time) to_time, (first(Y.departure_time)-X.departure_time)*24*60 minutes, count(*) number_of_trips pattern (X Y{2,} | X) define Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time ) order by route_name, from_time;
  • 88. © Oren Nakdimon © Oren Nakdimon select route_name, number_of_trips, to_char(from_time,'hh24:mi') ||nvl2(to_time, ' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes', null) departures from ( select t.route_name, datetime(s.day, st.departure_time) departure_time from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s where st.stop_id = i_stop_id and t.trip_id = st.trip_id and s.service_id = t.service_id ) match_recognize ( partition by route_name order by departure_time measures X.departure_time from_time, last(Y.departure_time) to_time, (first(Y.departure_time)-X.departure_time)*24*60 minutes, count(*) number_of_trips pattern (X Y{2,} | X) define Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time ) order by route_name, from_time;
  • 89. © Oren Nakdimon © Oren Nakdimon select route_name, number_of_trips, to_char(from_time,'hh24:mi') ||nvl2(to_time, ' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes', null) departures from ( select t.route_name, datetime(s.day, st.departure_time) departure_time from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s where st.stop_id = i_stop_id and t.trip_id = st.trip_id and s.service_id = t.service_id ) match_recognize ( partition by route_name order by departure_time measures X.departure_time from_time, last(Y.departure_time) to_time, (first(Y.departure_time)-X.departure_time)*24*60 minutes, count(*) number_of_trips pattern (X Y{2,} | X) define Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time ) order by route_name, from_time;
  • 90. © Oren Nakdimon © Oren Nakdimon select route_name, number_of_trips, to_char(from_time,'hh24:mi') ||nvl2(to_time, ' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes', null) departures from ( select t.route_name, datetime(s.day, st.departure_time) departure_time from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s where st.stop_id = i_stop_id and t.trip_id = st.trip_id and s.service_id = t.service_id ) match_recognize ( partition by route_name order by departure_time measures X.departure_time from_time, last(Y.departure_time) to_time, (first(Y.departure_time)-X.departure_time)*24*60 minutes, count(*) number_of_trips pattern (X Y{2,} | X) define Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time ) order by route_name, from_time;
  • 91. © Oren Nakdimon © Oren Nakdimon select route_name, number_of_trips, to_char(from_time,'hh24:mi') ||nvl2(to_time, ' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes', null) departures from ( select t.route_name, datetime(s.day, st.departure_time) departure_time from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s where st.stop_id = i_stop_id and t.trip_id = st.trip_id and s.service_id = t.service_id ) match_recognize ( partition by route_name order by departure_time measures X.departure_time from_time, last(Y.departure_time) to_time, (first(Y.departure_time)-X.departure_time)*24*60 minutes, count(*) number_of_trips pattern (X Y{2,} | X) define Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time ) order by route_name, from_time;
  • 92. © Oren Nakdimon © Oren Nakdimon select route_name, number_of_trips, to_char(from_time,'hh24:mi') ||nvl2(to_time, ' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes', null) departures from ( select t.route_name, datetime(s.day, st.departure_time) departure_time from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s where st.stop_id = i_stop_id and t.trip_id = st.trip_id and s.service_id = t.service_id ) match_recognize ( partition by route_name order by departure_time measures X.departure_time from_time, last(Y.departure_time) to_time, (first(Y.departure_time)-X.departure_time)*24*60 minutes, count(*) number_of_trips pattern (X Y{2,} | X) define Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time ) order by route_name, from_time;
  • 93. © Oren Nakdimon © Oren Nakdimon select route_name, number_of_trips, to_char(from_time,'hh24:mi') ||nvl2(to_time, ' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes', null) departures from ( select t.route_name, datetime(s.day, st.departure_time) departure_time from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s where st.stop_id = i_stop_id and t.trip_id = st.trip_id and s.service_id = t.service_id ) match_recognize ( partition by route_name order by departure_time measures X.departure_time from_time, last(Y.departure_time) to_time, (first(Y.departure_time)-X.departure_time)*24*60 minutes, count(*) number_of_trips pattern (X Y{2,} | X) define Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time ) order by route_name, from_time;
  • 94. © Oren Nakdimon © Oren Nakdimon select route_name, number_of_trips, to_char(from_time,'hh24:mi') ||nvl2(to_time, ' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes', null) departures from ( select t.route_name, datetime(s.day, st.departure_time) departure_time from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s where st.stop_id = i_stop_id and t.trip_id = st.trip_id and s.service_id = t.service_id ) match_recognize ( partition by route_name order by departure_time measures X.departure_time from_time, last(Y.departure_time) to_time, (first(Y.departure_time)-X.departure_time)*24*60 minutes, count(*) number_of_trips pattern (X Y{2,} | X) define Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time ) order by route_name, from_time;
  • 95. © Oren Nakdimon © Oren Nakdimon select route_name, number_of_trips, to_char(from_time,'hh24:mi') ||nvl2(to_time, ' - '||to_char(to_time,'hh24:mi')||' every '||minutes||' minutes', null) departures from ( select t.route_name, datetime(s.day, st.departure_time) departure_time from stop_times st, trips t, gtfs_sm.services(i_from_date, i_days) s where st.stop_id = i_stop_id and t.trip_id = st.trip_id and s.service_id = t.service_id ) match_recognize ( partition by route_name order by departure_time measures X.departure_time from_time, last(Y.departure_time) to_time, (first(Y.departure_time)-X.departure_time)*24*60 minutes, count(*) number_of_trips pattern (X Y{2,} | X) define Y as departure_time-prev(departure_time) = first(Y.departure_time)-X.departure_time ) order by route_name, from_time; @pm2