我有一个 Oracle Stored Proc - 从 Java 1.6 代码调用。有一条消息发送到一个号码,该号码可以回复它。我的问题是 UNION 部分不起作用。我希望与消息一起返回一行并在一行上回复。目前发生的是存储过程返回 2 行。第一行只有消息。第二行将它们组合在一起。我只想要第二行。
这是我的存储过程:
create or replace
FUNCTION "LIST_ALL_MSGS_SERVICE" (
gvi_service_code_in in varchar2,
start_date_in in varchar2,
end_date_in in varchar2
)
return types.cursorType
is
msg_cursor types.cursorType;
l_msg_code message.gvi_message_code%type;
l_start_date date;
l_end_date date;
BEGIN
IF start_date_in IS NULL THEN
raise_application_error(-20054, 'start_date missing');
END IF;
IF end_date_in IS NULL THEN
raise_application_error(-20054, 'end_date missing');
END IF;
/* Set end date */
l_end_date := to_date(end_date_in, 'yyyy-mm-dd hh24:mi:ss');
/* Set start date */
l_start_date := to_date(start_date_in, 'yyyy-mm-dd hh24:mi:ss');
/* Use cursor to select messages */
BEGIN
OPEN msg_cursor FOR
SELECT
m.message_id,
m.gvi_message_code sort_gvi_message_code,
m.recipient,
m.originator,
m.content,
mct.message_channel_type,
to_char(m.message_date, 'yyyy-mm-dd hh24:mi:ss'),
mst.description,
null,
null,
m.gvi_datafeed_name
FROM message m,
message_channel_type mct,
message_status_type mst,
message_status ms
WHERE TRIM(UPPER(m.gvi_service_code)) = gvi_service_code_in
AND m.gvi_message_code = ms.gvi_message_code
AND m.message_date >= l_start_date
AND m.message_date <= l_end_date
AND m.message_channel_type_id = mct.message_channel_type_id
AND ms.message_status_type_id = mst.message_status_type_id
AND ms.message_status_type_id =
(SELECT MAX(ms2.message_status_type_id)
FROM message_status ms2
WHERE ms2.gvi_message_code = m.gvi_message_code)
UNION
SELECT
m.message_id,
m.gvi_message_code sort_gvi_message_code,
m.recipient,
m.originator,
m.content,
mct.message_channel_type,
to_char(m.message_date, 'yyyy-mm-dd hh24:mi:ss'),
mst.description,
em.gvi_external_message_code,
em.content,
m.gvi_datafeed_name
FROM message m,
external_message em,
ext_msg_status_type emst,
message_channel_type mct,
message_status_type mst,
message_status ms
WHERE TRIM(UPPER(m.gvi_service_code)) = gvi_service_code_in
AND m.gvi_message_code = ms.gvi_message_code
AND m.gvi_message_code = em.gvi_message_code
AND TRIM(UPPER(emst.ext_msg_status_type)) = 'REPLY'
AND em.ext_msg_status_type_id = emst.ext_msg_status_type_id
AND m.message_date >= l_start_date
AND m.message_date <= l_end_date
AND m.message_channel_type_id = mct.message_channel_type_id
AND ms.message_status_type_id = mst.message_status_type_id
AND ms.message_status_type_id =
(SELECT MAX(ms2.message_status_type_id)
FROM message_status ms2
WHERE ms2.gvi_message_code = m.gvi_message_code)
ORDER BY sort_gvi_message_code;
END;
RETURN msg_cursor;
commit;
END list_all_msgs_service;