Reputation: 29
I am a newbie in writing PL/SQL. I have this small code, but unable to print out the output due to the subject error.
declare
output_tour_id varchar(4000);
begin
dbms_output.enable;
for r in
(
SELECT TOUR_ID FROM "/DSD/HH_RADELHD"
VERSIONS BETWEEN TIMESTAMP TO_TIMESTAMP('2015-04-02 18:00:00','YYYY-MM-DD HH24:MI:SS')
AND TO_TIMESTAMP('2015-04-02 18:30:00','YYYY-MM-DD HH24:MI:SS')
WHERE VERSIONS_OPERATION = 'D'
group by VERSIONS_STARTTIME, CLIENT, TOUR_ID
)
Loop
@/tmp/get.sql r.tour_id;
DBMS_OUTPUT.PUT_LINE (output_tour_id);
end loop;
end;
/
I get this error after executing:
old 30: WHERE CLIENT = 100 and TOUR_ID = &1;
new 30: WHERE CLIENT = 100 and TOUR_ID = r.tour_id;
'100','100002039690','000001','0001398563','0050543675','10','C170','20150402070750','CET','1',' ','10',' ','91597','20150330',' ',
declare
*
ERROR at line 1:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at line 13
Your inputs would be highly appreciated. Thank you in advance.
How do I make my code execute properly?
Upvotes: 1
Views: 568
Reputation: 4053
The error is in your get.sql script. Your SELECT INTO
statement in this script returns more than 1 row. You can try to use SELECT DISTINCT
and/or add another WHERE
condition to restrict the result set.
Upvotes: 0