Рассчитать время окончания на основе отметки времени и интервала - PullRequest
0 голосов
/ 05 ноября 2018

Я новичок в SQL. Я застрял на этой проблеме. Я смог завершить некоторые из них, но не могу правильно ввести информацию, чтобы получить время окончания.

Вопрос: Используйте анонимную программу PL / SQL, чтобы распечатать электронную почту организатора мероприятия «Город вечеринки», а также время начала и окончания мероприятия. Используйте неявный курсор и обработайте исключение.

Вот мой прогресс:

declare
o_email varchar(70);
s_tart_time timestamp;
begin
select oemail, start_time
into o_email, s_tart_time 
from  organizer o, event e
where e.oid = o.oid and
ename = 'Party City';
dbms_output.put_line ('email is: ' || o_email);
dbms_output.put_line ('start time is: ' || s_tart_time);
Exception
    when no_data_found then
    Dbms_output.put_line('No Data Found');
END;

Таблица:

create table event
(eid int, --- event id 
oid int, --- organizer id 
ename varchar(50), --- event name 
lid int, --- location id 
start_time timestamp, -- start time of event
duration interval day to second, --- duration of event, 
status int, --- 1 scheduled, 2 canceled, 3 finished 
primary key(eid), 
foreign key (lid) references location,
foreign key (oid) references organizer);

insert into event values (1, 1,'Party City', 1, timestamp '2018-9-6 10:00:00.00',interval '2' hour, 3);

Спасибо !!

1 Ответ

0 голосов
/ 05 ноября 2018

Oracle SQL поддерживает арифметику даты / времени, так что вы можете просто добавить интервал к отметке времени, чтобы получить время окончания. e.g.:

declare
o_email varchar(70);
s_tart_time timestamp;
end_time timestamp;
begin
select oemail, start_time, start_time + duration
into o_email, s_tart_time, end_time
from  organizer o, event e
where e.oid = o.oid and
ename = 'Party City';
dbms_output.put_line ('email is: ' || o_email);
dbms_output.put_line ('start time is: ' || s_tart_time);
dbms_output.put_line ('end time is: ' || end_time);
Exception
    when no_data_found then
    Dbms_output.put_line('No Data Found');
END;
/

email is: bla
start time is: 06-SEP-18 10.00.00.000000 AM
end time is: 06-SEP-18 12.00.00.000000 PM

LiveSQL - примечание: мне пришлось закомментировать некоторые биты, потому что вы не включили определение таблицы organizer в свой вопрос.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...