我是编写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
您的意见将受到高度赞赏。提前谢谢。
如何正确执行代码?
答案 0 :(得分:0)
错误发生在 get.sql 脚本中。此脚本中的SELECT INTO
语句返回多行。您可以尝试使用SELECT DISTINCT
和/或添加其他WHERE
条件来限制结果集。