带有游标的 PL/SQL 错误,ERROR ORA-06550
Posted
技术标签:
【中文标题】带有游标的 PL/SQL 错误,ERROR ORA-06550【英文标题】:PL/SQL error with cursor, ERROR ORA-06550 【发布时间】:2020-05-04 13:08:07 【问题描述】:我正在学习 PL/SQL,我正在尝试创建一个过程,但我的游标有问题,我不知道它是什么,如果你能帮助我的代码,我会感激不尽。
看看我的代码
DECLARE
TYPE T_CURSOR IS REF CURSOR;
V_CURSOR T_CURSOR;
V_STATION STATION_DATA%ROWTYPE;
BEGIN
OPEN V_CURSOR FOR SELECT * FROM STATION_DATA;
FETCH V_CURSOR INTO V_STATION;
EXIT WHEN V_CURSOR%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(
'STATION NUMBER = '||V_STATION.STATION_NUMBER||
'REPORT CODE = '||V_STATION.REPORT_CODE||
'YEAR = '||V_STATION.YEAR||
'MONTH = '||V_STATION.MONTH||
'DAY = ' ||V_STATION.DAY||
'DEW POINT = '||V_STATION.DEW_POINT||
'STATION PRESSURE = '||V_STATION.STATION_PRESSURE||
'VISIBILITY = '||V_STATION.VISIBILITY||
'WIND SPEED = '||V_STATION.WIND_SPEED||
'PRECIPATION = '||V_STATION.PRECIPATION||
'TEMPERATURE = '||V_STATION.TEMPERATURE||
'SNOW DEPTH = '||V_STATION.SNOW_DEPTH||
'FOG = '||V_STATION.FOG||
'RAIN = '||V_STATION.RAIN||
'HAIL = '||V_STATION.HAIL||
'THUNDER = '||V_STATION.THUNDER||
'TORNADO = '||V_STATION.TORNADO
);
END LOOP ;
CLOSE V_CURSOR ;
END ;
/
【问题讨论】:
select * from user_errors
将向您显示实际的错误消息。然后您可以edit your question 添加该重要信息。
此错误应为您提供引发错误的行号和列号。我想,缓冲区溢出可能会引发。
您忘记使用LOOP
语句,但您正在使用END LOOP
关闭它。请在FETCH V_CURSOR INTO V_STATION;
之前使用LOOP
并检查它是否适合您
【参考方案1】:
您的代码缺少LOOP
语句以及一些不需要的代码。
你需要这样的东西(见内联 cmets):
DECLARE
-- TYPE T_CURSOR IS REF CURSOR; -- YOU DON'T NEED THIS
V_CURSOR SYS_REFCURSOR; -- USE SYS_REFCURSOR
V_STATION STATION_DATA%ROWTYPE;
BEGIN
OPEN V_CURSOR FOR SELECT *
FROM STATION_DATA;
LOOP -- ADDED THIS
FETCH V_CURSOR INTO V_STATION;
EXIT WHEN V_CURSOR%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(
'STATION NUMBER = '||V_STATION.STATION_NUMBER||
'REPORT CODE = '||V_STATION.REPORT_CODE||
'YEAR = '||V_STATION.YEAR||
'MONTH = '||V_STATION.MONTH||
'DAY = ' ||V_STATION.DAY||
'DEW POINT = '||V_STATION.DEW_POINT||
'STATION PRESSURE = '||V_STATION.STATION_PRESSURE||
'VISIBILITY = '||V_STATION.VISIBILITY||
'WIND SPEED = '||V_STATION.WIND_SPEED||
'PRECIPATION = '||V_STATION.PRECIPATION||
'TEMPERATURE = '||V_STATION.TEMPERATURE||
'SNOW DEPTH = '||V_STATION.SNOW_DEPTH||
'FOG = '||V_STATION.FOG||
'RAIN = '||V_STATION.RAIN||
'HAIL = '||V_STATION.HAIL||
'THUNDER = '||V_STATION.THUNDER||
'TORNADO = '||V_STATION.TORNADO
);
END LOOP;
CLOSE V_CURSOR;
END;
/
【讨论】:
以上是关于带有游标的 PL/SQL 错误,ERROR ORA-06550的主要内容,如果未能解决你的问题,请参考以下文章