Я исследовал и пробовал множество способов объявить и присвоить значения переменным для базы данных PostgreSQL, используя Oracle SQL Developer, но безрезультатно. Вот что я пытаюсь сделать:
DEFINE response = '0'
DEFINE startDate = TO_TIMESTAMP('2020/03/28 00:00:00', 'yyyy/mm/dd HH24:MI:SS');
DEFINE endDate = TO_TIMESTAMP('2020/03/30 19:00:00', 'yyyy/mm/dd HH24:MI:SS');
SELECT clog.ch_call_index
,clog.ch_response AS "Response"
,cdata.ch_final_disposition AS "Result"
,clog.ch_spoken
,cdata.ch_recorded_msg AS "Recorded Message"
,cdata.ch_menu_selections AS "Menu Selections"
,clog.ch_spoken_dt_tm
,clog.ch_response_dt_tm
FROM ch_call_log clog
INNER JOIN ch_call_data cdata ON clog.ch_call_index = cdata.ch_call_index
WHERE cdata.ch_start_dt_tm >= &startDate
AND cdata.ch_start_dt_tm <= &endDate
AND (SELECT ch_response
FROM ch_call_log
WHERE ch_call_index = clog.ch_call_index
ORDER BY ch_spoken_dt_tm DESC
LIMIT 1) = '&&response'
AND clog.ch_response = '&&response'
ORDER BY cdata.ch_final_disposition
Следующее работает просто отлично, но я хотел бы выяснить, как использовать переменные и легко обновлять их при необходимости:
SELECT clog.ch_call_index
,clog.ch_response AS "Response"
,cdata.ch_final_disposition AS "Result"
,clog.ch_spoken
,cdata.ch_recorded_msg AS "Recorded Message"
,cdata.ch_menu_selections AS "Menu Selections"
,clog.ch_spoken_dt_tm
,clog.ch_response_dt_tm
FROM ch_call_log clog
INNER JOIN ch_call_data cdata ON clog.ch_call_index = cdata.ch_call_index
WHERE cdata.ch_start_dt_tm >= TO_TIMESTAMP('2020/03/28 00:00:00', 'yyyy/mm/dd HH24:MI:SS')
AND cdata.ch_start_dt_tm <= TO_TIMESTAMP('2020/03/30 19:00:00', 'yyyy/mm/dd HH24:MI:SS')
AND (SELECT ch_response
FROM ch_call_log
WHERE ch_call_index = clog.ch_call_index
ORDER BY ch_spoken_dt_tm DESC
LIMIT 1) = '0'
AND clog.ch_response = '0'
ORDER BY cdata.ch_final_disposition