1

我是编写 PL/SQL 的新手。我有这个小代码,但由于主题错误而无法打印输出。

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;
/

执行后出现此错误:

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

您的意见将不胜感激。先感谢您。

如何使我的代码正确执行?

4

1 回答 1

0

错误在您的get.sql脚本中。您SELECT INTO在此脚本中的语句返回超过 1 行。您可以尝试使用SELECT DISTINCT和/或添加另一个WHERE条件来限制结果集。

于 2015-04-09T07:22:32.317 回答