I am trying to create a union inside a stored procedure which unions two select statements. One of the select statement returns two or more rows. Thus I get the error "exact fetch returns more than requested number of rows", which occurs of course because I have more than 1 row being retunrned from the second select statement.
This is my stored procedure:
DECLARE
timer_before timestamp;
timer_after timestamp;
timer_duration number;
referencelistid number(20);
referencename varchar(20);
startdate timestamp;
enddate timestamp;
creationuser varchar(20);
creationdate timestamp;
changeuser varchar(20);
changedate timestamp;
username varchar(20);
changetime timestamp;
BEGIN
timer_before :=systimestamp;
--DBMS_OUTPUT.put_line('Start at: ' || timer_before);
SELECT
REFERENCE_LIST_ID,
REFERENCE_NAME,
START_DATE,
END_DATE,
CREATION_USER,
CREATION_DATE,
CHANGE_USER,
CHANGE_DATE,
USERNAME,
CHANGE_TIME
into
referencelistid,
referencename,
startdate,
enddate,
creationuser,
creationdate,
changeuser,
changedate,
username,
changetime
from
tbrd_reference_lists
where
reference_list_id = 0000
UNION SELECT
REFERENCE_LIST_ID,
REFERENCE_NAME,
START_ DATE,
END_DATE,
CREATION_USER,
CREATION_DATE,
CHANGE_USER,
CHANGE_DATE,
USERNAME,
CHANGE_TIME
from
tbrd_reference_lists_h
where
reference_list_id = 0000;
timer_after :=systimestamp;
--DBMS_OUTPUT.put_line('End at: ' || timer_after);
select
extract(second from timer_after-timer_before) into timer_duration
from
dual;
DBMS_OUTPUT.put_line('Delete Duration: (s): ' || timer_duration);
DBMS_OUTPUT.put_line('Delete Duration: (ms) ' || timer_duration*1000);
END;
I tried to search for a solution, and pipeline functions look like an option. Is there anything simpler that I can use to achieve this
Thanks Pulkit
SELECT .. UNION SELECT ..result? You need in execution time only? Maybe simply wrap it with something likeSELECT COUNT(*) INTO dummy_variable FROM (SELECT .. UNION SELECT ..)? Or the same with your query in CTE?